MySQL5.7.26 忘记Root密码小计

本是古典 何须时尚 2023-08-17 15:20 114阅读 0赞

以前直接修改mysql.user就ok了,现在不行了,正好虚拟机MySQL的root密码忘记了,就简单记录下:(本方法不适合互联网线上项目,除非你不在意这段时间的损失)

PS:以UbuntuServer为例(CentOS你把配置文件的位置换下就ok了)

坑点:

  1. 不能和以前一样直接修改user表了,需要使用新命令

    • alter user 'root'@'localhost' identified with mysql_native_password by '复合密码强度的新密码';
  2. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    • flush privileges;

修改密码

1127869-20190615152004033-173568243.jpg

附录

  1. dnt@ubuntuserver:~$ vi /etc/mysql/mysql.conf.d/mysqld.cnf
  2. dnt@ubuntuserver:~$ cat /etc/mysql/mysql.conf.d/mysqld.cnf |grep skip
  3. skip-external-locking
  4. # Instead of skip-networking the default is now to listen only on
  5. skip_name_resolve=on
  6. skip-grant-tables
  7. dnt@ubuntuserver:~$ sudo systemctl restart mysql
  8. dnt@ubuntuserver:~$ mysql -uroot
  9. Welcome to the MySQL monitor. Commands end with ; or \g.
  10. Your MySQL connection id is 2
  11. Server version: 5.7.26-0ubuntu0.18.04.1 (Ubuntu)
  12. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  13. Oracle is a registered trademark of Oracle Corporation and/or its
  14. affiliates. Other names may be trademarks of their respective
  15. owners.
  16. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  17. mysql> select user();
  18. +--------+
  19. | user() |
  20. +--------+
  21. | root@ |
  22. +--------+
  23. 1 row in set (0.01 sec)
  24. mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'WWW.baidu.com1';
  25. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  26. mysql> flush privileges;
  27. Query OK, 0 rows affected (0.01 sec)
  28. mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'WWW.baidu.com1';
  29. Query OK, 0 rows affected (0.00 sec)
  30. mysql> flush privileges;
  31. Query OK, 0 rows affected (0.01 sec)
  32. mysql> exit
  33. Bye

恢复正常

1127869-20190615152221770-2072656488.jpg

附录

  1. dnt@ubuntuserver:~$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
  2. dnt@ubuntuserver:~$ cat /etc/mysql/mysql.conf.d/mysqld.cnf |grep skip
  3. skip-external-locking
  4. # Instead of skip-networking the default is now to listen only on
  5. skip_name_resolve=on
  6. # skip-grant-tables
  7. dnt@ubuntuserver:~$ sudo systemctl restart mysql
  8. dnt@ubuntuserver:~$ mysql -uroot -p
  9. Enter password:
  10. Welcome to the MySQL monitor. Commands end with ; or \g.
  11. Your MySQL connection id is 2
  12. Server version: 5.7.26-0ubuntu0.18.04.1 (Ubuntu)
  13. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  14. Oracle is a registered trademark of Oracle Corporation and/or its
  15. affiliates. Other names may be trademarks of their respective
  16. owners.
  17. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  18. mysql> select user();
  19. +----------------+
  20. | user() |
  21. +----------------+
  22. | root@localhost |
  23. +----------------+
  24. 1 row in set (0.00 sec)

转载于:https://www.cnblogs.com/dotnetcrazy/p/11027732.html

发表评论

表情:
评论列表 (有 0 条评论,114人围观)

还没有评论,来说两句吧...

相关阅读