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了

总结:

mysql.user表结构的更改原来password字段更改为authentication_string字段

新增validate-password插件不需要强密码的就关闭吧。生产环境不建议

猜你喜欢

转载自www.linuxidc.com/Linux/2017-02/140149.htm