Usually the mysql server is configured not to allow network connections. Recently I had to find a way to allow connections over the internet, even the root account should be able to connect. I decided to use a ssh tunnel and configured the mysql daemon to listen on 127.0.0.1. Additionally the mysql port (3306) is blocked by the packetfilter.
Thus I had to add the “bind-address” option to /etc/mysql/my.cnf:
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
bind-address = 127.0.0.1
Furthermore I had to comment out “skip-networking”:
Otherwise mysqld would only work with sockets and not with TCP/IP connections.
To start the ssh tunnel run:
ssh -N -L 3306:localhost:3306 jimmy@mysql_host.com
Now connect to mysql with:
mysql -h 127.0.0.1
Use 127.0.0.1, not localhost, when connecting to the server. Otherwise the mysql-client will try to connect to localhost, without using the tunnel.