CentOS8.x 离线安装 MySQL5.7.x 指定版本数据库
- CentOS8.x 已安装 MySQL8.0.17
- 系统为:CentOS8.0.1905
- 最终安装 MySQL 版本:5.7.29
一、卸载 MySQL8
1、查看版本
mysql --version
2、查看安装的包
rpm -qa | grep mysql
3、卸载已安装 MySQL8
rpm -qa | grep mysql | xargs rpm -e --nodeps
删除 MySQL 配置文件及其目录
rm -rf /etc/my.cnf /etc/my.cnf.d
二、离线安装指定版本的 MySQL
- 安装必要的包
yum install libncurses*
2、官网下载 tar 包
官网地址:https://dev.mysql.com/downloads/mysql/
(Looking for the latest GA version?)
Select Version: 5.7.29
Select Operating System: Source Code
Select OS Version: Generic Linux(Architecture Independent)
或者使用以下命令下载
cd /usr/local/src wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-el7-x86_64.tar.gz
将离线下载的 tar 上传至 /usr/local/src
目录下
3、创建安装账户
mkdir /usr/local/mysql useradd -s /bin/false -d /usr/local/mysql mysql
4、安装过程
# 此过程有点长,耐心等待 tar -xvzf mysql-5.7.21-el7-x86_64.tar.gz -C /usr/local/mysql/ cd /usr/local/mysql/mysql-5.7.21-el7-x86_64/ mv * ../ cd .. rmdir mysql-5.7.21-el7-x86_64/ mkdir data chown -R mysql.mysql ../mysql cd bin ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
安装完成后在最后会显示 root 密码
拷贝可执行配置文件
cd /usr/local/mysql cp ../support-files/mysql.server /etc/init.d/mysqld
5、配置过程
MySQL 配置文件 /etc/my.cnf
中内容如下:
[mysqld] port = 3306 basedir = /usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock pid-file=/usr/local/mysql/data/mysql.pid log-error=/usr/local/mysql/data/error.log character_set_server=utf8 user=mysql max_connections=1500 symbolic-links=0 # 东八区时区,北京时区 default-time-zone = '+8:00' sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # 导入包允许的大小设置 max_allowed_packet=1024M # 忽略表名大小写;1表示忽略大小写,0表示解析大小写 lower_case_table_names=1 !includedir /etc/my.cnf.d
6、启动服务并登陆
常用命令
# 启动命令 service mysqld start 或者 /etc/init.d/mysqld start # 停止命令 service mysqld stop 或者 /etc/init.d/mysqld stop # 重启命令 service mysqld restart 或者 /etc/init.d/mysqld restart
登陆命令
./bin/mysql -u root -p'zisTBE)I8*/0'
7、修改密码并允许远程连接
mysql> set password=password('123456'); mysql> use mysql; mysql> update user set host='%' where user='root'; mysql> flush privileges;
如果远程还连接不上,看下是否防火墙开启了?
8、添加环境变量
vim /etc/profile # mysql PATH=/usr/local/mysql/bin:$PATH
添加环境变量
保存退出后,使用
source /etc/profile
使其生效。
三、MySQL 自启
# 查看MySQL是否自启 systemctl is-enabled mysqld
如下图,显示 disabled
,MySQL 默认非自启
# 开启自启 systemctl enable mysqld
如下图
四、防火墙放行 3306 端口
如果你的防火墙已经关闭,可忽略此操作。
# 永久开放3306端口 firewall-cmd --permanent --zone=public --add-port=3306/tcp # 重启防火墙 systemctl restart firewalld # 检测设定是否生效 iptables -nL | grep 3306
五、其他问题
问题 1:yum 仓库无法更新问题
在使用 yum repolist
列出仓库中的包时,出现 Error: Failed to synchronize cache for repo 'AppStream'
由于其原有的默认的源配置文件被我删除过,然后 CentOS8 换过阿里的源,在卸载 MySQL8 之后重新安装后出现上述问题;解决参照:CentOS8 使用阿里源。
将原来文件中
$releasever
替换为8.0.1905
,将$basearch
替换为x86_64
,然后再使用yum clean all && yum makecache
即可
正常的 CentOS-Base.repo
内容如下
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-8.0.1905 - Base - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/BaseOS/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official #additional packages that may be useful [extras] name=CentOS-8.0.1905 - Extras - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/extras/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official #additional packages that extend functionality of existing packages [centosplus] name=CentOS-8.0.1905 - Plus - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/centosplus/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/ gpgcheck=1 enabled=0 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official [PowerTools] name=CentOS-8.0.1905 - PowerTools - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/PowerTools/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/ gpgcheck=1 enabled=0 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official [AppStream] name=CentOS-8.0.1905 - AppStream - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/AppStream/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
版权声明
作者:静美书斋
链接:https://www.jianshu.com/p/ee018b20a6e6
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于