手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下MySQL忘记root用户密码

[日期:2015-02-11] 来源:Linux社区  作者:doiido [字体:大 中 小]

今天在接收一台MySQL服务器的时候发现忘记MySQL的root用户的密码,查找资料发了各种文档里面也没有root用户密码,因此需要修改root用户密码。

首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库。因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的状态下,其他的用户也可以任意地登录和修改MySQL的信息。最安全的状态是到服务器的Console上面操作,并且拔掉网线。

1、修改MySQL的登录设置:
在[mysqld]的段中加上的skip-grant-tables
# sed -i '/mysqld/a\skip-grant-tables ' /etc/my.cnf

2、重新启动mysqld
# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!

3、登录并修改MySQL的root密码
# /usr/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 Source distribution

Copyright (c) 2000, 2014, 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.

mysql> USE mysql ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

mysql> UPDATE user SET Password = password ( 'linuxidc' ) WHERE User = 'root' ;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
 
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

4、将MySQL的登录设置修改回来
将刚才在[mysqld]的段中加上的skip-grant-tables删除
# sed -i "/skip-grant-tables/d" /etc/my.cnf

5、重新启动mysqld
# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!

这个时候,就可以使用root/linuxidc进行登录了

Linux下MySQL的root密码忘记解决方法  http://www.linuxidc.com/Linux/2014-01/95509.htm

Windows/Linux MySQL忘记root密码的解决方法 http://www.linuxidc.com/Linux/2013-07/87069.htm

MySQL忘记root密码解决方法 http://www.linuxidc.com/Linux/2013-04/83024.htm

MySQL 更改root密码 http://www.linuxidc.com/Linux/2013-01/77207.htm

在Ubuntu中如何重置MySQL服务器的root密码 http://www.linuxidc.com/Linux/2012-12/76405.htm

Red Hat 下 MySQL root密码恢复 http://www.linuxidc.com/Linux/2012-12/75970.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-02/113251.htm

linux
相关资讯       MySQL root  MySQL忘记root用户密码 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款