Mysql 报错:Cant connect to local MySQL server through socket /var/lib/mysql/mysql.sock

时间:2019-11-20 08:52:02  来源:igfitidea点击:

执行命令
mysql -u root -p登录mysql时,报错:

Cant connect to local MySQL server through socket /var/lib/mysql/mysql.sock (2)

如何解决?

检查MySQL是否在运行

执行下面的命令

# service mysqld status

如果mysqld没有运行,则启动:

# service mysqld start

再次尝试mysql登录命令,如下所示:

$ mysql -u USER -p

检查系统是否安装了MySQL?

确保已安装软件包mysql-server:

# rpm -qa mysql-server

如果看不到软件包名称,则执行下面的命令,安装mysql-server:

# yum install mysql-server

设置开机时自启动:

# chkconfig mysqld on

运行mysqld服务:

# service mysqld start

为mysql服务器设置新的root密码:

# mysqladmin -u root password 'MySQL-Root-User-Password'