天天看點

mysql 5.7 初始化問題---空密碼

percona mysql 5.7 初始化,由于 環境需要 mysql 初始化之後是空密碼
場景複現:
mkdir mysql10888
mkdir binlog innodata innolog relaylog log cnf
/usr/sbin/mysqld --defaults-file=/data/mysql10888/cnf/mysql10888.cnf --initialize --initialize-insecure --datadir=/data/mysql10888/data --user=mysqldb 

報錯:
2019-03-13T15:49:10.674060+08:00 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-03-13T15:49:11.016977+08:00 0 [Warning] CA certificate ca.pem is self signed.
2019-03-13T15:49:11.226013+08:00 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2019-03-13T15:49:11.453063+08:00 1 [ERROR] 1819  Your password does not satisfy the current policy requirements
2019-03-13T15:49:11.453149+08:00 0 [ERROR] Aborting

可以正常的啟動,error日志也沒有報錯

使用空密碼無法進入:
mysql -S /data/mysql10777/data/mysqld10777.sock -uroot -p -P 10777
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[[email protected] mysql10777]$ mysql -S /data/mysql10777/data/mysqld10777.sock
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

端口與程序正常。

嘗試一:去掉密碼驗證:
   skip-grant-tables

進入mysql5.7 發現user表是空的
root@localhost:mysqld10777.sock:[(none)]>select user,host from mysql.user;
Empty set (0.00 sec)

root@localhost:mysqld10777.sock:[(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| undolog            |
+--------------------+
4 rows in set (0.00 sec)

少了sys庫

百思不得其解,在google了很多文章說的都不對

嘗試二、突然想到5.6和5.7 的密碼驗證模式不一樣,關閉5.7 密碼驗證

[mysqld]
validate_password              = off

重新初始化
error日志:
2019-03-13T15:06:55.600940+08:00 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-03-13T15:06:56.010897+08:00 0 [Warning] CA certificate ca.pem is self signed.
2019-03-13T15:06:56.266208+08:00 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

登入:
mysql -S /data/mysql10888/data/mysqld10888.sock -uroot

關閉了密碼,也不需要上來先設定密碼了
root@localhost:mysqld10888.sock:[(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| undolog            |
+--------------------+
5 rows in set (0.00 sec)

sys庫也有了 

root@localhost:mysqld10888.sock:[(none)]>select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

猜想:
  估計是一個bug,mysql5.7是嚴格的密碼政策使用空密碼可能觸發驗證機制
           

繼續閱讀