环境
$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.21
解决步骤
sudo vim /etc/my.cnf
修改
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
为
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
重启mysql,进入mysql命令行
sudo service mysqld restart
mysql
执行
use mysql;
update user set authentication_string=password('new_pwd') where user='root';
exit
然后把/etc/my.cnf文件改回来,重启mysql,重试登陆
sudo service mysqld restart
mysql -u root -p