error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' '

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' '相关的知识,希望对你有一定的参考价值。

 1、今天安装了一个mysql 5.7 的二进制安装方式,在连接mysql数据库的时候报了如下错误:

[[email protected] mysql]# mysql 

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)


2、根据提示应该是sock文件不在,通过查看进程配置,发现如下

[[email protected] bin]# ps -ef | grep mysql

root      9196  3125  0 11:18 pts/2    00:00:00 tail -f mysqld.log

root     11404     1  0 14:13 pts/1    00:00:00 /bin/sh /home/mysql/sysinfo/mysql/bin/mysqld_safe --datadir=/my_data/sysinfo --pid-file=/my_data/sysinfo/iccsdb01.pid

mysql    11616 11404  0 14:13 pts/1    00:00:00 /home/mysql/sysinfo/mysql/bin/mysqld --basedir=/home/mysql/sysinfo/mysql --datadir=/my_data/sysinfo --plugin-dir=/home/mysql/sysinfo/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/my_data/sysinfo/iccsdb01.pid --socket=/var/lib/mysql/mysql.sock


由上可知mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,

但Linux系统总是去/tmp/mysql.sock查找,所以会报错


3、创建连接文件到指定目录上

ln -s /var/lib/mysql/mysql.sock  /tmp/mysql.sock


4、测试连接成功登陆

[[email protected] /]# mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.18 MySQL Community Server (GPL)


Copyright (c) 2000, 2017, 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> 


本文出自 “记录点滴学习生活” 博客,请务必保留此出处http://ureysky.blog.51cto.com/2893832/1919251

以上是关于error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' '的主要内容,如果未能解决你的问题,请参考以下文章

ERROR 1010 (HY000): Error dropping database (can't rmdir './zabbix/', errno: 17)

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist(

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn'

ERROR 2003 (HY000): Can't connect to MySQL server on 'ip'(111)

ERROR 1010 (HY000): Error dropping database (can't rmdir '.qpweb', errno: 41) 删库失败问题的解决

170318 11:44:26 [ERROR] Can't start server: can't create PID file: No space left on device