Joyent

Translations of this page:

Connecting to MySQL via an SSH Tunnel

In order to connect to your Facebook Accelerator MySQL server via SSH, you will need to change some configuration settings.

Configuring SSH

To configure your SSH to allow tunneling, follow these steps:

1. Edit /etc/ssh/sshd_config
2. Change the following parameters to "Yes":
    AllowTcpForwarding yes
    GatewayPorts yes
3. Restarting SSH:
    svcadm restart svc:/network/ssh:default
4. Checking to ensure that SSH properly restarted:
    svcs -a | grep -i ssh
    online 21:31:42 svc:/network/ssh:default
The "21:31:42" is the time at which it last changed state, 
in this case, the time at which we restarted it.

For more information, see http://discuss.joyent.com/viewtopic.php?pid=159330#p159330.

Configuring MySQL

In order to remotely connect to MySQL, you will need to edit your configuration file to allow TCP/IP access:

1. Edit /opt/local/etc/my.cnf
    sudo vi /opt/local/etc/my.cnf
2. Comment out or remove the line that says "skip-networking"
3. If you are only accessing MySQL locally or through this SSH tunnel,
   check for the line that says "bind-address" and make sure it is "bind-address=127.0.0.1"
4. Restart MySQL
    svcadm restart mysql

Setting up the Tunnel

Now you should be ready to create your tunnel. The most common methods of setting up a tunnel are through putty or through command-line SSH.

To open an SSH tunnel via the command line, run:

ssh -L3307:127.0.0.1:3306 -p 22 -N -t -x user@myhost.com

To open an SSH tunnel via putty:

  1. Under the Connection > SSH > Tunnels menu enter 3306 into the source port field, 
     and 127.0.0.1:3306 into the Destination field.  
  2. The rest of the settings on that page should be correct (Local and Auto) click Add.
  3. Save your session so you won't have to set this again in the future.  
  4. Now connect as usual for regular ssh shell access, and your tunnel should be operational.

Connecting with MySQL

Now that you have the tunnel up and running, you can connect to the MySQL server!

mysql -u username -ppassword -h 127.0.0.1 -P 3307
 
facebook/kb/mysql-tunnel.txt · Last modified: 2008/05/04 13:38 by tcindie
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki