Can';t通过套接字连接到本地MySQL服务器'/var/lib/mysql/mysql.sock';(2)

Can';t通过套接字连接到本地MySQL服务器'/var/lib/mysql/mysql.sock';(2),mysql,linux,sockets,ubuntu,Mysql,Linux,Sockets,Ubuntu,我只是在我的WordPress站点上手动安装了一个新插件,在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] [200

我只是在我的WordPress站点上手动安装了一个新插件,在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)
这是我的配置文件中列出的MySQL信息(我认为是正确的):

这是/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

我看过类似错误的答案,但没有一个对我有效。任何帮助都将不胜感激。

以下是帮助我解决此问题的原因,即我服务器上的实际文件目录是/var/lib/mysql/mysql.sock,而不是/var/lib/mysqld/mysqld.sock:

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

    socket=/var/lib/mysql/mysql.sock


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

    遇到了同样的错误,发现是因为我还没有启动服务

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


    希望它有帮助

    MySQL可以监听
    TCP套接字
    unix域套接字
    或两者。您的服务器配置设置为在unix域套接字上侦听
    /var/run/mysqld/mysqld.sock
    ,但您的客户端正在连接到unix域套接字
    /var/lib/mysql/mysql.sock
    @alvits:解决方案是将客户端指向
    /var/run/mysqld/mysqld.sock
    ,这就是解决方案。我想这应该写在插件的某个地方?我快速搜索了这个插件,没有提到“mysql.sock”。如果很难识别WordPers,我建议重新配置mysql
    停止MySQL
    ,修改
    /etc/my.cnf
    以使用worpress期望的套接字。最后
    启动MySQL
    。只有当wordpress是这个MySQL的唯一客户机时才这样做,否则很难重新配置所有客户机。回答很有用,虽然你不需要重新启动MySQL服务器,因为它是一个客户机,而不是一个服务器,你正在更改设置。我的网站今天异常宕机,你的回答救了我。但是你能告诉我是什么引起的吗。我的网站在WordPress上,我正在使用amazon实例m4.xlarge。我的站点开始显示错误“建立数据库连接时出错”。我应该去哪里看?谢谢你。很好的帮助。如果数据库断开连接,我假设原因是mariadb没有在引导时启动,请尝试执行“systemctl enable mariadb”。希望有帮助。
    # 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