一、准备
1. 移除自带mariadb
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.aarch64
二、安装
2.1 yum安装
2.1.1 下载数据源
# CentOS 7
wget https://repo.mysql.com//mysql80-community-release-el7-4.noarch.rpm
# CentOS 8
wget https://repo.mysql.com//mysql80-community-release-el8-3.noarch.rpm
2.1.2 安装数据源(必须是root用户)
rpm -Uvh mysql80-community-release-el7-4.noarch.rpm
2.1.3 查看mysql版本
yum repolist all | grep mysql
2.1.4 切换MySQL版本
# 关闭5.7
yum-config-manager --disable mysql57-community
# 开启8.0
yum-config-manager --enable mysql80-community
2.1.5 检查启用的mysql仓库
yum repolist enabled | grep mysql
2.1.6 安装MySQL
yum -y install mysql-community-server --nogpgcheck
# 如果报错:没有任何匹配: mysql-community-server
# 先执行下边操作,然后再执行上边安装命令
yum module disable mysql
2.2 rpm包安装
2.2.1 下载rpm包 下载第一个bundle包
https://dev.mysql.com/downloads/mysql/
2.2.2 解压
tar -xvf mysql-8.0.26-1.el7.aarch64.rpm-bundle.tar
2.2.3 安装 (必须按照下列顺序)
rpm -ivh mysql-community-common-8.0.26-1.el7.aarch64.rpm
rpm -ivh mysql-community-client-plugins-8.0.26-1.el7.aarch64.rpm
rpm -ivh mysql-community-libs-8.0.26-1.el7.aarch64.rpm
rpm -ivh mysql-community-client-8.0.26-1.el7.aarch64.rpm
rpm -ivh mysql-community-server-8.0.26-1.el7.aarch64.rpm
2.3 Docker安装
2.3.1 下载镜像
docker pull mysql
2.3.2 创建相关文件夹
mkdir -p /opt/mysql/{conf,logs,data}
2.3.3 运行mysql容器
docker run --restart=always --name mysql -v /opt/mysql/conf:/etc/mysql/conf.d -v /opt/mysql/logs:/logs -v /opt/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d -p 3306:3306 mysql
docker安装的mysql默认开启远程登录。如果远程登录不上,进行后续步骤开启。
# 进入MySQL容器
docker exec -it mysql /bin/bash
三、启动配置mysql
3.1 启动mysql
systemctl start mysqld
3.2 查看初始密码
grep password /var/log/mysqld.log
3.3 登录
mysql -u root -p
3.4 修改初始密码 (因为mysql8.0默认不允许设置简单密码,而且密码规则必须在修改过一次密码以后才允许更改,所以此时先设置一个复杂密码,修改完密码规则以后,再改成简单密码)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ROot1234+';
3.5 远程访问授权
create user 'root'@'%' identified with mysql_native_password by 'ROot1234+';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
补充:
修改密码规则(设置简单密码)
SHOW VARIABLES LIKE 'validate_password%';
# 设置密码校验规则为低
# 密码校验规则有低/中/高
# 低:只需要包含数字
# 中:需要包含数字、大小写字母
# 高:需要包含数字、大小写字母、特殊符号
set global validate_password.policy=LOW;
# 设置密码长度最低为4位
set global validate_password.length=4;
# mysql 8.0 需要设置,
set global validate_password.check_user_name=OFF;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
ALTER USER 'root'@'%' IDENTIFIED BY 'root';
评论区