问题描述
我刚刚在WordPress网站上手动安装了一个新插件,并在MySQL中为该插件的条目创建了一个表,当我尝试打开使用该插件的页面时,出现此错误:
I just manually installed a new plugin on my WordPress site, created a table in MySQL for the plugin's entries, and when I try to open the page that uses the plugin, I receive this error:
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信息(我认为是正确的):
This is the MySQL info listed in my config file (which I believe is correct):
"type" => "Mysql",
"user" => "root",
"pass" => "******",
"host" => "localhost",
"port" => "",
"db" => "******"
这是/etc/my.cnf文件的主要内容:
This is the main contents of the /etc/my.cnf file:
# 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
我已经查看了类似错误的答案,但是没有一个解决方案对我有用.任何帮助将不胜感激.
I've looked at answers to similar errors but none of the solutions worked for me. Any help would be appreciated.
推荐答案
以下是帮助我解决此问题的原因,即我服务器上的实际文件目录为/var/lib/mysql/mysql.sock ,而不是/var/lib/mysqld/mysqld.sock:
Here's what helped me solve this problem, which was that the actual file directory on my server was /var/lib/mysql/mysql.sock, not /var/lib/mysqld/mysqld.sock:
- 打开您的 my.cnf 文件
- 将以下内容添加到您的
[client]
部分(如果没有[client]
部分,则将其添加).它应该看起来像这样:
- Open your my.cnf file
- Add the following to your
[client]
section (if you don't have a[client]
section, then add it). It should look like this:
socket =/var/lib/mysql/mysql.sock
socket=/var/lib/mysql/mysql.sock
错误应该消失了.非常感谢@alvits为我指出正确的方向.
The error should be gone. Many thanks to @alvits for pointing me in the right direction.
这篇关于无法通过套接字'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!