How to tunnel a mysql connection to your remote server

June 15, 2009    mysql tunnel ssh

Today I spent alot of the day sorting our development techniques to bring a best practise into what we do. We needed to both be able to connect to the same remote database but both be able to develop locally. So we decided to setup ssh tunnels to our mysql server.

You can quite simply open a ssh tunnel with your server using the following:

ssh -L 3307:domain.name.of.mysqlserver:3306 username@domain.name.of.gatewayserver

You can then connect to the server with php using the following,

DB_USER - root - DB_HOST - 127.0.0.1 :3307 - DB_NAME - db_name DB_PASS - root pass


blog comments powered by Disqus