How do I connect to a MySQL database remotely?
For security reasons we do not allow external connections to MySQL. If we did, you would have hackers probing your databases 24/7 trying to break in and steal your data.
However, this doesn't mean you cannot connect remotely to MySQL. You can create a connection by using SSH (secure shell) tunneling. We enable shell access upon request, so open a ticket to request this if your site hasn't already been enabled.
Once shell access has been enabled, on your local machine you must set up the tunnel to your site. On a Mac computer this is fairly simple--just load up the terminal app (from the Utilities folder in Applications) and run this command:
ssh -p 900 -L 3306:localhost:3306This email address is being protected from spambots. You need JavaScript enabled to view it.
Replace user with your cPanel username, and domain.com with your hosted domain. This command will tunnel traffic from port 3306 on your local machine to port 3306 on the remote web server. Once you've established this tunnel, you can make a connection from any MySQL utility to "localhost" and use the same database username and password that is used by scripts on the web server to connect to the database.
On Windows the same sort of tunnel can be set up using the freeware SSH client PuTTY. Here's a link to a website with details on setting up a tunnel with PuTTY:
http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html
However, this doesn't mean you cannot connect remotely to MySQL. You can create a connection by using SSH (secure shell) tunneling. We enable shell access upon request, so open a ticket to request this if your site hasn't already been enabled.
Once shell access has been enabled, on your local machine you must set up the tunnel to your site. On a Mac computer this is fairly simple--just load up the terminal app (from the Utilities folder in Applications) and run this command:
ssh -p 900 -L 3306:localhost:3306
Replace user with your cPanel username, and domain.com with your hosted domain. This command will tunnel traffic from port 3306 on your local machine to port 3306 on the remote web server. Once you've established this tunnel, you can make a connection from any MySQL utility to "localhost" and use the same database username and password that is used by scripts on the web server to connect to the database.
On Windows the same sort of tunnel can be set up using the freeware SSH client PuTTY. Here's a link to a website with details on setting up a tunnel with PuTTY:
http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html
Comment
or post as a guest
Be the first to comment.