1、修改MySQL的登录设置:
vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
保存并且退出vi。
linux下mysql的root密码忘记解决方法
2、重新启动mysqld
[root@lan199 ~]# /etc/init.d/mysqld restart
Stopping mysqld:[OK]
Starting mysqld:[OK]
3、登录并修改MySQL的root密码
mysql
mysql> use mysql;
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker 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: 3Changed: 0Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> q
Bye
[root@lan199 ~]#
4、将MySQL的登录设置修改回来
# vi /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vi。
5、重新启动mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
Ok,现在可以使用新密码登陆mysql数据库了
mysql -u root –ppassword