MySQL忘记密码怎么办

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

如果有一天你忘记了root的密码,我们可以利用 --skip-grant-tables这个参数,具体实施如下:


[root@HE1 bin]# mysql -uroot -p

Enter password:

ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: YES)

[root@HE1 bin]# ps-ef|grep mysql

root      7572 2398  0 00:58 pts/1    00:00:00 /bin/sh ./mysqld_safe--defaults-file=/etc/my.cnf

mysql     8199 7572  0 00:58 pts/1    00:00:00 /usr/local/mysql/bin/mysqld--defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql--plugin-dir=/usr/local/mysql/lib/plugin --user=mysql--log-error=/data/mysql/error.log --open-files-limit=3072--pid-file=/data/mysql/HE1.pid --socket=/data/mysql.sock --port=3306

root      8230 2398  0 00:59 pts/1    00:00:00 grep mysql

[root@HE1 bin]# kill -9 8199 7572

[root@HE1 bin]# ps-ef|grep mysql

root      8232 2398  0 00:59 pts/1    00:00:00 grep mysql

[1]+  Killed                  ./mysqld_safe--defaults-file=/etc/my.cnf

[root@HE1 bin]# ps-ef|grep mysql

root      8234 2398  0 00:59 pts/1    00:00:00 grep mysql

[root@HE1 bin]# ./mysqld_safe --defaults-file=/etc/my.cnf--skip-grant-tables &

[1] 8235

[root@HE1 bin]#160317 00:59:43 mysqld_safe Logging to '/data/mysql/error.log'.

160317 00:59:43mysqld_safe Starting mysqld daemon with databases from /data/mysql

 

[root@HE1 bin]# mysql -uroot

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQLconnection id is 1

Server version:5.6.16-log MySQL Community Server (GPL)

 

Copyright (c) 2000,2014, Oracle and/or its affiliates. All rights reserved.

 

Oracle is aregistered trademark of Oracle Corporation and/or its

affiliates. Othernames may be trademarks of their respective

owners.

 

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

 

mysql> quit

Bye

[root@HE1 bin]# mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQLconnection id is 2

Server version:5.6.16-log MySQL Community Server (GPL)

 

Copyright (c) 2000,2014, Oracle and/or its affiliates. All rights reserved.

 

Oracle is aregistered trademark of Oracle Corporation and/or its

affiliates. Othernames may be trademarks of their respective

owners.

 

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

 

mysql> quit

Bye

 


本文中采用kill-9的方式,这种方式不建议在生产库中使用,生产库中应采用正常停库




 本文转自 dbapower 51CTO博客,原文链接:http://blog.51cto.com/suifu/1753985,如需转载请自行联系原作者


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
关系型数据库 MySQL Apache
window下修改MySQL密码
window下修改MySQL密码
362 6
|
4月前
|
Ubuntu 关系型数据库 MySQL
mysql8.0安装初始化不需要设定root密码?
uubntu 的mysql安装完成后无法设定root密码
306 10
|
5月前
|
关系型数据库 MySQL Linux
CentOS 7系统下详细安装MySQL 5.7的步骤:包括密码配置、字符集配置、远程连接配置
以上就是在CentOS 7系统下安装MySQL 5.7的详细步骤。希望这个指南能帮助你顺利完成安装。
1414 26
|
存储 关系型数据库 MySQL
MySQL 忘记root密码解决方案
【7月更文挑战第19天】
1754 4
|
关系型数据库 MySQL 数据安全/隐私保护
windows mysql8 安装后 提示密码不对,修改下密码认证方式就可以了
windows mysql8 安装后 提示密码不对,修改下密码认证方式就可以了
2237 3
|
10月前
|
存储 关系型数据库 MySQL
【赵渝强老师】解决MySQL丢失root用户密码
本文介绍了MySQL数据库中用户密码存储的变化,以及如何通过特殊方法重置root用户的密码。从MySQL 5.7版本开始,密码字段由“password”改为“authentication_string”。文章详细列出了重置密码的步骤,并提供了相关代码示例和视频教程。
297 0
|
数据可视化 关系型数据库 MySQL
Mysql8 如何在 Window11系统下完成跳过密钥校验、完成数据库密码的修改?
这篇文章介绍了如何在Windows 11系统下跳过MySQL 8的密钥校验,并通过命令行修改root用户的密码。
Mysql8 如何在 Window11系统下完成跳过密钥校验、完成数据库密码的修改?
|
安全 关系型数据库 MySQL
在Linux中,如何重置 mysql root 密码?
在Linux中,如何重置 mysql root 密码?
|
SQL 关系型数据库 MySQL
mysql密码的初始化,修改与重置
【8月更文挑战第16天】在 MySQL 中,可通过特定步骤初始化、修改或重置密码: 1. **初始化密码**:适合首次安装或遗忘 root 密码。需先停用 MySQL 服务,以特殊模式启动(跳过权限表),登录后更新 root 用户密码,并重启服务。 2. **修改密码**:直接使用 `ALTER USER` SQL 语句或通过客户端工具如 MySQL Workbench 修改现有用户的密码。 3. **重置密码**:若遗忘密码且初始化方法不可行,则需停用服务、修改配置文件以允许无密码启动 MySQL,登录后更改密码,并恢复正常配置重启服务。
3608 2
|
关系型数据库 MySQL 数据安全/隐私保护
【MySQL】手把手教你MySQL各版本忘记密码如何处理
【MySQL】手把手教你MySQL各版本忘记密码如何处理

推荐镜像

更多