筆記: mysql client 出現 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/loc

2022110421:29
# mysql test -p -uroot
出現錯誤訊息
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/mysql.sock' (2)
 

原因

通常是 mysql.sock 檔案路徑不對
mysql.sock 通常會放在 /var/lib/mysql/mysql.sock

而剛安裝的 mysql (mariaDB) 通常 /etc/my.cnf 是空的內容
 

解法一:

/etc/my.cnf 加入這段即可
[client]
port            = 3306
socket         = /var/lib/mysql/mysql.sock

 

解法二:

可行,但不優
$ ln -s  /var/lib/mysql/mysql.sock /usr/local/mysql/mysql.sock


  •   mini 於 2021-06-11 11:54 1F
  • 11
    22
    33
  • 版主於 2021-06-11 12:09 回覆
    44aaa111111
    55bbb
    66cccccc1111