前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >【MySQL】mysql忘记root密码

【MySQL】mysql忘记root密码

作者头像
用户5522200
发布2019-06-02 15:22:44
发布2019-06-02 15:22:44
5.1K00
代码可运行
举报
文章被收录于专栏:lindalinda
运行总次数:0
代码可运行

mysql数据库忘记root密码的解决方法,步骤如下

① # vim /etc/my.cnf 在[mysqld]下添加skip-grant-tables,然后保存并退出 ② 重启mysql服务:service mysqld restart ③ 执行 mysql 命令进入数据库,修改数据库密码 MySQL> UPDATE mysql.user SET Password=PASSWORD('新密码') where USER='root'; 如果是MySQL5.7,需要改为MySQL> UPDATE mysql.user SET authentication_string=PASSWORD('新密码') where USER='root'; mysql> flush privileges; ④ 把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql, 即:service mysqld restart ⑤ 下面就可以用root新的密码登录了

代码语言:javascript
代码运行次数:0
运行
复制
[root@ops04 scripts]# vim /etc/my.cnf
[root@ops04 scripts]# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]
[root@ops04 scripts]# 
[root@ops04 scripts]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.22-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 
MariaDB [(none)]> set password=password('000000');
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('000000') where USER='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@ops04 scripts]# vim /etc/my.cnf
[root@ops04 scripts]# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]
[root@ops04 scripts]# 
[root@ops04 scripts]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.22-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • mysql数据库忘记root密码的解决方法,步骤如下
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档