Nov 24, 2014 Tags: Howto, Linux
Snippets, howtos, tips and tricks around SSH. This post will be updated as needed.
See also: Using Linux
Updated on Sep 26, 2018
Readings: OpenSSH manual, Quick-Tip SSH Tunneling Made Easy
Create a tunnel to port 3306 on the remote server. This is the standard port for MySQL. Example:
ssh -N -f -L 13306:localhost:3306 \
    sshuser@remote-server.com
Options:
| -N | Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only). | 
| -f | Send ssh into the background. | 
| -L | In this example: forward the local port 13306to the remote port3306. | 
Make sure the MySQL user and the database are opened to TCP access:
UPDATE USER SET host='%' WHERE user='DBUSER';
UPDATE DB SET host='%' WHERE user='DBUSER';
Now you can connect to the MySQL service running on the server:
localmachine>$  mysql -h 127.0.0.1 -P 13306 -u DBUSER -pDBPASSWORD
Attention: -h localhost did not work for me.
Save time and write -h 127.0.0.1 instead!
Note: This technique will only work if access for remote machines is enabled on the server:
# in file: /etc/mysql/my.cnf
## disable remote access:
#bind-address           = 127.0.0.1
# enable remote access:
bind-address            = 0.0.0.0
# Restart MySQL after changing this section - a reload is not enough:
$ service mysql restart
Warning: Allowing network access for MySQL creates potential security risks. Turn the feature off whenever you can!