建议安装前,先挂载数据盘(如果有)到 mysql 的数据存储路径。
- 下载 mysql5.7 官方 yum 仓库源。
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 导入 2022 年的 RPM Key。
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- 通过 yum 进行安装。
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 启动 mysql 并设置开机启动。
systemctl start mysqld
systemctl enable mysqld
- 由于 mysql5.7 安装后会自动 generate root 密码,所以需要从日志中找到该密码。
grep 'A temporary password' /var/log/mysqld.log | awk -F"root@localhost: " '{ print $2}'
- 记录该密码并执行下面的命令,初始化mysql 配置。
mysql_secure_installation
- 根据系统提示,修改 root 密码,设置远程访问等。由于这步的设置只需要跟随系统提示即可,所以不再赘述。