MySQL 5.7.x修改root默认密码
1.编辑my.cnf文件加入skip-grant-tables,忽略密码登录
[root@node1 ~]# vi /etc/my.cnf
[mysqld]
skip-grant-tables
[root@node1 ~]# sudo service mysql restart
2.修改密码
[root@node1 ~]# mysql
mysql> update mysql.user set authentication_string=PASSWORD('root1234') where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit;
3.开启密码登录
[root@node1 ~]# vi /etc/my.cnf
[mysqld]
#skip-grant-tables
[root@node1 ~]# sudo service mysql restart
4.修复错误
[root@node1 ~]# mysql -uroot -proot1234;
[root@node1 ~]# mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root1234'
Query OK, 0 rows affected (0.09 sec)