centos7安装mysql8,修改密码策略,配置远程登录

# 去官网下载 rpm 包,选择好版本
https://dev.mysql.com/downloads/repo/yum/

# 下载
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm

# 安装源
yum -y install mysql80-community-release-el7-3.noarch.rpm

# 查看
yum repolist enabled | grep mysql.*

# 安装mysql服务
yum install mysql-community-server 
# mysql-devel mysql-lib 这两个也许需要
# yum install mysql-devel gcc gcc-devel python-devel

# 启动
systemctl start  mysqld.service

# 查看初始默认密码
grep "password" /var/log/mysqld.log

# 使用默认密码 登录
mysql -uroot -p

# 如果要更改密码为123456 简单密码,需要更改密码策略
SHOW VARIABLES LIKE 'validate_password%';
# 看输出 有的是validate_password_policy,有的是validate_password.policy
set global validate_password_policy=LOW;
set global validate_password_length=6;

# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

# 更改权限
FLUSH PRIVILEGES;

# 如果想要远程登录
mysql> use mysql; 
mysql> update user set host = '%' where user = 'root'; 
mysql> select host, user from user;
mysql> FLUSH PRIVILEGES;


# 开机启动
systemctl enable mysqld
# 重载服务配置
systemctl daemon-reload

如果出现2059问题,密码加密方式相关问题

mysql> use mysql;
mysql> select user,plugin from user where user=’root’;

# 以下操作 如果出现密码不安全太简单, 重复上面的密码策略修改
# 修改加密方式
mysql> ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
# 修改密码
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# 刷新 
mysql> FLUSH PRIVILEGES;

你可能感兴趣的:(环境搭建)