CentOS安装MySQL的两种方式——RPM和YUM
|
0、首先确认是否安装过MySQL
yum list installed | grep mysql
rpm -qa | grep mysql
若果有安装,需要先删除旧版本。yum remove mysql
一、通过官网下载tar压缩包(或者直接下载RPM安装包)
1.打开MySQL官网下载地址,选择适合自己的版本,下载tar压缩包。
2.通过WinSCP等工具上传到CentOS服务器并解压
创建MySQL的安装路径mkdir /usr/local/MySQL
解压上传好的MySQL压缩包,解压后得到若干RPM安装包- [root@2a792e360945 ~]# tar -xvf /root/temp/mysql-5.7.41-1.el7.x86_64.rpm-bundle.
- tar -C /usr/local/MySQL
- mysql-community-client-5.7.41-1.el7.x86_64.rpm
- mysql-community-common-5.7.41-1.el7.x86_64.rpm
- mysql-community-devel-5.7.41-1.el7.x86_64.rpm
- mysql-community-embedded-5.7.41-1.el7.x86_64.rpm
- mysql-community-embedded-compat-5.7.41-1.el7.x86_64.rpm
- mysql-community-embedded-devel-5.7.41-1.el7.x86_64.rpm
- mysql-community-libs-5.7.41-1.el7.x86_64.rpm
- mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm
- mysql-community-server-5.7.41-1.el7.x86_64.rpm
- mysql-community-test-5.7.41-1.el7.x86_64.rpm
复制代码 3.安装RPM包
因为是使用RPM安装软件包,所以需要手动解决依赖关系,一般安装 MySQL 时需要按照以下顺序安装这些软件包。首先切换到MySQL的安装路径cd /usr/local/MySQL,然后依次执行下列安装命令- rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm
- rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm
- rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
- rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
复制代码 其他安装包是MySQL的开发文件或者测试文件,非必须安装。
如果安装mysql-community-server-5.7.41-1.el7.x86_64.rpm的时候,出现依赖关系的错误,可能是由于系统没有安装依赖项,根据提示安装缺少的依赖项再执行mysql-community-server-5.7.41-1.el7.x86_64.rpm的安装即可
例如我的CentOS是新安装的镜像,没有安装任何依赖项,有如下输出信息- [root@2a792e360945 MySQL]# rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
- warning: mysql-community-server-5.7.41-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
- error: Failed dependencies:
- /usr/bin/perl is needed by mysql-community-server-5.7.41-1.el7.x86_64
- libaio.so.1()(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- perl(Getopt::Long) is needed by mysql-community-server-5.7.41-1.el7.x86_64
- perl(strict) is needed by mysql-community-server-5.7.41-1.el7.x86_64
复制代码 使用软件包管理工具(例如yum)来安装这些依赖项
yum install perl libaio libnuma perl-Getopt-Long perl-strict numactl
安装完依赖项之后,再安装MySQL服务,即可安装成功。
至此,RPM方式安装MySQL就结束了。
二、通过YUM的方式安装
这种安装方式的好处是不用手动管理依赖关系,YUM(软件包管理工具)会自动按顺序安装依赖项并解决依赖关系。但是不能安装任意我们想安装的历史版本。
1.先卸载上面安装过的5.7.41版本的MySQL
查看当前以及安装的MySQL
yum list installed | grep mysql
rpm -qa | grep mysql- [root@2a792e360945 MySQL]# yum list installed | grep mysql
- mysql-community-client.x86_64 5.7.41-1.el7 installed
- mysql-community-common.x86_64 5.7.41-1.el7 installed
- mysql-community-libs.x86_64 5.7.41-1.el7 installed
- mysql-community-server.x86_64 5.7.41-1.el7 installed
复制代码 卸载这四个软件包
yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-server
再次确认是否卸载成功- [root@2a792e360945 MySQL]# rpm -qa | grep mysql
- [root@2a792e360945 MySQL]#
复制代码 2.查看CentOS服务器上是否已经存在yum安装包
yum list | grep mysql
上图不存在与 MySQL 服务器软件本身相关的软件包。这些列表显示了与 MySQL 数据库相关的其他软件包,如 MySQL 的客户端库、连接器、PHP 的 MySQL 扩展等。
3.获取MySQL官方yum源并安装
①MySQL官方源网站获取yum源地址,具体步骤如下
把复制的下载链接在CentOS服务器下载yum源(如果没有安装wget的话,先安装wgetyum install wget)
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
②安装yum源
rpm -Uvh mysql80-community-release-el7-11.noarch.rpm
查看所有版本的MySQL的yum源
yum makecache
yum repolist all | grep mysql
可以看到8.0版本的yum源是enable,而5.7版本是disable,但是我要安装5.7版本,按照下面命令禁用8.0,启用5.7即可
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
点击查看代码③安装MySQL软件包
yum -y install mysql-community-server
三、启动MySQL
查看MySQL服务状态
systemctl status mysqld
启动MySQL服务
systemctl start mysqld
来源:https://www.cnblogs.com/shixiaobin/p/18165871
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|
|
|
发表于 2024-4-30 10:41:36
举报
回复
分享
|
|
|
|