ERROR 2002 (HY000): 无法通过 socket '/var/run/mysqld/mysql.sock' 连接到本地 MySQL 服务器 (2)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19658891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
提问by user2028856
I'm getting this error
我收到这个错误
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
even though I have managed to start mysql via command line in ubuntu
即使我已经设法在 ubuntu 中通过命令行启动了 mysql
mysql stop/waiting
mysql start/running, process 17691
However when attempting to access the site I get a database connection error as well as the above error when trying to access mysql via mysql -u root -p
但是,当尝试访问该站点时,我在尝试通过以下方式访问 mysql 时收到数据库连接错误以及上述错误 mysql -u root -p
I checked my error logs and I saw this
我检查了我的错误日志,我看到了这个
131029 12:53:34 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be remo$
131029 12:53:34 [Note] Plugin 'FEDERATED' is disabled.
131029 12:53:34 InnoDB: The InnoDB memory heap is disabled
131029 12:53:34 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131029 12:53:34 InnoDB: Compressed tables use zlib 1.2.3.4
131029 12:53:34 InnoDB: Initializing buffer pool, size = 26.0G
131029 12:53:36 InnoDB: Completed initialization of buffer pool
131029 12:53:36 InnoDB: highest supported file format is Barracuda.
131029 12:53:38 InnoDB: Waiting for the background threads to start
131029 12:53:39 InnoDB: 5.5.34 started; log sequence number 5146431500
131029 12:53:39 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
131029 12:53:39 [Note] - '0.0.0.0' resolves to '0.0.0.0';
131029 12:53:39 [Note] Server socket created on IP: '0.0.0.0'.
131029 12:53:39 [Note] Event Scheduler: Loaded 0 events
131029 12:53:39 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.34-0ubuntu0.12.04.1-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
It's the first time I see this error and I'm not sure how to solve this issue, please help me out a bit here.
这是我第一次看到这个错误,我不知道如何解决这个问题,请在这里帮助我。
Thanks
谢谢
UPDATE
更新
Okay I tried glglgl's solution and after a restart, I get the following in the error log:
好的,我尝试了 glglgl 的解决方案,重新启动后,我在错误日志中看到以下内容:
131029 13:17:36 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be remo$
131029 13:17:36 [Note] Plugin 'FEDERATED' is disabled.
131029 13:17:36 InnoDB: The InnoDB memory heap is disabled
131029 13:17:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131029 13:17:36 InnoDB: Compressed tables use zlib 1.2.3.4
131029 13:17:36 InnoDB: Initializing buffer pool, size = 26.0G
131029 13:17:38 InnoDB: Completed initialization of buffer pool
131029 13:17:38 InnoDB: highest supported file format is Barracuda.
131029 13:17:40 InnoDB: Waiting for the background threads to start
131029 13:17:41 InnoDB: 5.5.34 started; log sequence number 5146431500
131029 13:17:41 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
131029 13:17:41 [Note] - '127.0.0.1' resolves to '127.0.0.1';
131029 13:17:41 [Note] Server socket created on IP: '127.0.0.1'.
131029 13:17:41 [Note] Event Scheduler: Loaded 0 events
131029 13:17:41 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.34-0ubuntu0.12.04.1-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
回答by Wellington Lorindo
My problem was solved checking if the process was running on Ubuntu 12.04
我的问题解决了检查进程是否在 Ubuntu 12.04 上运行
ps ax | grep mysql
Then the answer was that it wasn't running, so I did
然后答案是它没有运行,所以我做了
sudo service mysql start
Or try
或者试试
sudo /etc/init.d/mysql start
回答by johnny
Firstly, please confirm mysql-server is installed. I have the same error when mysql-server is installed but corrupted somehow. I do the trick by uninstall mysql completelyand reinstall it.
首先,请确认安装了mysql-server。安装 mysql-server 但不知何故损坏时,我遇到了同样的错误。我通过完全卸载 mysql并重新安装它来解决这个问题。
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server mysql-client
回答by krgaurav
I had the same problem when i installed xampp on my system. The mysql server looks for /var/run/mysqld/mysqld.sock but the mysql.sock file was in xampp folder so i used
我在系统上安装 xampp 时遇到了同样的问题。mysql 服务器查找 /var/run/mysqld/mysqld.sock 但 mysql.sock 文件在 xampp 文件夹中,所以我使用
find / -name '*.sock'
to find the mysql.sock file and then used
找到mysql.sock文件然后使用
ln -s <the file location> /var/run/mysqld/mysqld.sock
to get a link for the *.sock file then tried mysql and it ran without error. Hope this could solve yours.
获取 *.sock 文件的链接,然后尝试 mysql 并且它运行没有错误。希望这可以解决你的问题。
Remember to create the directory if it does not exists.
如果目录不存在,请记住创建该目录。
回答by feuyeux
The client should be set consistent with server setting.
客户端设置应与服务器设置一致。
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
回答by Code Ph0y
This took me ages to figure out but could you try the same -
这花了我很长时间才弄明白,但你能不能试试同样的——
1 - Update and Upgrade
1 - 更新和升级
sudo apt-get update
sudo apt-get upgrade
2 - Purge MySQL Server and Client (if installed).
2 - 清除 MySQL 服务器和客户端(如果已安装)。
sudo apt-get purge mysql-server mysql-client
3 - Install MySQL Server and Client fresh
3 - 全新安装 MySQL 服务器和客户端
sudo apt-get install mysql-server mysql-client
4 - Test MySQL
4 - 测试 MySQL
mysql -u root -p
> enter root password
*** should get socket not found in /var/run/mysqld/mysql.sock
*** 应该在 /var/run/mysqld/mysql.sock 中找不到套接字
4 - Configure mysqld.cnf with nano of vi
4 - 使用 vi 的 nano 配置 mysqld.cnf
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
须藤纳米 /etc/mysql/mysql.conf.d/mysqld.cnf
Change bind-address from 127.0.0.1 to localhost
将绑定地址从 127.0.0.1 更改为 localhost
bind-address = localhost
** Write and Exit
** 写入和退出
5 - Restart MySQL
5 - 重启 MySQL
sudo /etc/init.d/mysql restart
6 - check mysql
6 - 检查 mysql
mysql -u root -p
> enter root password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
You should get in to mysql cli now.
您现在应该进入 mysql cli。
Hope this helps
希望这可以帮助
Code.Ph0y
代码.Ph0y
回答by Aung Kyaw Nyunt
recently i have faced with this error in my mysql
ERROR 2002 (HY000)
:
最近我在我的 mysql 中遇到了这个错误
ERROR 2002 (HY000)
:
Can't connect to local MySQL server through socket
'/var/lib/mysql/mysql.sock' (111)
无法通过套接字连接到本地 MySQL 服务器
'/var/lib/mysql/mysql.sock' (111)
because i forget to start my mariadb. just type this command on ur terminal.
因为我忘记启动我的 mariadb。只需在您的终端上键入此命令。
systemctl start mariadb.service
回答by Ranju R
You may be missing mysql-server. install it using
您可能缺少 mysql-server。安装它使用
sudo apt-get install mysql-server
回答by Endre Simo
This is an old tread with different solution proposed, but none of them worked for me. I'm adding this answer in the hope it will help somebody who struggled as me for some time.
这是一个旧的胎面,提出了不同的解决方案,但没有一个对我有用。我正在添加这个答案,希望它能帮助那些像我一样挣扎了一段时间的人。
I've checked all the existing answers and all the existing solution, but for me the issue was incorrect user permission on var/run/mysql
folder.
我已经检查了所有现有的答案和所有现有的解决方案,但对我来说问题是var/run/mysql
文件夹的用户权限不正确。
I've checked the user permission on that folder and it was set to root
. Once i changed to mysql:mysql
the problem has gone.
我已经检查了该文件夹的用户权限,并将其设置为root
. 一旦我改变mysql:mysql
了问题就消失了。
So enter into /var/run/mysqld
and change the user permission to:
所以进入/var/run/mysqld
并将用户权限更改为:
chown -R mysql:mysql .
回答by schlusie
I deleted everything connected to mysql with
我删除了连接到 mysql 的所有内容
sudo apt-get remove --purge --auto-remove mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7
sudo rm -r /etc/mysql* /var/lib/mysql* /var/log/mysql*
sudo apt-get remove --purge --auto-remove mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7
须藤 rm -r /etc/mysql* /var/lib/mysql* /var/log/mysql*
and then reinstalled it again with
然后重新安装它
sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get 更新
须藤 apt-get 安装 mysql-server
and then started it with
然后开始
mysql -u root -p
mysql -u 根 -p
followed by the password
然后是密码
回答by Chudamani Sanju
You don't need to reinstall MySQL serverI was facing the same issue but I have resolved the issue by running these commands.
你不需要重新安装 MySQL 服务器我遇到了同样的问题,但我已经通过运行这些命令解决了这个问题。
1 ps -A|grep mysql
2 sudo pkill mysql
3 ps -A|grep mysqld
4 sudo pkill mysqld
5 sudo service mysql restart
6 mysql -u root -p