无法通过套接字“/var/lib/mysql/mysql.sock”连接到本地MySQL服务器(2)

我只是在我的WordPress站点上手动安装了一个新的插件,在插件的条目中创build了一个MySQL表格,当我尝试打开使用该插件的页面时,我收到这个错误:

DataTables warning (table id = 'to-do_list'): An error occurred while connecting to the database 'wordpress_clouse'. The error reported by the server was: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 

这是我的configuration文件(我相信是正确的)列出的MySQL信息:

 "type" => "Mysql", "user" => "root", "pass" => "******", "host" => "localhost", "port" => "", "db" => "******" 

这是/etc/my.cnf文件的主要内容:

 # The following options will be passed to all MySQL clients [client] #port = 3306 socket = /var/run/mysqld/mysqld.sock # The MySQL server [mysqld] #port = 3306 socket = /var/run/mysqld/mysqld.sock log_error = mysqld.err skip-networking 

我已经看过类似的错误的答案,但没有解决scheme为我工作。 任何帮助,将不胜感激。

这是什么帮助我解决了这个问题,这是我的服务器上的实际文件目录是/var/lib/mysql/mysql.sock ,而不是/var/lib/mysqld/mysqld.sock:

  1. 打开你的my.cnf文件
  2. 将以下内容添加到[client]部分(如果您没有[client]部分,则将其添加)。 它应该是这样的:

[客户]

插座=的/ var / lib中/ MySQL的/的mysql.sock

错误应该消失。 非常感谢@alvits指导我正确的方向。

遇到同样的错误,发现是因为我还没有开始服务。

执行命令systemctl start mariadb ,然后使用命令mysql连接到MariaDB服务器,它工作。

希望能帮助到你