我在新的Ubuntu 16.04服务器上安装MySQL 5.7。由于我的安装使用Ansible,因此在安装时没有定义root密码,我稍后在ansible中使用mysql_user角色进行设置,但root密码保持为空。
因此我尝试直接在MySQL上运行命令,没有Ansible,但我得到了相同的行为:alter user命令没有错误,但没有设置密码。
我的服务器配置:
重现步骤:
然后运行mysql命令:
mysql> select authentication_string from user where host='localhost' and user='root';
+-----------------------+
| authentication_string |
+-----------------------+
| |
+-----------------------+
1 row in set (0,00 sec)
mysql> alter user root@localhost identified by 'mypassword';
Query OK, 0 rows affected (0,00 sec)
mysql> select authentication_string from user where host='localhost' and user='root';
+-----------------------+
| authentication_string |
+-----------------------+
| |
+-----------------------+
1 row in set (0,00 sec)
但是,使用散列值运行相同的命令可以起作用:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*D7B8FEAED940F8F2A0055864C0A59782B4BCED02';
mysql> select authentication_string from user where host='localhost' and user='root';
+-------------------------------------------+
| authentication_string |
+-------------------------------------------+
| *D7B8FEAED940F8F2A0055864C0A59782B4BCED02 |
+-------------------------------------------+
1 row in set (0,00 sec)
然后,我可以使用原始请求更改密码:
mysql> alter user root@localhost identified by 'mypassword';
Query OK, 0 rows affected (0,00 sec)
mysql> select authentication_string from user where host='localhost' and user='root';
+-------------------------------------------+
| authentication_string |
+-------------------------------------------+
| *FABE5482D5AADF36D028AC443D117BE1180B9725 |
+-------------------------------------------+
1 row in set (0,00 sec)
为什么“unhashed”版本第一次无效?我错过了什么或这是这个版本的MySQL中的错误吗?