Mysql 密码忘记如何修改密码

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: Mysql 密码忘记如何修改密码 Linux服务器,把mysql数据库密码忘记了。 [root@VM_0_13_centos ~]# mysql -uroot -p  Enter password:  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 密码忘了登陆不了MySQL了。

Mysql 密码忘记如何修改密码

Linux服务器,把mysql数据库密码忘记了。

[root@VM_0_13_centos ~]# mysql -uroot -p 
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
密码忘了登陆不了MySQL了。

1、首先停止mysql服务进程:

service mysqld stop 

然后编辑mysql的配置文件my.cnf(目的是跳过密码验证)

 vim /etc/my.cnf 

在最后面添加一段代码

 skip-grant-tables   ##忽略mysql权限问题,直接登录

然后保存 :wq!退出

2.重启service mysqld start 服务进程

[root@VM_0_13_centos my.cnf.d]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 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> show database
 

使用mysql表,然后进行修改mysql的root密码:

mysql> use mysql; ##使用mysql数据库
 2 Reading table information for completion of table and column names
 3 You can turn off this feature to get a quicker startup with -A
 4 
 5 Database changed
 6 mysql> update user set password=password("123456") where user="root";##更新密码()
 7 Query OK, 4 rows affected (0.00 sec)
 8 Rows matched: 4  Changed: 4  Warnings: 0
 9 
10 mysql> flush privileges;##刷新权限
11 Query OK, 0 rows affected (0.00 sec)

 

注意:我在更新的时候发现user表提示没有password 这一栏,原来是我这个版本这个栏位更新成新名字:authentication_string

update user set authentication_string=password("123456")  where user="root"
    -> ;
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 1
 

3.切回配置文件中将添加的那一行删除就可以了。vim /etc/my.cnf

4.重启数据库服务。

[root@VM_0_13_centos etc]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 

此时,可以发现已经不能登录了。

 

[root@VM_0_13_centos etc]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.7.22 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> 

原文地址https://blog.csdn.net/weixin_39316363/article/details/81269626

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
关系型数据库 MySQL 数据库
MySQL忘记root密码、远程无法连接的解决方法
MySQL忘记root密码、远程无法连接的解决方法
|
3月前
|
Ubuntu 关系型数据库 MySQL
百度搜索:蓝易云【ubuntu下Mysql安装与root密码重置教程】
请注意,以上步骤是针对Ubuntu系统的。如果你使用的是其他Linux发行版,请相应地调整命令。
110 1
|
5月前
|
存储 关系型数据库 MySQL
Centos Mysql忘记密码,修改密码
Centos Mysql忘记密码,修改密码
323 0
|
1月前
|
SQL 关系型数据库 MySQL
阿里云MySQL数据库价格、购买、创建账号密码和连接数据库教程
阿里云数据库使用指南:购买MySQL、SQL Server等RDS实例,选择配置和地区,完成支付。创建数据库和账号,设置权限。通过DMS登录数据库,使用账号密码访问。同地域VPC内的ECS需将IP加入白名单以实现内网连接。参考链接提供详细步骤。
371 3
|
1月前
|
关系型数据库 MySQL 数据库
【MySQL】——忘记密码后如何修改密码
【MySQL】——忘记密码后如何修改密码
44 0
|
8月前
|
关系型数据库 MySQL Linux
Linux登录mysql忘记密码Access denied for user ‘root‘@‘localhost‘ (using password: YES)错误
Linux登录mysql忘记密码Access denied for user ‘root‘@‘localhost‘ (using password: YES)错误
78 0
|
4月前
|
关系型数据库 MySQL Linux
CentOS7下忘记MySQL数据库root密码与密码过期
CentOS7下忘记MySQL数据库root密码与密码过期
123 0
|
6月前
|
SQL 网络协议 关系型数据库
【MySQL用法】在MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES) 拒绝访问,并可修改MySQL密码
【MySQL用法】在MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES) 拒绝访问,并可修改MySQL密码
123 1
|
8月前
|
关系型数据库 MySQL 数据库
MySQL忘记root密码的解决方法
MySQL数据库多次输入密码错误再登陆或者不输入密码会提示如下错误信息,如下图:
137 0
|
2天前
|
SQL 存储 关系型数据库
MySQL Cluster集群安装及使用
MySQL Cluster集群安装及使用