前言

一直以来,MySQL的应用和学习环境都是MySQL 5.6和之前的版本,也没有去关注新版本MySQL 5.7的变化和新特性。今天帮人处理忘记root密码的时时候,发现以前的方法不奏效了。

具体情况如下所示:

案例环境如下:

操作系统 : Red Hat Enterprise Linux Server release 6.6 (Santiago)

数据库版本: 5.7.18 MySQL Community Server (GPL)

忘记密码,输入错误的密码时遇到下面错误信息:

[root@mytestlnx02 ~]# mysql -u root -pEnter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)[root@mytestlnx02 ~]#
[root@mytestlnx02 ~]# ps -ef | grep -i mysqlroot  22972  1 0 14:18 pts/0 00:00:00 /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=mysqlmysql 23166 22972 0 14:18 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sockroot  23237 21825 0 14:22 pts/0 00:00:00 grep -i mysql[root@mytestlnx02 ~]# service mysqld stopStopping mysqld: [ OK ][root@mytestlnx02 ~]# 
[mysqld] skip-grant-tables 

具体操作过程如下所示:

[root@mytestlnx02 ~]# service mysqld startStarting mysqld: [ OK ][root@mytestlnx02 ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A Database changedmysql> update user set password=PASSWORD('Kd8k&dfdl023') -> where user='root';ERROR 1054 (42S22): Unknown column 'password' in 'field list'mysql> update mysql.user set authentication_string=password('Kd8k&dfdl023') where user='root';Query OK, 1 row affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges;Query OK, 0 rows affected (0.00 sec) mysql> exit
[root@mytestlnx02 ~]# service mysqld startStarting mysqld: [ OK ][root@mytestlnx02 ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.18 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> set password=password('Kd8k&dfdl023');Query OK, 0 rows affected, 1 warning (0.00 sec)

1. 用户表 mysql.user 的 plugin字段不允许为空, 默认值是 mysql_native_password,而不是 mysql_old_password,不再支持旧密码格式;

2. 增加密码过期机制,过期后需要修改密码,否则可能会被禁用,或者进入沙箱模式; 是否启用密码过期由参数default_password_lifetime控制。

mysql> show variables like 'default_password_lifetime';+---------------------------+-------+| Variable_name    | Value |+---------------------------+-------+| default_password_lifetime | 0  |+---------------------------+-------+1 row in set (0.00 sec) mysql>
mysql> show variables like 'validate_password%';+--------------------------------------+--------+| Variable_name      | Value |+--------------------------------------+--------+| validate_password_check_user_name | OFF || 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  |+--------------------------------------+--------+7 rows in set (0.00 sec)
[root@mytestlnx02 mysql]# yum localinstall mysql-community-{server,client,common,libs}-* [root@mytestlnx02 mysql]# rpm -qa | grep -i mysqlmysql-community-client-5.7.18-1.el6.i686mysql-community-libs-5.7.18-1.el6.i686perl-DBD-MySQL-4.013-3.el6.x86_64mysql-community-server-5.7.18-1.el6.i686mysql-community-common-5.7.18-1.el6.i686mysql-community-libs-compat-5.7.18-1.el6.i686[root@mytestlnx02 mysql]# service mysqld start Initializing MySQL database: [ OK ]Installing validate password plugin: [ OK ]Starting mysqld: [ OK ][root@mytestlnx02 mysql]# [root@mytestlnx02 mysql]# grep 'temporary password' /var/log/mysqld.log2017-05-05T06:10:57.802143Z 1 [Note] A temporary password is generated for root@localhost: w99s(m-q_ML: mysql> select user ,host from user;+-----------+-----------+| user  | host  |+-----------+-----------+| mysql.sys | localhost || root  | localhost |+-----------+-----------+2 rows in set (0.00 sec)

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Pycharm安装PyQt5的详细教程
  3. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  4. android用户界面之按钮(Button)教程实例汇
  5. 【Android(安卓)开发教程】Toast通知
  6. android 分辨率及密度详细
  7. Android简易实战教程--第三十九话《Chronometer实现倒计时》
  8. android加密解密完美教程
  9. Android(安卓)SDK自带教程之BluetoothChat

随机推荐

  1. MobX
  2. dva
  3. 嵌入式:我不是针对谁,我是说在座的Javaer都
  4. 戴耳机敲代码,我都听些啥?
  5. 外边距合并规则
  6. redux-saga
  7. 详解HDFS3.x新特性-纠删码
  8. 深入理解Java:内部类
  9. 超链接的lvha原则
  10. (不谈废话,只有干货)解决线程间协作问题的工