首页 > 代码库 > Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

很久沒弄mysql,今天突然想做下練習,於是去打開mysql,系統提示錯誤:

Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ 。

去查下位於/etc/my.cnf(一般情況都是在這個目錄下),裏面內容如下:

  1 [mysqld]
  2 datadir=/var/lib/mysql
  3 socket=/var/lib/mysql/mysql.sock
  4 user=mysql
  5 # Disabling symbolic-links is recommended to prevent assorted security risks
  6 symbolic-links=0
  7 
  8 [mysqld_safe]
  9 log-error=/var/log/mysqld.log
 10 pid-file=/var/run/mysqld/mysqld.pid
 11 
 12 [mysql.server]
 13 user=mysql
 14 basedir=/usr/local/mysql
 15 
 16 [client]
 17 socket=/var/lib/mysql/mysql.sock 

 似乎沒錯,於是去找下問題所在,發現原來mysql沒有打開(打開mysql需要root權限)。

使用命令service mysqld start打開。這樣就可以用mysql -u root -p登錄了。