详解mysql5.7密码忘记解决方法
作者:Matrix-bystander 发布时间:2024-01-28 16:10:00
标签:mysql5.7,忘记密码
ENV:
[root@centos7 ~]# uname -r
3.10.0-514.el7.x86_64
[root@centos7 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@centos7 ~]# rpm -qa mysql
[root@centos7 ~]# rpm -qa |grep mysql
mysql-community-common-5.7.26-1.el7.x86_64
mysql-community-client-5.7.26-1.el7.x86_64
mysql57-community-release-el7-11.noarch
mysql-community-server-5.7.26-1.el7.x86_64
mysql-community-libs-5.7.26-1.el7.x86_64
mysql-community-libs-compat-5.7.26-1.el7.x86_64
登陆时出错:
[root@centos7 ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
密码忘记了(和刚安装后不知道密码一样)
网上有人说mysql的密码是空密码,其实在mysql5.7版本之后,密码不再是空密码了,
如果是刚安装的,可以在mysql的日志文件找到
grep 'temporary password' /var/log/mysqld.log
补充:如果找到mysql提供的密码,可以使用
mysqladmin -u root -p 'mysql提供的密码' password ‘自己的新密码'
直接修改mysql的密码,但这种方法存在安全隐患,毕竟密码在命令行上显示了,不建议但不反对。
如果是忘记,修改如下:
1.修改 /etc/my.cnf,加入 skip-grant-tables;
[root@centos7 ~]# vim /etc/my.cnf
空白位置加入,并保存退出;
[mysqld]
skip-name-resolve
skip-grant-tables
[root@centos7 ~]# systemctl restart mysqld
2.空密码直接进入mysql;
[root@centos7 ~]# mysql -u root -p
Enter password: (这里是空密码,直接回车)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
进入mysql库;
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>
这里的mysql并不是没变,数据库位置是变化的;
3.修改密码:UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
4改回/etc/my.cnf
注释掉 #skip-grant-tables
[root@centos7 ~]# vim /etc/my.cnf
[mysqld]
skip-name-resolve
#skip-grant-tables
[root@centos7 ~]# systemctl restart mysqld
5.用新的密码再进入mysql;
[root@centos7 ~]# mysql -u root -p
Enter password: (之前演示为newpassword)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26
Copyright (c) 2000, 2019, 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>
6.更改root密码,更改root密码: alter user 'root'@'localhost' identified by '密码';
修改用户密码;
ALTER USER testuser IDENTIFIED BY '123456';
修改当前登录用户
ALTER USER USER() IDENTIFIED BY '123456';
mysql> alter user user() identified by 'Linuxpassword!@#';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user user() identified by 'LINUX123password!@#';
Query OK, 0 rows affected (0.00 sec)
mysql>
可以看出,密码的复杂度有了很大的要求;
7.修改完成后就可以继续操作mysql了
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
以上所述是小编给大家介绍的mysql5.7密码忘记解决方法详解整合网站的支持!
来源:https://blog.csdn.net/silent_ghost/article/details/89819511
0
投稿
猜你喜欢
- 使用cv2.imread(),cv2.imshow(),cv2.imwrite()读取、显示和保存图像一、读入图像使用函数cv2.imrea
- 前言之前一直写不出来,这周周日花了一下午终于弄懂了, 顺便放博客里,方便以后忘记了再看看。 要实现的是输入一张 图,起点,终点,输出起点和终
- 什么是函数重载?简单的理解,支持多个同名函数的定义,只是参数的个数或者类型不同,在调用的时候,解释器会根据参数的个数或者类型,调用相应的函数
- 本文实例讲述了Python装饰器用法。分享给大家供大家参考,具体如下:用类作为装饰器示例一最初代码:class bol(object): d
- 一、首先你要确认你的鉴别模式:WIN NT鉴别模式呢还是混合模式,其中混合模式包括WIN NT鉴别模式和SQL SERVER 鉴别模式实施鉴
- 引子编程世界里只存在两种基本元素,一个是数据,一个是代码。编程世界就是在数据和代码千丝万缕的纠缠中呈现出无限的生机和活力。数据天生就是文静的
- 在用python的bottle框架开发时,前端使用ajax跨域访问时,js代码老是进入不了success,而是进入了error,而返回的状态
- APScheduler就是定时进行周期性的运行某些程序,在语言程序编写中,一直会遇到些定时服务,有时是根据时间定时,有时在固定的位置上进行定
- 前三篇文章中,明确了栅格系统的设计细节和适用范围。这一篇将集中讨论960栅格系统的技术实现。Blueprint的实现Blueprint是一个
- pip install *** :Cannot connect to proxy在使用pip install 安装任何新的包都会出现下面错误
- 问题有二进制文件中保存了 20 亿个 2 Bytes 的数,需将其读出,每 20000 个数作图,拟合后输出结果。解决# -*- codin
- 简单低级的爬虫速度快,伪装度低,如果没有反爬机制,它们可以很快的抓取大量数据,甚至因为请求过多,造成服务器不能正常工作。而伪装度高的爬虫爬取
- 主要采用的技术点Python + Numpy + PIL在正文代码开始前,大家先看看最初原图和转换手绘风图片前后对比。当然了,我先查了手绘的
- 一直以来,我们大多使用js来实现弹出菜单,可是根据 w3c 的css标准,根本就没有这个必要。只需要简单得使用css+html就可以做出一个
- 基本代码from redis import *if __name__ == '__main__': sr = StrictR
- Base64是一种用64个字符来表示任意二进制数据的方法。用记事本打开exe、jpg、pdf这些文件时,我们都会看到一大堆乱码,因为二进制文
- 1、ComboBox的基础属性# -*- encoding=utf-8 -*-import tkinterfrom tkinter impo
- eval 是干嘛的?解析字符串表达式并执行,并返回一个值语法格式eval(expression[, globals[, locals]])
- MySQL的命令行提示符及其表达的意思mysql> 准备好接受新命令。 &n
- 朴素贝叶斯估计朴素贝叶斯是基于贝叶斯定理与特征条件独立分布假设的分类方法。首先根据特征条件独立的假设学习输入/输出的联合概率分布,然后基于此