1在配置文件中添加skip-grant-tables后重启mysql,然后直接登录
[root@tyjs09 ~]# cat /etc/my.cnf [mysqld] user=mysql basedir=/application/mysql datadir=/data/mysql/data socket=/tmp/mysql.sock server_id=6 port=3306 gtid-mode=on enforce-gtid-consistency=true log_error=/data/mysql/data/mysql.log log_bin=/data/binlog/mysql-bin secure-file-priv=/tmp innodb_flush_method=o_direct lower_case_table_names=1 skip-grant-tables
2更新密码
mysql> flush privileges; query ok, 0 rows affected (0.00 sec) mysql> alter user "root"@"localhost" identified by "123456"; error 1396 (hy000): operation alter user failed for 'root'@'localhost' mysql> use mysql;select user,host from user;root | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 4 rows in set (0.00 sec) mysql> alter user 'root'@'%' identified with mysql_native_password by '123456'; query ok, 0 rows affected (0.00 sec) mysql> flush privileges;
3在配置文件中去掉免登录然后重启mysql:
[root@tyjs09 ~]# vim /etc/my.cnf [mysqld] user=mysql basedir=/application/mysql datadir=/data/mysql/data socket=/tmp/mysql.sock server_id=6 port=3306 gtid-mode=on enforce-gtid-consistency=true log_error=/data/mysql/data/mysql.log log_bin=/data/binlog/mysql-bin secure-file-priv=/tmp innodb_flush_method=o_direct lower_case_table_names=1 skip-grant-tables #去掉
[root@tyjs09 ~]# service mysql restart shutting down mysql.. success! starting mysql. success! [root@tyjs09 ~]# mysql -uroot -p123456 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 8 server version: 8.0.19 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>
到此这篇关于mysql8.0.19忘记密码处理方法详解的文章就介绍到这了,更多相关mysq忘记密码处理内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
“张承辉博客” mysql8.0.19忘记密码处理方法详解 https://www.zhangchenghui.com/267397