忘记mysql 8 密码,怎么办

2022-03-17  本文已影响0人  青玉_f18c
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
# 但都是要在[myqld]这个节点下添加
skip-grant-tables
[root@centos8.2 dir]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select user,authentication_string,host,plugin from user;
image.png
mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql  
//或者  
mysql -u root -p   
password直接回车  
# 执行这个
ALTER user 'root'@'localhost' IDENTIFIED with mysql_native_password BY '123456'
# 如果上面的报错,改为
ALTER user 'root'@'%' IDENTIFIED with mysql_native_password BY '123456'
上一篇下一篇

猜你喜欢

热点阅读