MySQL5.7初始化后5种密码重置方法
前言:由于好几次安装MySQL5.7后一直被重置密码所困扰,因此特意整理重置的方法
安装MySQL5.7
[root@node1 db]# ll 以下的rpm安装包可以随处下载
total 402356
-rw-r--r-- 1 root root 24744 Nov 25 2015 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 25106088 Mar 5 10:24 mysql-community-client-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 3781636 Mar 5 10:24 mysql-community-devel-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2239868 Mar 5 10:24 mysql-community-libs-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 172992596 Mar 5 10:25 mysql-community-server-5.7.22-1.el7.x86_64.rpm
[root@node1 db]#
[root@node1 db]# rpm -ivh *.rpm --nodeps --force
warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.22-1.el7################################# [ 20%]
2:mysql-community-client-5.7.22-1.e################################# [ 40%]
3:libaio-0.3.109-13.el7 ################################# [ 60%]
4:mysql-community-server-5.7.22-1.e################################# [ 80%]
5:mysql-community-devel-5.7.22-1.el################################# [100%] 启动mysql
[root@node1 db]# systemctl start mysqld 从日志中获取随机生成的密码
[root@node1 db]# grep password /var/log/mysqld.log
2018-07-15T09:01:09.735836Z 1 [Note] A temporary password is generated for root@localhost: ViFg8pWf+,lU
[root@node1 db]# mysql -uroot -pViFg8pWf+,lU
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
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 databases;
ERROR 1820 (HY000): Unknown error 1820
mysql> select * from mysql;
ERROR 1046 (3D000):
方法1:使用alter修改
mysql> ALTER USER USER() IDENTIFIED BY 'Reid790!@#$';
Query OK, 0 rows affected (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tom579#$%^&'; #针对localhost
Query OK, 0 rows affected (0.00 sec) 或者先关闭其密码策略修改
mysql> select @@validate_password_length;
ERROR 1820 (HY000): Unknown error 1820
mysql> ALTER USER USER() IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0.00 sec) validate_password_policy有以下取值:
Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
方法2:使用set password
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Gerk087@&#@'); #第一次也要符合密友复杂度
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
方法3:使用update
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('Marry583@&%!'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
方法4:使用mysql_secure_installation
[root@node1 db]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: Marry583@&%!
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root. Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Tom579#$%^& Re-enter new password: Tom579#$%^& Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
为了安全应该yes
Remove anonymous users? (Press y|Y for Yes, any other key for No) : No ... skipping. Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
为了安全应该yes
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : No ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment. 为了安全应该yes
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : No ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success. All done!
方法5:跳过授权列表skip-grant-tables
[root@node1 db]# mysql
ERROR 1045 (28000): Unknown error 1045
[root@node1 db]# vim /etc/my.cnf #使用完后去掉
[mysqld]
skip-grant-tables=1 重启mysql,再修改
[root@node1 db]# systemctl restart mysqld
[root@node1 db]# 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> set password = PASSWORD('Reid4909@%&');
ERROR 1290 (HY000): Unknown error 1290
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tom579#$%^&';
ERROR 1290 (HY000): Unknown error 1290
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> set password = PASSWORD('Reid4909@%&');
ERROR 1133 (42000):
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tom579#$%^&';
Query OK, 0 rows affected (0.01 sec) mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
Summary
a. mysql5.7安装好后会在/var/log/mysql.log中产随机密码,而且不修改密码不能执行任何操作
b. mysql5.7的user表中的password字串修改为authentication_string
c. 修改密码的Policy转变是1(中级),因此设置时要符合规则
d. 跳过授权列时,同时也不受密码policy影响
MySQL5.7初始化后5种密码重置方法的更多相关文章
- centos系统mysql数据库忘记密码重置方法(ERROR 1045 28000 Access denied...)
当mysql的密码错误的时候,就会报如下这样的错误信息 解决方法如下: 首先输入mysqld_safe --skip-grant-tables 然后停止mysql服务,输入service mysqld ...
- MySQL密码重置方法
MySQL数据库的安装和配置,配置Mysql按照bin目录到Path中 使用命令行窗口连接MYSQL数据库:mysql –u用户名 –p密码 对于密码的重置有以下两种方法(卸载重新安装当然也可以): ...
- mysql 8.0.15忘记密码重置方法
1.打开命令窗口cmd,输入命令:net stop mysql,停止MySQL服务, 2.开启跳过密码验证登录的MySQL服务 输入命令 mysqld --console --skip-grant-t ...
- Linux用户密码重置方法
方法一: 启动时,随便按一个键,空格即可(不能是回车),让其停留在如下界面 按e编辑 在UTF-8后面添加init=/bin/sh init=/bin/sh 根据上面提示,按Ctrl+x启动得下图 输 ...
- Windows Server 2012 (2008) 忘记密码重置方法 Windows 10 忘记密码
要使用windows server 2012安装DVD,选择光盘引导进入 进入修复系统---命令提示符---切换目录至系统目录--执行move命令 先备份 utilman.exe(他就是这个程 ...
- MAC MYSQ忘记密码重置方法
网友的方法,记个笔记请勿转载. step1: 关闭mysql服务: 苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) ...
- ubuntu下MySQL忘记密码重置方法
方法一: 1):编辑mysqld.cnf文件 sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 2):在文件中的skip-external-locking一行的下面 ...
- pymysql_mysql密码重置方法,连接局域网数据库的解决办法
https://blog.csdn.net/qq_37176126/article/details/72824106 pymysql模块的操作 https://blog.csdn.net/skh2 ...
- wamp5 忘记mysql root密码 重置方法
wamp5比较恶心,忘记mysql root密码了,重新安装都没用,网上找了个文章可以修改root的密码. http://www.kuqin.com/database/20080306/4249.ht ...
随机推荐
- js实现图片上传方法
知识点 onchange事件 循环 封装函数 ajax php Javascript代码 //找到元素 var file=document.getElementById("file" ...
- (二十三)c#Winform自定义控件-等待窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- JMeter的JavaRequest探究
1.背景 最近笔者的一位老朋友咨询了一个问题:在自定义的Java请求中如何编写多个请求?老朋友反应他们发送请求只能基于这种Java请求形式(代码调需用三方封装的jar包).这个问题恰巧不久前在笔者所在 ...
- Element-UI 2.4.11 版本 使用注意(发现一点更新一点)
1.$Vue.$refs.addForm.resetFields() 的resetFields()方法重置到默认值并不是 ,你在form绑定对象上写的默认值 ,而是这个form被渲染出来之后第一次赋到 ...
- javascript——原型与继承
一.什么是继承? 继承是面向对象语言的一个重要概念.许多面向对象语言都支持两种继承方式:接口继承和实现继承:接口继承只继承方法签名,而实现继承则继承实际的方法.由于函数没有签名,所以ECMAScrip ...
- Mac 隐藏、显示文件;移动开发者常用路径
Mac Finder 标题显示文件完整路径 // mac Finder 标题栏显示文件夹完整路径, 把YES改为NO则是不显示 defaults write com.apple.finder _FXS ...
- 分布式事务TransactionScope所导致几个坑
记录一下,个人见解,欢迎指正 错误: 1.该伙伴事务管理器已经禁止了它对远程/网络事务的支持. (异常来自 HRESULT:0x8004D025)2.事务已被隐式或显式提交,或已终止3.此操作对该事务 ...
- python 38 线程队列与协程
目录 1. 线程队列 1.1 先进先出(FIFO) 1.2 后进先出(LIFO)堆栈 1.3 优先级队列 2. 事件event 3. 协程 4. Greenlet 模块 5. Gevent模块 1. ...
- 使用ansible对思科交换机备份
先决条件 - 了解ansible基本操作 - 了解网络设备相关操作 - 了解linux相关操作 安装 安装EPEL yum install https://dl.fedoraproject.org/p ...
- Docker容器技术的核心
容器技术的核心 所谓容器,其实是由Linux Namespace.Linux Cgroups和rootfs三种技术构建出来的进程的隔离环境 对于Docker项目来说,其实最核心就是为待创建的用户进程: ...