admin 发表于 2023-5-23 11:03:19

mysql8忘记密码

1.修改/etc/my.cnf,添加skip-grant-tables



default-character-set=utf8

skip-name-resolve
port = 3306
basedir=/usr/local/mysql
datadir=/app/mysql/data
max_connections=200
character-set-server=utf8
lower_case_table_names=1
default-storage-engine=INNODB
skip-grant-tables
2.启动mysql

systemctl start mysql
3.无密码登录mysql,-p提示输入密码后,直接回车进入
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.27 MySQL Community Server - GPL

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> flush privileges;
Query OK, 0 rows affected (0.04 sec)
4.修改密码
mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'mysql';
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)5.关闭数据库
systemctl stop mysql
6.去掉my.cnf中的skip-grant-tables
7.启动数据库,正常密码登录
页: [1]
查看完整版本: mysql8忘记密码