Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to Remote MySQL database (NEWBIE)

Status
Not open for further replies.

t35li

Programmer
May 28, 2009
12
CA
I'm building a website for my lab using MySQL database provided by the university's server. I can't seem to figure out how to connect to MySQL using SSH Secure Shell Client. I have connected to the university's server using SSH, but when I type commands like :

[user@servername]$ mysql -u user -p database

it gives sth like:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I have no idea what I'm suppose to do or if I'm not doing something correctly. Please help.
 
If its remote, you should be specifying the IP address or DNS name of the remote machine that holds the mysql server.

Currently its trying to connect to a MYSQL server locally. That is the same machine the shell client is running on


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The error message you are getting says that it won't do a local connect through a socket. Mind you, you are typing that command on the remote server. You therefore are already there and are issuing a local command there. You may be able to connect if you also state host 127.0.0.1. For MySQL, localhost is NOT the same as 127.0.0.1: 127.0.0.1 is the loopback interface (using TCP/IP) and localhost means to bypass networking altogether by using a socket. Hence the message.

Another option is to connect programs on your machine to the remote server through port forwarding. If you are using PuTTY on your local machine, go to Connection > SSH > Tunnels before you connect, and enter a free port on your machine (3307 for instance) as "source port" and the remote port, seen from the remote location as destination. You will probably have to enter 127.0.0.1:3306 there. If the server is not on your network, it does not hurt to enable compression as well. Now connect and log in. You will get a shell, but you do not need to enter anything on that shell for the port forwarding.

Now you can use your own programs and connect them to port 3307 on your local machine. SSH will make sure the traffic goes safely encrypted to the server and back.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top