Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/rekall/krisgale.com/wp-includes/formatting.php on line 74

a number of articles and blog posts exist that (attempt to) explain how one might go about connecting to a remote mysql server by way of an ssh tunnel… a vast majority of them are a copy-and-paste of the same information on how to do it using PuTTY as go-between.

seeing as how PuTTY serves the WIntel folks, and i prefer my powerbook to my thinkpad these days, i searched for a solution to do this simply on OS X… and found mention, but not working example, of using Terminal to handle the necessary port forwarding.

i looked more carefully at the man pages for ssh, and lo and behold, the -L option will do everything you need.

launch Terminal and issue this command:

ssh [host] -l [username] -p [port] -L 127.0.0.1:3306:[mysql_server]:[mysql_port] -N

[host], [username] and [port] pertain to the login credentials for the ssh connection (the port will usually but not always be 22)… the -L option is to establish forwarding the standard mysql port (3306) from your own computer (127.0.0.1 aka localhost) to the remote mysql server (usually but not always localhost)… -N tells Terminal to make the connection but provide no interaction, so the console will just sit there without giving you a command shell on the remote machine.

with the tunnel and port forwarding established, you can use MySQL Query Browser or another front-end to connect to 127.0.0.1 on port 3306 and you’ll be on your merry way administering rows of data…

* it should go without saying that this won’t work if you are already running an instance of mysql server on your own machine on port 3306.