在我的例子中,我已经将套接字文件移动到/etc/my.cnf内的另一个位置
从/var/lib/mysql/mysql.sock到/tmp/mysql.sock
即使在重新启动mysqld服务后,当我尝试连接时,我仍然看到错误消息。
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) < / p >
问题在于客户端的配置方式。运行诊断将实际显示正确的套接字路径。如ps aux | grep mysqld
工作原理:
mysql -uroot -p -h127.0.0.1
mysql -uroot -p --socket=/tmp/mysql.sock
hostname:/var/lib/mysql #
.protected IT files ibdata1 mysqld.log systemtemp
.tmp NEWS greekDB mysql mysqld.pid test
ARXEIO TEMP1 ib_logfile0 mysql.sock polis
DATING deisi ib_logfile1 mysql_upgrade_info restore
eric@dev ~ $ mysql -u dev -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/var/lib/mysql/mysql.sock' (2)
eric@dev ~ $
所以你必须像这样指定主机:
eric@dev ~ $ mysql --host=yourdb.yourserver.com -u dev -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 235
Server version: 5.6.19 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| performance_schema |
+-------------------------+
3 rows in set (0.00 sec)
mysql> exit
Bye
eric@dev ~ $