Allow Local 3306 Connections to MySQL on Ubuntu 18.04 with UFW

MySQLufw

If I run this command:

mysql -u root -p -h 127.0.0.1 -P 3306

with the correct password (yes, I have the correct password) it says access denied

I run the exact same thing, just disable ufw first
sudo ufw disable

then the above command, and it works.
But: now ufw is disabled :S

What I really want to do is connect via mysql workbench using ssh
but without disabling ufw altogether, and without allowing none ssh access to my mysql installation?

these are the current settings that work for me with mysql-workbench, but only if ufw is disabled. As soon as I enable ufw, this stops working. And I dont want to just open 3306 ports to everyone either using ufw. I want to close everything except ssh, and let me connect via ssh to the 3306 port of mysql.

enter image description here

Best Answer

To allow connection via loopback adapter only on port 3306 you can run the following:

sudo ufw allow from 127.0.0.1 to 127.0.0.1 port 3306 proto tcp