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 ...
随机推荐
- [NYOJ 43] 24 Point game
24 Point game 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 There is a game which is called 24 Point game ...
- 编译安装nginx并修改版本头信息—参考实例
今天做实验的时候,想起我那台yum安装的nginx+php-fpm+mysql服务器上的nginx版本有点低了,并且还要加两个第3方模块,就去nginx官网下载了最新稳定版nginx-1.0.6,好了 ...
- VS2012启用SQLite的Data Provider
VS 2012默认是不带的SQLite的Data Provider,所以无法直接在VS 2012里管理SQLite的数据库,自然也不能在VS里像SQL Server那样直接生成Entity Frame ...
- 打印grid
void PrintButtonClick(object sender, EventArgs e) { PrintPreviewDialog dlg = new PrintPreviewDialog( ...
- Oracle 新增表空间文件
ALTER TABLESPACE users ADD DATAFILE 'D:/oracle/oradata/orcl/users.dbf' SIZE 500M AUTOEXTEND ON NEXT ...
- Android UI -- 内容简介
Android UI(User Interface) 是android学习的必要课程,在接下来的内容我们将主要介绍 Android UI 的基础知识.
- [NOIP2002]自由落体
NOIp2002提高组 题目描述 在高为 H 的天花板上有 n 个小球,体积不计,位置分别为 0,1,2,….n-1.在地面上有一个小车(长为 L,高为 K,距原点距离为 S1).已知小球下落距离计算 ...
- NOIP2000 单词接龙
题三. 单词接龙 (27分) 问题描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的 ...
- HDOJ-ACM1015(JAVA) 运用 组合、全排列实现
转载声明:原文转自:http://www.cnblogs.com/xiezie/p/5573934.html 这个题目的题意:(自己结合百度翻译,简单的翻译了一下) “这个项目是在一个在二楼图书馆一幅 ...
- [二]java运行原理
public class HelloWorld{ public static void main(String args[]){ System.out.println("hello" ...