MySQL 5.7安裝後的一些配置

現在MySQL 5.7之後新增了很多功能,其中最明顯的就是密碼增強的配置。


安裝完MySQL 5.7之後默認是沒有用戶名密碼的。

/etc/init.d/mysqld stop

mysqld_safe --skip-grant-tables & 

如果此時不想被遠程連接:mysqld_safe --skip-grant-tables --skip-networking &


MySQL 5.7.15之後就沒有mysqld_safe了,使用

mysqld --user=mysql --explicit_defaults_for_timestamp=1 --skip-grant-tables


完成之後使用如下重置密碼

update set authentication_string=password('password') where user='root';


然後就可以無密碼登錄了,接着修改密碼

alter user 'root'@'localhost' identified by 'password';

不建議用此方法:否則後面會報ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


#update mysql.user set authentication_string=password("password") where user="root";

killall mysqld

/etc/init.d/mysqld start

就可以用密碼登錄了

mysql -uroot -p

但是會發現

mysql> show variables like '%char%';

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by 'password';

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

關閉MySQL強密碼插件

修改MySQL的啓動腳本

大約在132行位置修改

$exec   --datadir="$datadir" --socket="$socketfile" --validate-password=OFF\

增加紅色部分即可

service mysqld restart

mysql> alter user 'root'@'localhost' identified by 'password';

就OK了


總結:

  1. mysql.user表結構的更改原來password字段更改爲authentication_string字段

  2. 新增validate-password插件不需要強密碼的就關閉吧。生產環境不建議



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章