Mysql 单机多实例密码丢失的处理

本文介绍了一种通过停用MySQL服务,使用skip-grant-tables参数启动来绕过密码验证,然后利用UPDATE语句修改MySQL管理员密码的方法。最后,通过正常方式重启MySQL服务,并使用新密码登录。

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

1.停用mysql
2.使用skip-grant-tables参数启动
3.update语句更新密码
4.重开mysql,正常登录密码更改后的mysql


1.停用mysql

#停用mysql 如若没有密码也只能killall mysqld ,这里我有密码只是演示所以还是平滑关闭
[root@master01 bin]# mysqladmin -uroot -poracle -S /data/3307/mysql.sock shutdown
[root@master01 bin]# netstat -lntup|grep 330


2.使用skip-grant-tables参数启动

#使用skip-grant-tables参数启动mysql,忽略授权登录验证
[root@master01 bin]# mysqld_safe --defaults-file=/data/3307/my.cnf  --skip-grant-tables --user=mysql

#无密码方式登录mysql
[root@master01 bin]#  mysql -uroot -S /data/3307/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.39-log Source distribution

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

#利用update 语句更新用户密码
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
3.update语句更新密码

mysql> update user set password=password('oracle123456') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye


4.重开mysql,正常登录密码更改后的mysql

#使用更新密码关闭mysql并开启
[root@master01 ~]# mysqladmin -uroot -poracle123 -S /data/3307/mysql.sock shutdown

#启动mysql 3307
[root@master01 bin]# mysqld_safe --defaults-file=/data/3307/my.cnf  --user=mysql

#登录mysql
[root@master01 bin]#  mysql -uroot -S /data/3307/mysql.sock -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.39-log Source distribution
Copyright (c) 2000, 2014, 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.

OK
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值