MySQL8 修改密碼驗證插件


MySQL8 修改密碼驗證插件

查看當前用戶使用的密碼驗證插件

mysql> show variables like '%auth%';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+

查看 MySQL8 支持的密碼驗證插件

mysql> show plugins;
+----------------------------+----------+--------------------+---------+---------+
| Name                       | Status   | Type               | Library | License |
+----------------------------+----------+--------------------+---------+---------+
| binlog                     | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
| mysql_native_password      | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
| sha256_password            | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
| caching_sha2_password      | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
| sha2_cache_cleaner         | ACTIVE   | AUDIT              | NULL    | GPL     |
| CSV                        | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |

修改用戶的密碼驗證插件

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.45 sec)

修改系統默認的密碼驗證插件

  1. 配置參數方式 default-authentication-plugin
# 設置默認密碼驗證插件
default-authentication-plugin=caching_sha2_password
  1. 啟動參數方式 --default-authentication-plugin
C:\Users\jie>D:\chengxu\MySQL\mysql-8.0.12-winx64\bin\mysqld --default-authentication-plugin=mysql_native_password

bugs

如果只指定用戶名不指定主機,則表示的用戶是任意主機,即 'username'@'%',這個和本地主機即 'username'@'localhost' 的含義是不同的。

# 'root' 更改失敗,因為表示的是 'root'@'%',而此處用戶只有'root'@'localhost'
mysql> alter user 'root' identified with mysql_native_password by 'root';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'

mysql> select host, user, plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| localhost | caocao           | caching_sha2_password |
| localhost | liubei           | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+

無法通過命令行方式設置默認的密碼驗證插件

mysql> set default_authentication_plugin=mysql_native_password;
ERROR 1238 (HY000): Variable 'default_authentication_plugin' is a read only variable
mysql> set global default_authentication_plugin=mysql_native_password;
ERROR 1238 (HY000): Variable 'default_authentication_plugin' is a read only variable


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM