当我尝试连接mysql时,我得到以下错误:
无法通过套接字/var/lib/ MySQL / MySQL连接到本地MySQL服务器。袜子”(2)
有解决这个错误的方法吗?背后的原因可能是什么?
当我尝试连接mysql时,我得到以下错误:
无法通过套接字/var/lib/ MySQL / MySQL连接到本地MySQL服务器。袜子”(2)
有解决这个错误的方法吗?背后的原因可能是什么?
当前回答
我也有同样的问题,当我研究日志时
Sudo tail -f /var/log/mysqld.log
InnoDB: mmap(137363456 bytes) failed; errno 12
200610 6:27:27 InnoDB: Completed initialization of buffer pool
200610 6:27:27 InnoDB: Fatal error: cannot allocate memory for the buffer pool
200610 6:27:27 [ERROR] Plugin 'InnoDB' init function returned error.
200610 6:27:27 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
200610 6:27:27 [ERROR] Unknown/unsupported storage engine: InnoDB
200610 6:27:27 [ERROR] Aborting
很明显没有足够的内存来启动InnoDB。我意识到我从来没有设置交换文件…
我按照这个设置交换文件,它工作。
其他回答
以下是对我有效的方法:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
service mysqld restart
确保您的mysql服务正在运行
service mysqld start
然后,试试下面的方法:
(如果你没有设置mysql密码)
mysql -u root
如果您已经设置了密码
mysql -u root -p
在我的情况下,我已经将套接字文件移动到/etc/my.cnf内的另一个位置 从/var/lib/mysql/mysql.Sock到/tmp/mysql.sock
即使在重新启动mysqld服务后,当我尝试连接时,我仍然看到错误消息。 错误2002 (HY000):无法通过套接字/var/lib/ MySQL / MySQL连接到本地MySQL服务器。袜子”(2)
问题在于客户端的配置方式。运行诊断将实际显示正确的套接字路径。Eg ps aux | grep mysqld
工作原理:
mysql -uroot -p -h127.0.0.1
mysql -uroot -p --socket=/tmp/mysql.sock
不工作:
mysql -uroot -p
mysql -uroot -p -hlocalhost
你可以通过在mysql配置的[client]部分中添加相同的套接字行来解决这个问题。
先尝试2、3种解决方案。如果您无法找到/var/lib/mysql/mysql.sock .sock,则仍然弹出错误提示
find /var/ -name mysql.sock
检查/var/中的可用空间
df
如果目录已满,请删除一些无用的文件/目录
rm /var/cache/*
也许你的问题现在可以解决了。
重现此错误的一种方法:如果您打算连接到外部服务器,但却连接到不存在的本地服务器:
eric@dev ~ $ mysql -u dev -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/var/lib/mysql/mysql.sock' (2)
eric@dev ~ $
所以你必须像这样指定主机:
eric@dev ~ $ mysql --host=yourdb.yourserver.com -u dev -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 235
Server version: 5.6.19 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| performance_schema |
+-------------------------+
3 rows in set (0.00 sec)
mysql> exit
Bye
eric@dev ~ $