运维联盟俱乐部

 找回密码
 立即注册
查看: 748|回复: 0

[日常管理] mysql8忘记密码

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2023-5-23 11:03:19 | 显示全部楼层 |阅读模式
    1.修改/etc/my.cnf,添加skip-grant-tables


    1. [mysql]
    2. default-character-set=utf8
    3. [mysqld]
    4. skip-name-resolve
    5. port = 3306
    6. basedir=/usr/local/mysql
    7. datadir=/app/mysql/data
    8. max_connections=200
    9. character-set-server=utf8
    10. lower_case_table_names=1
    11. default-storage-engine=INNODB
    12. skip-grant-tables
    复制代码
    2.启动mysql

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

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

    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.

    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    11. mysql> flush privileges;
    12. Query OK, 0 rows affected (0.04 sec)
    复制代码
    4.修改密码
    1. mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'mysql';
    2. Query OK, 0 rows affected (0.00 sec)

    3. mysql>
    4. mysql>
    5. mysql>
    6. mysql> flush privileges;
    7. Query OK, 0 rows affected (0.01 sec)
    复制代码
    5.关闭数据库
    systemctl stop mysql
    6.去掉my.cnf中的skip-grant-tables
    7.启动数据库,正常密码登录
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-4-29 10:05 , Processed in 0.051081 second(s), 22 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表