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

【MySQL】mysql忘记root密码

作者头像
用户5522200
发布2019-06-02 15:22:44
5K0
发布2019-06-02 15:22:44
举报
文章被收录于专栏:linda

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
复制
[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密码的解决方法,步骤如下
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档