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

时间:2020-01-09 10:37:33  来源:igfitidea点击:

运行mysql -u root -p时收到以下错误

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

无法通过套接字/var/lib/mysql/mysql.sock连接到本地MySQL服务器(2)

如何在CentOS/RHEL/Red Hat Enterprise Linux服务器5.x或6.x下解决此问题?
要解决此问题,请执行以下步骤。

MySQL正在运行吗?

输入以下命令

# service mysqld status

如果mysqld没有运行,请启动它:

# service mysqld start

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

$ mysql -u USER -p

是否已安装MySQL?

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

# rpm -qa mysql-server

输出示例:

mysql-server-5.1.61-4.el6.x86_64

如果看不到软件包名称,请键入以下命令以安装mysql-server:

# yum install mysql-server

打开mysqld以在启动时自动启动:

# chkconfig mysqld on

运行mysqld服务,输入:

# service mysqld start

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

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