我正在新的 Ubuntu 16.04 服务器上安装 MySQL 5.7。由于我的安装使用了Ansible,所以在安装时没有定义root密码,后来我在ansible中设置了mysql_user角色,但是root密码保持为空。
因此,我尝试在没有 Ansible 的情况下直接在 MySQL 上运行该命令,但我得到了相同的行为:alter user 命令没有错误,但未设置密码。
我的服务器配置:
- 操作系统:
- 经销商编号:Ubuntu
- 说明:Ubuntu 16.04.1 LTS
- 发布时间:16.04
- 代号:xenial
- 数据库:MySQL 5.7.12-0ubuntu1.1
重现步骤:
- 在不提供 root 密码的情况下安装 mysql-server-5.7 包。
- 从系统root账户连接mysql
然后运行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)
为什么“未散列”版本第一次不起作用?我是否遗漏了什么或者这是这个版本的 MySQL 中的一个错误?