MYSQL8.0修改密碼的一些疑問

mysql安裝之後,默認密碼爲空,可使用mysql

mysqld --initial

Mysql 提供了兩種基於SHA-256的密碼驗證的插件:sql

sha256_password  基於基本的sha-256 驗證
caching_sha2_password Implements SHA-256 authentication (like sha256_password), but uses caching on the server side for better performance and has additional features for wider applicability.

查看mysql使用的密碼插件:app

mysql> show variables like '%default_authentication_plugin%';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set (0.01 sec)

那麼修改密碼的時候,咱們就要這樣:ide

  alter user 'root'@'localhost' identified with caching_sha2_password by 'your_new_password';

若是你的root密碼原來是空密碼,那麼使用select語句查看:插件

mysql> select authentication_string from user;
+------------------------------------------------------------------------+
| authentication_string                                                  |
+------------------------------------------------------------------------+
| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| $A$005$4<+yQ2yNzb+L{TFc{T.xxxoMky8g1F0KbCQeyHOZ8JSO/NWydKhRGnhCVxyn/ |
+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

就變成了有密碼...
而後使用新密碼登錄mysql,發現已經成功了。orm

相關文章
相關標籤/搜索