详解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


猜你喜欢
- 一、原理概述Query Cache就是把“查询返回的结果”缓存起来。但是,仅仅只是缓存“查询返回的结果”,其实是不准确的,Query Cac
- 一、标准的数据集流程梳理分为几个步骤数据准备以及加载数据库–>数据加载器的调用或者设计–>
- 本文实例讲述了Python使用sorted排序的方法。分享给大家供大家参考,具体如下:# 例1. 按照元素出现的次数来排序seq = [2,
- 介绍当创建一个应用程序时,通常希望能够告诉你的应用程序如何做某事。有两种流行的方法来完成这项任务,你可以让应用程序接受命令行参数,或者创建一
- 一、介绍对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github.com/m
- 基本思路就是,使用MIMEMultipart来标示这个邮件是多个部分组成的,然后attach各个部分。如果是附件,则add_header加入
- 在看本篇文章前我们需要了解阻塞的概念在执行过程中暂停,以等待某个条件的触发 ,我们就称之为阻塞在Go中我们make一个channel有两种方
- 引用计数Python默认的垃圾收集机制是“引用计数”,每个对象维护了一个ob_ref字段。它的优点是机制简单,当新的引用指向该对象时,引用计
- 前端开发环境多数基于Node.js,好处不多说了。但与使用Visual Studio开发的后端Asp.Net Core项目一起调试,却不是很
- 本文实例讲述了Python redis操作。分享给大家供大家参考,具体如下:一、redisredis是一个key-value存储系统。和Me
- 我最近用MYSQL数据库挺多的,发现了一些非常有用的小玩意,今天拿出来分享到大家,希望对你会有所帮助。1.group_concat在我们平常
- 注意,本文代码是使用在txt文档上,同时txt文档中的内容每一行代表的是图片的名字。#coding:utf-8 import shutil
- 如何提高ASP的效率?通过修改注册表来提高asp的执行效率 改的第一个地方:HKEY_LOCAL_MAC
- 一、算法简要我们希望有这么一种函数:接受输入然后预测出类别,这样用于分类。这里,用到了数学中的sigmoid函数,sigmoid函数的具体表
- 1.re.match()re.match()的概念是从头匹配一个符合规则的字符串,从起始位置开始匹配,匹配成功返回一个对象,未匹配成功返回N
- messageboxtkinter.messagebox中封装了多种消息框,其输入参数统一为title, message以及其他参数。其中t
- Python适配器模式,代码,思考等# -*- coding: utf-8 -*-# author:baoshanclass Compute
- JavaScript游戏开发之键盘控制层的移动截图:<html> <head> <meta http-equi
- 说明相应的学习视频见链接,本文只对重点进行总结。多进程重点(只要看下面代码的main函数即可)1.创建2.如何开守护进程3.多进程,开销大,
- 要访问一个MySQL服务器,你需要使用一个用户帐号登录其中方可进行。每个MySQL用户帐号都有许多与之相关连的属性,例如用户名、密码以及权限