MySQL5.6重置root用户密码 原创 数据库 2022年9月27日 11:23 夏至未至 930 当前内容 3049 字,在路上,马上到,马上到 ### 前提 本次实测数据库环境为5.6.51,5.6系列版本应该都是如此,5.7系列,请参照:[MySQL5.7重置root用户密码](https://www.codecomeon.com/posts/36/ "MySQL5.7重置root用户密码") #### 1. 编辑实例配置文件 vi /etc/my.cnf 确定是自己数据库实例配置文件 #### 2. 跳过密码验证 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd skip-grant-tables [mysqld_safe] log-error=mysql.log pid-file=mysql.pid # # include all files from the config directory # !includedir /etc/my.cnf.d 上边 **skip-grant-tables** 需要放在 [mysqld] 小节下 #### 3. 重启实例 [root@node1 ClientService]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! 重启实例 **skip-grant-tables** 跳过鉴权才能生效 #### 4. 连接数据库 [root@node1 ~]# mysql -uroot -S /var/lib/mysql/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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> 由于跳过鉴权,密码是不需要填的 #### 5. 修改密码 mysql> update mysql.user set password=password('123456') where user='root'; Query OK, 5 rows affected (0.00 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> #### 6. 刷新数据库 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> 这一步不能忽略,需要加上 #### 7. 退出当前命令窗口后,编辑配置文件,去除 skip-grant-tables ,重启实例 [root@node1 bin]# vi /etc/my.cnf [root@node1 bin]# [root@node1 bin]# [root@node1 bin]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! #### 8. 带密码登录验证 [root@node1 ~]# mysql -uroot -p123456 -S /var/lib/mysql/mysql.sock 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 9 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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> 设置密码后,如果不带密码断然是登陆不上的,带上密码,登陆成功,至此,root密码就成功重置了。 本文标题: MySQL5.6重置root用户密码 本文作者: 夏至未至 发布时间: 2022年9月27日 11:23 最近更新: 2022年10月6日 22:41 原文链接: 许可协议: 署名-非商业性-禁止演绎 4.0 国际(CC BY-NC-ND 4.0) 请按协议转载并保留原文链接及作者 MySQL(28) 密码(2) 上一个 MySQL5.6 解析 BinLog 生成SQL文件 下一个 Android学习书籍推荐 当前文章评论暂未开放,请移步至留言处留言。