MySQL5.7.12新密码登录方式及密码策略
在Centos6.6上安装MySQL5.7.12时,遇到了一个问题
安装后在/root目录下没有发现有.mysql_secret这个文件,所以没有没法按照官方文档上说的那样使用,这里记录下,
解决方式:
首先修改MySQL授权登录方式---(跳过授权验证方式启动MySQL):
[root@test ~]# mysqld_safe --skip-grant-tables &
[]
[root@test ~]# --19T12::.564385Z mysqld_safe Logging to '/var/log/mysqld.log'.
--19T12::.589376Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
检查MySQL启动情况
[root@test ~]# ps -ef | grep mysql
root : pts/ :: /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql : pts/ :: /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
这时登录MySQL不再需要验证
[root@test ~]# mysql
成功登录MySQL后:
切换到mysql系统库:
mysql> use mysql; 修改root账户登录密码:
mysql> update user set password=password('') where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
---报错没有password这个数据字段列
描述user表
mysql> desc user;
...
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
---没发现password列,但是找到这5个跟密码相关的数据字段
查询一下相关的密码信息:
mysql> select user,host,authentication_string,password_expired from user;
+-----------+-----------+-------------------------------------------+------------------+
| user | host | authentication_string | password_expired |
+-----------+-----------+-------------------------------------------+------------------+
| root | localhost | *9AA01F6E2A80A823ACB72CC07337E2911404B5B8 | Y |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N |
+-----------+-----------+-------------------------------------------+------------------+
---到这里不难发现root账户的密码已过期,还比5.6多出了一个mysql.sys用户
修改密码
mysql> update user set authentication_string=password('123abc') where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> exit
密码修改成功,测试:
重启MySQL:
[root@test ~]# /etc/init.d/mysqld restart 登录测试:
[root@test ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-enterprise-commercial-advanced
...
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
---报错,需要使用alter user 修改密码
mysql> alter user root@'localhost' identified by 'oracle';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
---报错,密码不满足制定的密码负责度要求
mysql> alter user 'root'@'localhost' identified by 'Abc!123D';
Query OK, 0 rows affected (0.01 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
关于密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
6 rows in set (0.02 sec) mysql> show plugins;
+----------------------------+----------+--------------------+----------------------+-------------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+----------------------+-------------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | PROPRIETARY | ...
| validate_password | ACTIVE | VALIDATE PASSWORD | validate_password.so | PROPRIETARY |
+----------------------------+----------+--------------------+----------------------+-------------+
---可以通过在配置文件[mysqld]标签中添加 validate_passwor=off ,来关闭密码策略
如下:
...
| validate_password | DISABLED | VALIDATE PASSWORD | validate_password.so | PROPRIETARY |
+----------------------------+----------+--------------------+----------------------+-------------+
总结
1) 安装好mysql后,第一次启动时,root管理密码会在/root/.mysql_secret中随机生成
2) 至5.7后,MySQL的 mysql.user 表中的密码字段由之前的 password 改为 authentication_string
3) 使用--skip-grant-tables 参数启动,跳过MySQL的授权验证,--skip-networking参数,跳过远程登录
4) 修改MySQL密码方式:
法1:update user set authentication_string=password('123abc') where user='root';
法2:set password=password('newpassword');
法3:alter user root@'localhost' identified by 'oracle';
法4:在shell下使用MySQL工具:mysqladmin -uroot -poldpassword pasword "newpassword"
5) 关于MySQL密码策略:
后记
经过一段时间后,发现mysql初始密码原来被记录到了日志文件中
查找日志位置
[root@test /var/lib/mysql]# ps -ef | grep mysql
root : pts/ :: /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql : pts/ :: /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root : pts/ :: grep --color mysql
藏在日志文件中的临时密码
[root@test /var/lib/mysql]# grep "A temporary password" /var/log/mysqld.log
--17T16::.059632Z [Note] A temporary password is generated for root@localhost: +wGVA#to(4tu
MySQL5.7.12新密码登录方式及密码策略的更多相关文章
- 安装xampp之后如何建立远程登录用户并修改登录方式和密码
其实xampp作为开发环是非常好用的,但是很少人将其用作生产环境,主要还是它的安全性较低,很多默认设置都存在安全漏洞,但是实际上使用xampp在Linux下面进行配置确实是很节省时间的一件事(如果你的 ...
- stackstorm docker中配置ssh免密码登录方式
在docker中配置st2的ssh登录方式折腾了好久,今天终于彻底搞懂了如何重启容器后也不丢失之前的配置,只要容器起来后就可以正常ssh 执行st2中的remote-shell-script 和rem ...
- Mysql 免密码登录,修改密码及忘记密码操作
----免密码登陆 方式一 my.cnf增加[client]标签 [client] user="root" password="你的密码" 单对定义不同的客户端 ...
- Amazon ec2 改成密码登录方式
sudo passwd rootsu rootvi /etc/ssh/sshd_config"# PasswordAuthentication yes" uncommentsbin ...
- Telnet的三种登录方式
Telnet的三种登录方式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.华为创建telnet的三种验证方式 首先,我们可以简单的看一个拓扑图,让我们可以在亦庄的路由器上对双桥 ...
- ssh免密码登录之分发密钥
ssh免密码登录之分发密钥 1.ssh免密码登录 密码登录和密钥登录有什么不同? 密码登录(口令登录),每次登录都需要发送密码(ssh) 密钥登录,分为公钥和私钥,公钥相当于锁,私钥相当于钥匙 1.1 ...
- MySQL 8.0.14 新的密码认证方式和客户端链接
MySQL 8.0.14 新的密码认证方式和客户端链接 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. MySQL8.0在密码认证方式发生了改变,这也是有点小伙伴在MySQL创建 ...
- MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法
MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法: 1.备份my.ini 2.在my.ini字段里 [mysqld] #socket=mysql skip-grant-tables ...
- laravel更改默认的登录密码加密方式
laravel更改默认的登录密码加密方式 laravel 默认用的登录密码加密方式是: $password = Hash::make('password'); 而我平时用的密码加密方式是: $pa ...
随机推荐
- Aspose.Words组件介绍及使用—基本介绍与DOM概述
1.基本介绍 Aspose.Words是一个商业.NET类库,可以使得应用程序处理大量的文件任务.Aspose.Words支持Doc,Docx,RTF,HTML,OpenDocument,PDF,XP ...
- nginx 健康检查和负载均衡机制分析
nginx 是优秀的反向代理服务器,这里主要讲它的健康检查和负载均衡机制,以及这种机制带来的问题.所谓健康检查,就是当后端出现问题(具体什么叫出现问题,依赖 于具体实现,各个实现定义不一样),不再往这 ...
- linux的nohup命令的用法
在应用Unix/Linux时,我们一般想让某个程序在后台运行,于是我们将常会用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/mysql/bin/my ...
- 用 ggplot2 在同一个图上画多条颜色不同的线
假如数据格式是这样: day 邓文迪 微博 城管0 0.0 9.262970888519191E-4 0.01 0.0 0.00144775855013 ...
- HW3.11
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- jQuery进行图片预先加载
/** **将图片加载到内存中,在页面任何位置引用的时候,直接从缓存中读取,提升用户的体验,提高网站的流畅度.** **/ <!DOCTYPE html PUBLIC "-//W3C/ ...
- 关闭utorrent的广告
版本:3.4.9 / 方法来源:wikihow. 在"选项-高级"里将下面的选项全部改成false. offers.left_rail_offer_enabledoffers.sp ...
- Struts文件上传机制
1首先建立文件上传jsp页面如下 <form action="" method="post" enctype="multipart/form-d ...
- 【JAVA - SSM】之MyBatis动态SQL
动态SQL就是在SQL语句中添加一些标签,以完成某些逻辑.通常用到的动态SQL标签有<if>.<choose>.<where>.<trim>.<s ...
- 使用jdom操作xml文件 去除子节点带有命名空间
package com.soft.common; import java.util.HashMap; import java.util.Map; import org.jdom2.Namespace; ...