CentOs:ERROR 2002 (HY000): Can't connect to local MySQL

MySql 码拜 8年前 (2016-05-19) 1588次浏览
使用CentOs7 安装 mysql,命令 yum install mysql
但是运行 mysql 一直提示
ERROR 2002 (HY000): Can”t connect to local MySQL server through socket “/var/lib/mysql/mysql.sock” (2)
整个流程:
1.yum install mysql
2.rpm -qa | grep mysql //空的
3.whereis mysql

[root@webmaster /]# whereis mysql
mysql: /usr/bin/mysql /usr/share/man/man1/mysql.1.gz

4.那几个文件其实根本不存在的

[root@webmaster /]# ls -l /var/lib/mysql/mysql.sock
ls: cannot access /var/lib/mysql/mysql.sock: No such file or directory
[root@webmaster /]# ls -l /var/lib/mysql
ls: cannot access /var/lib/mysql: No such file or directory

安装过程的代码:

================================================================================
 Package         Arch           Version                   Repository       Size
================================================================================
Installing:
 mariadb         x86_64         1:5.5.37-1.el7_0          updates         8.9 M
Transaction Summary
================================================================================
Install  1 Package
Total download size: 8.9 M
Installed size: 49 M
Is this ok [y/d/N]: y
Downloading packages:
mariadb-5.5.37-1.el7_0.x86_64.rpm                                                                                      | 8.9 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-5.5.37-1.el7_0.x86_64                                                                                            1/1
  Verifying  : 1:mariadb-5.5.37-1.el7_0.x86_64                                                                                            1/1
Installed:
  mariadb.x86_64 1:5.5.37-1.el7_0
Complete!
[root@webmaster /]# whereis mysql
mysql: /usr/bin/mysql /usr/share/man/man1/mysql.1.gz
[root@webmaster /]# mysql
ERROR 2002 (HY000): Can"t connect to local MySQL server through socket "/var/lib/mysql/mysql.sock" (2)
[root@webmaster /]# rpm -qa | grep mysql --color
[root@webmaster /]# ls -l /etc/my.cnf
-rw-r--r-- 1 root root 570 Jun 24 04:55 /etc/my.cnf
[root@webmaster /]# nano /etc/my.cnf
  GNU nano 2.3.1                                  File: /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
解决方案

10

先touch /var/lib/mysql/mysql.sock
然后再重启服务试试看看能不能自动生成这个文件.

30

检查一下MYSQL的错误日志,看其中的信息是什么。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明CentOs:ERROR 2002 (HY000): Can't connect to local MySQL
喜欢 (0)
[1034331897@qq.com]
分享 (0)