我收到了这个错误
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
即使我已经设法通过ubuntu中的命令行启动mysql
mysql stop/waiting
mysql start/running, process 17691
Run Code Online (Sandbox Code Playgroud)
但是,当尝试访问该站点时,我在尝试访问mysql时遇到数据库连接错误以及上述错误 mysql -u root -p
我检查了我的错误日志,我看到了这个
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)
Run Code Online (Sandbox Code Playgroud)
这是我第一次看到这个错误,我不知道如何解决这个问题,请在这里帮助我.
谢谢
UPDATE
好的,我尝试了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)
Run Code Online (Sandbox Code Playgroud)
Wel*_*ndo 50
我的问题已经解决,检查进程是否在Ubuntu 12.04上运行
ps ax | grep mysql
Run Code Online (Sandbox Code Playgroud)
然后答案是它没有运行,所以我做到了
sudo service mysql start
Run Code Online (Sandbox Code Playgroud)
或者试试
sudo /etc/init.d/mysql start
Run Code Online (Sandbox Code Playgroud)
joh*_*nny 39
首先,请确认已安装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
Run Code Online (Sandbox Code Playgroud)
小智 12
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
find / -name '*.sock'
Run Code Online (Sandbox Code Playgroud)
to find the mysql.sock file and then used
ln -s <the file location> /var/run/mysqld/mysqld.sock
Run Code Online (Sandbox Code Playgroud)
to get a link for the*.sock file then tried mysql and it ran without error. Hope this could solve yours.
Remember to create the directory if it does not exists.
feu*_*eux 10
应将客户端设置为与服务器设置一致.
[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
Run Code Online (Sandbox Code Playgroud)
小智 9
这花了我很多年才弄清楚,但你可以尝试相同 -
1 - 更新和升级
sudo apt-get update
sudo apt-get upgrade
Run Code Online (Sandbox Code Playgroud)
2 - 清除MySQL服务器和客户端(如果已安装).
sudo apt-get purge mysql-server mysql-client
Run Code Online (Sandbox Code Playgroud)
3 - 安装MySQL服务器和客户端
sudo apt-get install mysql-server mysql-client
Run Code Online (Sandbox Code Playgroud)
4 - 测试MySQL
mysql -u root -p
> enter root password
Run Code Online (Sandbox Code Playgroud)
***应该在/var/run/mysqld/mysql.sock中找不到套接字
4 - 使用nano的vi配置mysqld.cnf
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address从127.0.0.1更改为localhost
bind-address = localhost
Run Code Online (Sandbox Code Playgroud)
**写和退出
5 - 重启MySQL
sudo /etc/init.d/mysql restart
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
你现在应该进入mysql cli.
希望这可以帮助
Code.Ph0y
小智 8
你不需要重新安装 MySQL 服务器 我遇到了同样的问题,但我已经通过运行这些命令解决了这个问题。
ps -A|grep mysqlsudo pkill mysqlps -A|grep mysqldsudo pkill mysqldsudo service mysql restartmysql -u root -p小智 5
最近我在mysql中遇到了这个错误
ERROR 2002 (HY000):
无法通过套接字连接到本地MySQL服务器
'/var/lib/mysql/mysql.sock'(111)
因为我忘了开始我的mariadb。只需在您的终端上键入此命令即可。
systemctl start mariadb.service
Run Code Online (Sandbox Code Playgroud)
在 linux 终端中,我运行以下步骤,他们帮助了我
1.首先列出所有安装的mysql包
sudo dpkg -l | grep mysql
Run Code Online (Sandbox Code Playgroud)
2.使用列出的命令删除列出的包
sudo apt-get --purge autoremove <package name>
Run Code Online (Sandbox Code Playgroud)
3.重新安装mysql服务器
sudo apt-get install mysql-server
Run Code Online (Sandbox Code Playgroud)
这对我有用,希望这对你也有用。
或者试试
sudo apt-get remove --purge mysql-\
Run Code Online (Sandbox Code Playgroud)
然后重新安装
sudo apt-get install mysql-server mysql-client
Run Code Online (Sandbox Code Playgroud)
如果你仔细观察,你会发现差异:
/var/run/mysqld/mysqld.sock/var/run/mysqld/mysql.sock您必须调整其中之一。