mysql忘记密码的解决办法

本文详细介绍了在阿里云上遇到MySQL密码遗忘时的解决步骤,包括停止MySQL服务、跳过授权方式启动、重置密码及使新密码生效的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

很久之前在阿里云上装的mysql,最近想用的时候发现忘记密码了,
这时候可以用下面的方法解决

1、停止mysql,可以直接杀进程
root@iZ286yyopd3Z ~]# netstat -tlnp | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      21763/mysqld        
[root@iZ286yyopd3Z ~]# kill -9 21763
2、跳过授权方式启动
[root@iZ286yyopd3Z ~]# /bin/mysqld_safe --defaults-file=my.cnf --skip-grant-tables  --skip-networking &
[1] 10981
[root@iZ286yyopd3Z ~]# Could not open required defaults file: /root/my.cnf
Fatal error in defaults handling. Program aborted
WARNING: Defaults file 'my.cnf' not found!
Could not open required defaults file: /root/my.cnf
Fatal error in defaults handling. Program aborted
WARNING: Defaults file 'my.cnf' not found!
Logging to '/var/lib/mysql/iZ286yyopd3Z.err'.
190510 15:11:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
190510 15:11:55 mysqld_safe mysqld from pid file /var/lib/mysql/iZ286yyopd3Z.pid ended

[1]+  Done                    /bin/mysqld_safe --defaults-file=my.cnf --skip-grant-tables --skip-networking
[root@iZ286yyopd3Z ~]#
3、进入mysql,输密码的时候直接敲回车即可
[root@iZ286yyopd3Z ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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>
4、重置密码,并使其生效

注意,如果是5.6的版本,重置密码的命令为:
update mysql.user set password=password(‘123456’) where host=‘localhost’ and user=‘root’;
如果是5.7以及以上版本,则

mysql> update mysql.user set authentication_string=password('123456') where  user='root';
Query OK, 5 rows affected (0.14 sec)
Rows matched: 5  Changed: 5  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值