1

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)
3
  • 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, 2011 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, 2011 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, 2011 at 2:11

3 Answers 3

2

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)

0
0

From the mysql(1) man page:

  ·   --host=host_name, -h host_name

      Connect to the MySQL server on the given host.
1
  • tried that with the same result. I'll edit the question with the result.
    – cwd
    Jun 27, 2011 at 1:30
0

$ 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

1
  • 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, 2011 at 3:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .