Not only possible, but also really easy. As long as you're not running a MySQL instance locally, just invoke SSH like this:
ssh -L 3306:mysql.server:3306 geoffham@ssh.pythonanywhere.com
That -L
option means "forward LOCAL port 3306 to REMOTE host mysql.server port 3306" (the port numbers can be different, but in this case the standard MySQL port would be easiest). You can also use -R
to cause remote connections to be forwarded back to you, but that's a pretty unusual thing to do for most people.
REMEMBER that you need to keep your SSH session open at all times! As soon as that closes, your forwarded connection is also lost.
At this point, you should be able to run MySQL as normal. One thing to watch out for, however - many MySQL clients treat the hostname localhost
as special, meaning "connect to the local server over a domain socket". What you want to do is force it to connect to your local machine on port 3306, and you can do this by specifying 127.0.0.1
for the host instead of localhost
. For example, to use the command-line mysql
client you'd invoke it like this:
mysql -h 127.0.0.1 -u geoffham -p
Finally, if you are running a MySQL server locally and hence port 3306 is already in use, you can modify your SSH invocation to use any other port:
ssh -L 3333:mysql.server:3306 geoffham@ssh.pythonanywhere.com
However, you'd then need to configure your MySQL client to use this other port, as this is not the default for MySQL.