开发服务器上安装MysqL 8,因为都是内网环境所以变更root密码为简单密码。
根据官网链接 ,执行:
wget https://dev.MysqL.com/get/MysqL80-community-release-el7-1.noarch.rpm
yum localinstall MysqL80-community-release-el7-1.noarch.rpm
检查版本:
yum repolist enabled | grep MysqL
yum install MysqL-community-server
启动:
service MysqLd start
检查状态:
service MysqLd status
grep 'temporary password' /var/log/MysqLd.log
用log中的密码登录:
MysqL -uroot -p
变更root的密码(必须先是localhost)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
变更密码策略默认值为medium
show 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 |
+————————————–+——–+
变更root账号的密码为简单策略,并变更root的账户密码:
set global validate_password.policy = low alter user 'root'@'localhost' with MysqL_native_password identified by 'simplepassword';
create user 'root'@'%' with MysqL_native_password identified by 'simplepassword' ;
创建应用账号和密码:
create user 'foo'@'%' with MysqL_native_password identifieid by 'foo_pass';
create database bar;
grant all privileges on bar.* to 'foo'@'%';
说明:
MysqL8 默认是caching_sha2_password。可以从show create table MysqL.user
中的plugin字段的默认值开出来。针对用户的字段更改,不能update MysqL.user实现,只能是create user或alter user时加with MysqL_native_password。网上的MysqL_old_password插件已经不再安装在MysqL服务器中(不信可以试试select host,user,plugin from MysqL.user where user = 'foo';
)。在MysqL 5.7之前版本,默认是MysqL_native_password。如果使用MysqL 8默认的caching_sha2_password会造成MysqL小于等于5.7版本的客户端出错:
ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password’ cannot be loaded: /usr/lib64/MysqL/plugin/cach_sha2_password.so: cannot open shared object file: No such file or directory