问题将有相关技术和产品第一时间回答在线咨询

MySQL5.7.12新密码登录方式及密码策略

问题:MySQL5.7.12新密码登录方式及密码策略

2018-06-12 10:15:30

回复答案

首先修改MySQL授权登录方式---(跳过授权验证方式启动MySQL):

[root@test ~]# mysqld_safe --skip-grant-tables &

[1] 3401

[root@test ~]# 2016-05-19T12:47:56.564385Z mysqld_safe Logging to '/var/log/mysqld.log'.

2016-05-19T12:47:56.589376Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql


检查MySQL启动情况

[root@test ~]# ps -ef | grep mysql

root      3401  2880  0 20:47 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables

mysql     3548  3401  0 20:47 pts/1    00:00:00 /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> 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


标签 微信 H5 公众号 阿里云 MYSQL