https://mirror.tuna.tsinghua.edu.cn/help/mysql/
新建 /etc/yum.repos.d/mysql-community.repo,内容如下:
注:
mysql-8.0,mysql-connectors和mysql-tools在RHEL 7/8上还提供了aarch64版本。
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
或者,替换
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
重建缓存
yum clean all && yum makecache
如果配置了,镜像源,可以略过本步骤
https://dev.mysql.com/downloads/repo/yum/
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
yum install mysql80-community-release-el7-7.noarch.rpm
yum install mysql-community-server --nogpgcheck -y
systemctl enable mysqld --now
grep 'temporary password' /var/log/mysqld.log
输入如下命令后,数据上面的到的密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'A.com.123456789';
A.com.123456789即 新密码
先登陆
mysql -uroot -p
执行命令
create user 'fox'@'%' identified by '999999';
999999即 新密码
给 fox 用户授权(全部权限)
grant all privileges on *.* to 'fox'@'%';
# 刷新权限
flush privileges;
CREATE DATABASE IF NOT EXISTS fox \
CHARACTER SET utf8mb4 \
COLLATE utf8mb4_general_ci ;
utf8mb4_bin: 区分大小写的,也区分e和é类字符的
utf8mb4_genera_ci: 不区分大小写的,也不区分e和é类字符
修改配置
vim /etc/my.cnf
在[mysql]下面加入
bind-address=0.0.0.0
如果已经存在
bind-address,那么把它改为和上面一样
systemctl restart mysqld
查看防火墙状态
firewall-cmd --state
开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
应用
firewall-cmd --reload
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
systemctl enable mysqld --now
systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
systemctl status mysqld