linux下mysql root密码忘记的解决方法
1,首先,确认服务器出于安全的状态
确保非授权的用户,禁止连接MySQL数据库。
在重新设置mysql的root密码期间,MySQL数据库完全处于没有密码保护的状态,其他的用户可以任意地登录和修改MySQL的信息。
可以采用将MySQL对外的端口封闭,并且停止Apache以及所有的用户进程。
最安全的方法,当然是到服务器的Console终端上操作,并且拔掉网线,这个不安全都不行,呵呵。
2,修改MySQL登录设置:
在[mysqld]段中加上:
skip-grant-tables
例如:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存,退出vi。
3,重新启动mysqld
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4,登录并修改MySQL的root密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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 ( 'new-password' ) WHERE User = 'root' ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
5,将MySQL的登录设置修改回来
# vi /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除,保存并退出vi。
6,重启mysqld
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
至此,mysql的root密码,就修改完成了。
不过,还是建议大家保管好自己的root密码,毕竟找回密码的过程,还是费时费力的。
您可能感兴趣的文章:
修改mysql密码与忘记mysql密码的处理方法
mysql修改root密码的几种方法
mysql root密码忘记怎么办 mysql中root密码修改方法
mysql 忘记密码重置的方法分享
修改mysql数据库密码的方法
mysql忘记密码的解决方法
Windows下mysql5.1忘记root密码的解决方法
MySQL 忘记密码的解决办法
linux忘记root密码的解决办法(图文)
修改MYSQL的root权限与密码的方法