mysql 8.0忘记root密码
1、修改参数文件添加以下内容 skip-grant-tables 2、关闭数据库 [root@node01 ~]# /etc/init.d/mysqld8 stop Shutting down MySQL. SUCCESS! 3、重启数据库 [root@node01 ~]# /etc/init.d/mysqld8 start Starting MySQL.. SUCCESS! 4、修改用户密码为空 mysql> update mysql.user set authentication_string='' where user='root' and host='localhost'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.02 sec) 5、关闭数据库 [root@node01 ~]# /etc/init.d/mysqld8 stop Shutting down MySQL. SUCCESS! 6、去掉参数文件中以下内容 skip-grant-tables 7、启动数据库 [root@node01 ~]# /etc/init.d/mysqld8 start Starting MySQL.. SUCCESS! 8、使用空密码登录数据库 [root@node01 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 9、修改用户密码 mysql> alter user 'root'@'localhost' identified by 'mysql'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 10、使用新密码登录数据库 [root@node01 ~]# mysql -uroot -pmysql mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>