Can I connect to MySQL remotely?

By DigitalPulseHosting.com
2004-09-08 00:37:46

Yes, you can connect to your MySQL database remotely however for security reasons native remote direct connections to the MySQL server are disabled. So, you cannot use MySQLFront or other similar MySQL admin applications running on your computer to connect to the server directly. However, since there is a reasonable need for remote connections we do allow them using the secure tunneling protocol SSH.

SSH (Secure SHell) is protocol which allows users to remotely connect to a server and use a specified service in the same manner as if it were running locally. This process is called tunnelling. An SSH connection can be visualized as a communication tunnel. When you establish an SSH connection you specify a local port and a remote server address and port. You send information through one side of tunnel (the local port) and it exits on other side (the remote server/port). The connection is bi-directional, so you will also receive data from the remote server.

There are several solutions to create SSH tunnels. The most popular one is the freeware PuTTY (OpenSSH) package. It contains the application plink.exe which does the job of SSH tunneling. Unix users should check out OpenSSH.

plink.exe is console application and it must be started from the command prompt. It receives lots of parameters but very few are needed to establish connection.

It is best to create a .bat batch file to start the SSH tunnel like:

--- start of plink.bat ----
plink.exe -L 3306:localhost:3306 username@domain
--- end of plink.bat ----

Replace username and domain with your details for the database server you want to access. For instance if you want to access the domain mysite.com with CPanel username admin you will run plink as plink.exe -L 3306:localhost:3306 admin@mysite.com

The parameter -L sets which local port to listen to and where (host and port) to forward everything received on the local port. For most cases the example command will do the job. It instructs plink to listen on port 3306 (default MySQL server port). Everything it receives on that port will be sent to the tunnel and when it exits on the other side it will be sent to the host address localhost and port 3306. Automatically, any response from the server will be forwarded back to your computer.

When you start plink it will connect to the remote host to establish the tunnel. It will ask you for your CPanel password during the process. After it establishes the link it will stay open in the command prompt window. Do not close this window as it must stay open, however you may minimize it.

Finally when you want to stop tunnel, press Ctrl-C in plink console and wait for it to stop operation. Then you may close command prompt.

After the tunnel is establish you have to configure your applications to use it. Configuring an application is actually very easy. Just pretend the MySQL server is on your local computer but use the username and password of remote server. This means you set the option for the MySQL server address as localhost, and the port to 3306. For the username and password use the MySQL username and password you created via CPanel.

There does exist some front-end applications to plink.exe that enable you to establish connections via a GUI without needing the command prompt. One is available from http://www.delight.ch/, others can be found via google.com.



Page: 1
return to top