mysql忘记密码修改

偶尔会忘记mysql密码,特别是在测试环境中,此时该怎么办呢?
mysql忘记密码修改
1、关闭mysql

[root@vm01 ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

2、启动mysql时跳过mysql的用户验证

[root@vm01 ~]# /usr/libexec/mysqld --skip-grant-tables       
170512 21:27:16  InnoDB: Initializing buffer pool, size = 8.0M
170512 21:27:16  InnoDB: Completed initialization of buffer pool
170512 21:27:17  InnoDB: Started; log sequence number 0 900270
170512 21:27:17 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

3、另开一个终端,登录mysql(不要指定用户密码,因为此时没有开启mysql用户验证)

[root@vm01 src]# mysql -h127.0.0.1 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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> select host,user,password from user;
+-------------------------+------+-------------------------------------------+
| host                    | user | password                                  |
+-------------------------+------+-------------------------------------------+
| localhost               | root | *DBB5837ZB74329105ER4568DDA7DC67ED2CA2ABC |
| tongyeyun01.localdomain | root | *DBB5837ZB74329105ER4568DDA7DC67ED2CA2ABC |
| 127.0.0.1               | root | *DBB5837ZB74329105ER4568DDA7DC67ED2CA2ABC |
+-------------------------+------+-------------------------------------------+
3 rows in set (0.00 sec)

此时,看不到密码原文,只看到密码md5加密后的密文。
4、mysql命令行中重新修改密码

# password函数中字符串为你需要设置的密码
mysql> update user set password=password("123456"); 
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

5、杀掉mysqld进程

[root@vm01 ~]# kill -9 `ps -ef|grep mysqld|grep -v grep|awk '{print $2}'`
[root@vm01 ~]# ps -ef|grep mysqld
root     14971 14500  0 21:49 pts/3    00:00:00 grep mysqld

6、重启mysql服务,并使用新设置密码登录

[root@vm01 ~]# service mysqld start
Starting mysqld:                                           [  OK  ]
[root@vm01 ~]# mysql -h127.0.0.1 -uroot -p123456 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cmdb_v2            |
| monitor            |
| mysql              |
| ops                |
| test               |
| test_ops           |
+--------------------+
7 rows in set (0.00 sec)

mysql> 

ok,密码已修改成功,并可正常使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值