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)
Glorfindel
  • 1,213
  • 4
  • 15
  • 22
cwd
  • 2,763
  • 9
  • 33
  • 48
  • 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 01: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 01: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 02:11

3 Answers3

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)

ghm1014
  • 944
  • 1
  • 5
  • 14
0

From the mysql(1) man page:

  ·   --host=host_name, -h host_name

      Connect to the MySQL server on the given host.
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
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

TomKro
  • 136
  • 2
  • 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 03:15