Linux下 mysql忘记root用户密码

今天在接收一台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.cnf2、重新启动mysqld# service mysqld restartShutting down MySQL. SUCCESS!Starting MySQL. SUCCESS!3、登录并修改MySQL的root密码# /usr/bin/mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.19 Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.mysql> USE mysql ;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> UPDATE user SET Password = password ( ‘doiido’ ) WHERE User = ‘root’ ;Query OK, 3 rows affected (0.01 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> flush privileges ;Query OK, 0 rows affected (0.01 sec)mysql> quitBye4、将MySQL的登录设置修改回来将刚才在[mysqld]的段中加上的skip-grant-tables删除# sed -i "/skip-grant-tables/d" /etc/my.cnf5、重新启动mysqld# service mysqld restartShutting down MySQL. SUCCESS!Starting MySQL. SUCCESS!

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

我想去旅行,一个人背包,一个人旅行,

Linux下 mysql忘记root用户密码

相关文章:

你感兴趣的文章:

标签云: