MySQL5.7初始化后5种密码重置方法

前言:由于好几次安装MySQL5.7后一直被重置密码所困扰,因此特意整理重置的方法

安装MySQL5.7

[[email protected] 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
[[email protected] db]#
[[email protected] 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
[[email protected] db]# systemctl start mysqld

从日志中获取随机生成的密码
[[email protected] db]# grep password /var/log/mysqld.log
2018-07-15T09:01:09.735836Z 1 [Note] A temporary password is generated for [email protected]: ViFg8pWf+,lU
[[email protected] 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 ‘[email protected]#$‘;
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(‘[email protected]&#@‘);  #第一次也要符合密友复杂度
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(‘[email protected]&%!‘), 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

[[email protected] db]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: [email protected]&%!
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

[[email protected] db]# mysql
ERROR 1045 (28000): Unknown error 1045
[[email protected] db]# vim /etc/my.cnf  #使用完后去掉
[mysqld]
skip-grant-tables=1

重启mysql,再修改
[[email protected] db]# systemctl restart mysqld
[[email protected] 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(‘[email protected]%&‘);
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(‘[email protected]%&‘);
ERROR 1133 (42000):
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Tom579#$%^&‘;
Query OK, 0 rows affected (0.01 sec)

mysql> set password for [email protected] = 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影响

原文地址:https://www.cnblogs.com/reid21/p/9314376.html

时间: 2024-11-10 18:39:15

MySQL5.7初始化后5种密码重置方法的相关文章

centOS7忘记密码重置方法

线索Cues重启和关机命令重启命令:reboot.init 6.shutdown -r now关机命令:init 0.poweroff切换系统环境:chroot查看文件内容:cat更改密码:passwd root定义语言:LANG=en 笔记Notes1.开机在选择操作系统介面,按"e"键(相关于进入系统启动盘)2.找到Linux16这一行,定位到"ro"处,将"ro"(只读)改成"rw"(读写)3.在"rw&quo

phpstudy升级mysql到mysql5.7.17后修改root密码

按照上一篇文章走完流程后,接着下面继续 1. 到D:\phpStudy\MySQL\data目录找到.err文件(不同版本可能名字不一样,但只有一个.err文件) 我的是z-PC.err 2. 这个就是初始密码 3. 打开cmd 输入mysql -uroot -p    然后输入初始密码 4. 注意:然后立即修改密码(密码不能太简单,我设的密码包含小写字母.数字和特殊字符) alter user 'root'@'localhost' indentified by '你的密码'; 原文地址:htt

centos7.2下2种密码修改方法(验证可行)

centos7.2和centos6使用的引导不一样,centos7用的gurb2,centos6用的grub,因此他们的密码修改有不少差距. 下面有2个种方法,实现密码修改: 测试环境,虚拟机VMware Workstation11,系统centos7.2: 方法一: 1.启动系统,选中第一行,按"e"进入编辑模式 2.键盘向下键,找到linux16这行 3.把 ro 改成rw:添加 init=/bin/sh  :把lang前面2个单词删除:把zh_CN.UTF-8  改成 en_EN

MAC MYSQ忘记密码重置方法

网友的方法,记个笔记请勿转载. step1: 关闭mysql服务:  苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) step2: 进入终端输入:cd /usr/local/mysql/bin/    回车后 登录管理员权限 sudo su    回车后输入以下命令来禁止mysql验证功能 ./mysqld_safe --skip-grant-tables &    回车后mysql会自动重启(偏好设置中mysql

忘记CentOS 7.0 root密码后,更改密码的方法如下

1.启动画面出来时,选择第一项,并按下e字母键.如下图 2.移动光标键,找到linux16这一行.如下图 3.如图,将ro改成成为rw init=sysroot/bin/sh,并执行ctrl-x 4.执行以下命令,如下图 5.最后重启,进入系统

zzcms8.2#任意用户密码重置#del.php时间盲注#复现

00x0 引言 早上起来,发现seebug更新了一批新的洞, 发现zzcms8.2这个洞好多人在挖,于是我就默默的踏上了复现之路(要不是点进去要买详情,我何必这么折腾~) 环境:zzcms8.2(产品招商型) php-5.4.45 . mysql-5.5.53 01x0 任意用户密码重置 01x1 任意用户密码重置方式一 话说,这个洞的标题应该是任意前台用户密码重置,后台管理员重置不了的,或许是我复现的问题.~~ 先注册个账号,然后首页点击找回密码. 地址:http://localhost/on

CentOS 7系统root用户忘记密码的重置方法

CentOS 7 的密码重置方法 进入到下面箭头指向的按"e" 跳入到下面的界面把"ro"删了改成"rw init=/sysroot/bin/sh" 按下面的命令进行操作 然后重启系统当下面箭头指向的位置加载到100%就说明密码修改成功了 . 然后用新密码登陆

自动修改mysql5.7初始化密码

mysql5.7为了安全考虑,初始化后root密码随机生成,密码放在error日志里面. 分两步: 第一步获取error.log密码. 修改默认密码, passwd=`grep 'generated for [email protected]' $base_log/error.log|awk '{print $NF}'` expect <<! spawn /app/mysql/servers/bin/mysql -uroot -p expect "*password*" s

华为交换机Console密码重置和设备初始化

1. 华为交换机Console密码重置 1.通过Console口连接交换机,并重启交换机.2.当界面出现以下打印信息时,及时按下快捷键"Ctrl+B"并输入BootROM/BootLoad密码,进入BootROM/BootLoad主菜单3.密码: [email protected] A必须大写.4.选着7 Clear password for console user (选择清除console用户密码模式).5.选择1 Boot with default mode(键入1启动默认模式)