安装环境 AliyunLinux(阿里的linux系统64位)
1.去官网下载yum仓库文件
官网下载连接 MySQL :: Download MySQL Yum Repository
根据系统下载合适的文件
下载官方源
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
由于官方很慢 也可以下载清华的源
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql80-community-release-el7-3.noarch.rpm
查看是否下载成功
[root@localhost ~]# ls
anaconda-ks.cfg mysql80-community-release-el7-3.noarch.rpm
2.安装yum仓库文件
可使用rpm -ivh或者是yum localinstall 去安装,两者实质是一样的
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql80-community-release-el7-3 ################################# [100%]
安装完成后可以看到mysql的repo文件
#安装完成后可以看到mysql的repo文件
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo mysql-community.repo mysql-community-source.repo
#导入key(或者忽略检查)
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
3.版本选择
[root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 185
mysql-tools-community/x86_64 MySQL Tools Community 123
mysql80-community/x86_64 MySQL 8.0 Community Server 229
选择默认安装的版本
安装 YUM 管理工具包,此包提供了 yum-config-manager 命令工具
yum -y install yum-utils
选择或取消选择8.0 或5.7版本
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql80-community
yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql57-community
查看默认启动的仓库
[root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 185
mysql-tools-community/x86_64 MySQL Tools Community 123
mysql57-community/x86_64 MySQL 5.7 Community Server 484
4.安装
yum install -y mysql-community-server
在安装过程中如果报错:All matches were filtered out by modular filtering for argument: mysql-community-server
先执行:yum module disable mysql
再执行:yum install mysql-community-server
5.启动服务
# 启动
systemctl start mysqld
# 查看状态
systemctl status mysqld
# 开机自启动
systemctl enable mysqld
# 查看监听端口,默认 3306
ss -natl |grep 3306
查看初始密码
[root@centos8 ~]# grep 'temporary password' /var/log/mysqld.log
2022-08-31T08:26:44.935527Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -u_*c#*cb1-V
登陆数据库
mysql -u root -p;
修改密码 必须先修改默认密码 否则无法继续其他操作
查看数据库
Show databases;
修改密码规则
密码策略问题异常信息:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解决办法:
1、查看 mysql 初始的密码策略,
输入语句
SHOW VARIABLES LIKE 'validate_password%';
如下图:
2、首先需要设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW 即可,
输入设值语句进行设值,
set global validate.password_policy=LOW;
如下图:
3、当前密码长度为 8 ,如果不介意的话就不用修改了,按照通用的来讲,设置为 6 位的密码,设置 validate_password_length 的全局参数为 6 即可,
输入设值语句进行设值,
set global validate.password_length=6;
如下图:
4、现在可以为 mysql 设置简单密码了,只要满足六位的长度即可,
输入修改语句可以看到修改成功,表示密码策略修改成功了!!!
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
如下图:
关于 mysql 密码策略相关参数;
1)、validate_password_length 固定密码的总长度;
2)、validate_password_dictionary_file 指定密码验证的文件路径;
3)、validate_password_mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
4)、validate_password_number_count 整个密码中至少要包含阿拉伯数字的个数;
5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
关于 validate_password_policy 的取值:
0/LOW:只验证长度;
1/MEDIUM:验证长度、数字、大小写、特殊字符;
2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;
6)、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;
授权root用户远程访问
use mysql;
select host,user from user; # 查询当前状态
update user set host = '%' where user = 'root' ; # 修改访问限制为%
flush privileges; # 重新载入授权表,刷新权限缓存
转自 linux安装mysql8 会飞的蚂蚁王 EverEternity
修改密码验证规则 CSDN-华仔