Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an account on a shared server. I have jailshell access and also PhpMyAdmin.

I want to run mysql commands via SSH but I'm getting an error:

$ mysql -u mySqlUser -p mySqlPw
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

I can connect with PHP and phpMyAdmin, so would it be possible to call mysql from the shell and have it connect via an ip and port instead of the socket? The file /var/lib/mysql/mysql.sock does not exist - maybe that is intentional, and the only thing in /etc/my.cnf is

[mysqld]
skip-innodb

More Info

I don't have access to change system settings. I did a search in /var for mysql.sock but found nothing. However, phpMyAdmin might be connecting via a socket somehow:

Image

Really it would just be great if I could connect via IP.

Also tried these two syntaxes:

$ mysql -u mySqlUser -p mySqlPw -h localhost
$ mysql -u mySqlUser -p mySqlPw -h localhost -P 3306

Both with the same result:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
share|improve this question
    
mysql probably isn't running on that server. Where is phpmyadmin served from? Does the address you visit in your browser resolve to a different IP from the server you're connecting to via SSH? –  LukeR Jun 27 '11 at 1:30
    
I am fairly certain that mysql is actually running on that machine. The server has cPanel set up and the address resolves to the same IP for the website, for cPanel, and for phpMyAdmin. –  cwd Jun 27 '11 at 1:43
    
Fair enough. Probably worth contacting support then. They'd be the best people to advise on your specific situation. –  LukeR Jun 27 '11 at 2:11
add comment

3 Answers

up vote 1 down vote accepted

You are missing the protocol parameter:

mysql --protocol=tcp -u mySqlUser -p mySqlPw

or

mysql -u mySqlUser -p mySqlPw -h localhost --protocol=tcp -P 3306

Both should be the same (localhosst:3306 are default values)

share|improve this answer
    
YES! Thank you! –  cwd Jun 27 '11 at 15:38
add comment

From the mysql(1) man page:

  ·   --host=host_name, -h host_name

      Connect to the MySQL server on the given host.
share|improve this answer
    
tried that with the same result. I'll edit the question with the result. –  cwd Jun 27 '11 at 1:30
add comment

$ mysql -u ... -p ... -h 127.0.0.1

or

$ mysql -u ... -p ... -h hostname.example.com

I believe this prevents the use of socket, use -h localhost uses the socket. Another option, look for the mysql.sock file on the server ans then...

$ mysql -u ... -p ... -S /path/to/mysql.sock

share|improve this answer
    
Using the 127.0.0.1 did not work. There is no mysql.sock file on the server. The --protocol=tcp parameter specified above worked great. –  cwd Jun 30 '11 at 3:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.