这个字段是一个比较神奇的字段。该字段有值,则不允许root@localhost 免密码登录,若该字段无值,则不允许 root@localhost 使用密码登录。
这两种情况,与authentication_string字段没有关系。 发现该问题的版本是Mariadb 10.2.25.
下面是验证过程:
# password 字段不为空时,不允许免密登录
[root@tycxaiftest1 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# 使用密码登录,并查看password 的值
[root@tycxaiftest1 ~]# mysql -uroot -hlocalhost -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.2.25-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select password from mysql.user where user='root' and host='localhost';
+-------------------------------------------+
| password |
+-------------------------------------------+
| *5AF624CAC5796884CBBEDD5FF7A02C3BEC52E2B2 |
+-------------------------------------------+
1 row in set (0.00 sec)
# 将该字段设置为空。
MariaDB [(none)]> update mysql.user set password='' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
# 验证: password 字段为允时允许免密登录
[root@tycxaiftest1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.2.25-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
# 验证 password 字段为空时,不允许使用密码登录
MariaDB [(none)]> exit
Bye
[root@tycxaiftest1 ~]# mysql -uroot -h localhost -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)