mysql安装后修改默认密码提示error: 'Can't connect to local MySQL server through socket

场景

通过yum安装mysql成功之后,执行下面的命令:

 mysqladmin -u root password 'xxxx'

然后报错信息如下:

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'

解决方案

修改my.cnf文件,默认路径是在/etc下。默认内容如下:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

修改之后的内容如下:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
socket=/var/lib/mysql/mysql.sock

[client]
socket=/var/lib/mysql/mysql.sock

[mysqldump]
socket=/var/lib/mysql/mysql.sock

[mysqladmin]
socket=/var/lib/mysql/mysql.sock

修改后保存,然后重启mysql服务,执行一开始的命令,mysql的root的默认登录密码就可以设置成功。

Well Done!!!

你可能感兴趣的:(linux,mysql)