1.安装环境
此教程适用于centos7.0及以上兼容版本的安装
2.实现方案
①运行以下命令
- 安装MySQL5.7
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm;
yum -y install mysql57-community-release-el7-10.noarch.rpm;
(下面出错如果是秘钥过期执行下面语句 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022)
yum -y install mysql-community-server;
systemctl start mysqld.service;
systemctl status mysqld.service;
yum -y remove mysql57-community-release-el7-10.noarch;
grep "password" /var/log/mysqld.log;
- 安装MySQL8.0
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
yum -y install mysql80-community-release-el7-3.noarch.rpm
上面报错执行 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
3.默认安装MySQL8.0,如果需要安装MySQL5.7的话需要修改/etc/yum.repos.d/mysql-community.repo配置文件
将mysql80中enabled属性改为0,并添加图中红框内代码(安装MySQL8.0跳过该步骤)
yum -y install mysql-community-server
systemctl start mysqld.service
cat /var/log/mysqld.log | grep password
大约等待3分钟,然后会生成一个root用户的随机密码
②复制该密码,mysql -u root -p
③粘贴随机密码,不显示密码,直接回车登录
设置密码策略
mysql5.7
set global validate_password_policy=0;
mysql8.0
set global validate_password.policy=0;
然后将随机密码修改成自己定义的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你想设置的密码';
③然后重新登录mysql,创建mysql用户
CREATE USER '你的用户名'@'%' IDENTIFIED BY '你的密码';
④对所有库授权
grant all on *.* to '你创建的用户名'@'%';
或者对指定库进行授权
grant all on库名.* to '你创建的用户名'@'%';
⑤刷新权限
flush privileges;
⑥开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
⑦重启防火墙
firewall-cmd --reload
⑧navicat连接mysql