os: centos 7.4
db: mysql 8.0.19
版本
# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
#
# mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.19 |
+-----------+
1 row in set (0.00 sec)
mysql>
alter user identified by
使用 yum 安裝 mysql-server 後,第一次啓動 mysql ,會自動創建一個 mysql 數據庫
# systemctl start mysqld.server
默認生成的 ‘root’@‘localhost’ 密碼保存在 /var/log/mysqld.log
# cat /var/log/mysqld.log
2020-02-25T13:43:20.116141Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 5195
2020-02-25T13:43:24.206701Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8t89OsTdEs,&
2020-02-25T13:43:29.311452Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 5246
2020-02-25T13:43:30.001833Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-02-25T13:43:30.063997Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2020-02-25T13:43:30.286359Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '0.0.0.0' port: 33060
登錄後,需要第一時間修改密碼,但是如果是測試庫的話,密碼沒必要設置的很複雜,就需要修改一下
# mysql -h localhost -u root -p
Enter password:
mysql> select * from mysql.user;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'mysqlmysql';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>
先臨時修改一個較複雜的密碼
mysql> alter user 'root'@'localhost' identified by 'PAss@@2020';
Query OK, 0 rows affected (0.22 sec)
mysql 8.0 的密碼默認使用 caching_sha2_password ,已不再是 mysql_native_password 。
mysql> show global variables like '%default_auth%';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set (0.00 sec)
validate_password 相關參數,看上去 8.0 相比 5.7 改成了"."
mysql> show global variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
臨時修改 validate_password 參數
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=4;
mysql> alter user 'root'@'localhost' identified by 'mysqlmysql';
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | caching_sha2_password | $A$005$3
-b%<1x}8Neyo`@vGfGUUFglFEZnzdOcz5ev/Z.oUKTH34s7EH0VZdBKH43 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)
永久修改的話,需要修改 my.cnf 參數文件
# vi /etc/my.cnf
validate_password.policy=0
validate_password.length=4
validate_password.number_count=0
validate_password.mixed_case_count=0
validate_password.special_char_count=0
如果使用 mysql_native_password 方式請參考
<<mysql 8.0 的用戶認證方式 caching_sha2_password、mysql_native_password>>
<<mysql 密碼插件 validate_password>>
參考: