Linux – How to connect with MySQL server if it won’t connect via the socket

linuxMySQLsocketunix

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)

Best Answer

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)