`

mysql 密码忘记 解决方案

阅读更多
1.关闭mysql 服务
[root@local ~]#etc/rc.d/init.d/mysqld stop
 
2.测试检查mysql是否真的关闭
#netstat -antl | grep 3306  或用ps 的方式查看进程
 
3.开启mysql用 --skip-grant-tables 参数
 
[root@local ~]# /usr/bin/mysqld_safe --skip-grant-tables --user=mysql &
[1] 24076
[root@local ~]# Starting mysqld daemon with databases from /var/lib/mysql

4.mysql -u root -p 通过空密码进入mysql,
 
[root@local ~]# mysql -u root -p
Enter password:                    #### 直接按回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> use mysql;          ###这里需要使用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
 
5.利用mysql库中的user表,重新设置密码
mysql> update user set password=password('123456') where user='root';
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2  Changed: 2  Warnings: 0

6:flush privileges 刷新缓冲区
 
mysql> flush privileges;
 
7. 退出mysql ,并重新启动mysql 服务

mysql> quit
 
[root@local ~]# /etc/rc.d/init.d/mysqld restart   ##确保设置生效
 
8.使用新设置密码登录:
[root@local ~]# mysql -u root -p
Enter password:                                #输入新设置密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

############################END####################################
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics