首页 > 数据库 >CentOS安装MySQL的两种方式——RPM和YUM

CentOS安装MySQL的两种方式——RPM和YUM

时间:2024-04-29 22:44:25浏览次数:32  
标签:x86 CentOS 5.7 MySQL community 64 yum mysql YUM

0、首先确认是否安装过MySQL

yum list installed | grep mysql
rpm -qa | grep mysql
若果有安装,需要先删除旧版本。yum remove mysql

一、通过官网下载tar压缩包(或者直接下载RPM安装包)

1.打开MySQL官网下载地址,选择适合自己的版本,下载tar压缩包。

image

2.通过WinSCP等工具上传到CentOS服务器并解压

image

创建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

image

再次确认是否卸载成功

[root@2a792e360945 MySQL]# rpm -qa | grep mysql
[root@2a792e360945 MySQL]#

2.查看CentOS服务器上是否已经存在yum安装包
yum list | grep mysql

image

上图不存在与 MySQL 服务器软件本身相关的软件包。这些列表显示了与 MySQL 数据库相关的其他软件包,如 MySQL 的客户端库、连接器、PHP 的 MySQL 扩展等。

3.获取MySQL官方yum源并安装
MySQL官方源网站获取yum源地址,具体步骤如下

image

image

把复制的下载链接在CentOS服务器下载yum源(如果没有安装wget的话,先安装wgetyum install wget
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm

image

②安装yum源
rpm -Uvh mysql80-community-release-el7-11.noarch.rpm

image

查看所有版本的MySQL的yum源
yum makecache
yum repolist all | grep mysql

image

可以看到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

点击查看代码

[root@2a792e360945 MySQL]# yum-config-manager --disable mysql80-community
Loaded plugins: fastestmirror, ovl
======================================== repo: mysql80-community =========================================
[mysql80-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql80-community
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 0
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023,
   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,
   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql80-community/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 8.0 Community Server
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/mysql80-community
pkgdir = /var/cache/yum/x86_64/7/mysql80-community/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql80-community/x86_64
ui_repoid_vars = releasever,
   basearch
username =

[root@2a792e360945 MySQL]# yum-config-manager --enable mysql57-community
Loaded plugins: fastestmirror, ovl
======================================== repo: mysql57-community =========================================
[mysql57-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql57-community
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023,
   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,
   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql57-community/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 5.7 Community Server
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/mysql57-community
pkgdir = /var/cache/yum/x86_64/7/mysql57-community/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql57-community/x86_64
ui_repoid_vars = releasever,
   basearch
username =

③安装MySQL软件包
yum -y install mysql-community-server

image

三、启动MySQL

查看MySQL服务状态
systemctl status mysqld

image

启动MySQL服务
systemctl start mysqld

标签:x86,CentOS,5.7,MySQL,community,64,yum,mysql,YUM
From: https://www.cnblogs.com/shixiaobin/p/18165871

相关文章

  • 【教程】Homebrew安装MySQL 8 & 设置root密码
    ✨Homebrew安装MySQL8brewinstallmysql==>CaveatsWe'veinstalledyourMySQLdatabasewithoutarootpassword.Tosecureitrun:mysql_secure_installationMySQLisconfiguredtoonlyallowconnectionsfromlocalhostbydefaultToconnectr......
  • Mysql启动报错:Job for mysqld.service failed because the control process exited wi
      该方法会删除mysql数据,慎用centos7上使用yum安装mysql后,启动报错[root@localhost~]#systemctlstartmysqldJobformysqld.servicefailedbecausethecontrolprocessexitedwitherrorcode.See"systemctlstatusmysqld.service"and"journalctl-xe"for......
  • Mysql锁机制与优化实践以及MVCC底层原理剖析
    学习来源-图灵课堂https://vip.tulingxueyuan.cn锁学习参考:https://juejin.cn/post/7307889500545253395  锁机制为了保证数据的一致性,当访问共享变量的时候我们可以针对共享数据加锁,但是加锁要时要注意加锁的成本,还有加锁的粒度,还有就是是否会发生死锁,还有就是发生了死锁......
  • centos iptables xtables-multi
    docker启动systemctlstartdocker#失败查看原因journalctl-xeudocker4月2917:57:42a03dockerd[55315]:time="2024-04-29T17:57:42.491144216+08:00"level=infomsg="Startingup"4月2917:57:42a03dockerd[55315]:time="2024-04-29T17:57......
  • 3分钟部署mysql并开启binlog
    curl-fsSLhttps://get.docker.com|bashyum-yinstalldocker-cesudosystemctlstartdockersudosystemctlenabledockermysql快速安装sudodockerpullmysqlmkdir-p/opt/module/mysql/conf/opt/module/mysql/data/opt/module/mysql/conf/config.d/touch/opt......
  • Mysql、Oracle、SqlServer的JDBC连接实现和对比(提供驱动包)
    Mysql、Oracle、SqlServer的JDBC连接实现和对比(提供驱动包)首先,我们需要准备数据库连接所需的jar包。目前mysql的驱动包可能比较好找,但是oracle和sqlserver的有很多,要找到能用的要花一点点心思,这里直接把下载地址和版本发送出来。Mysql:驱动程序包:mysql-connector-java-5.1.3......
  • mysql-undo log
    MySQL的UndoLog(回滚日志)是InnoDB存储引擎中一个核心的组件,它主要有以下两个目的:确保事务的原子性支持多版本并发控制(MVCC)1.事务的原子性保证UndoLog记录了数据更改之前的状态。当一个事务开始修改数据时,InnoDB首先会在UndoLog中记录这些更改的反向操作(比如,一个......
  • Docker安装MySQL 5.7
    1.创建数据存储目录先创建3个目录,创建MySQL容器时会挂载容器的卷。mkdirlogmkdirdatamkdirconf2.Docker仓库查看MySQL3.拉取镜像dockerpullmysql:5.74.创建MySQL配置文件[client]default-character-set=utf8mb4[mysql]default-character-set=utf8mb4[......
  • openGauss mysql_fdw
    mysql_fdwmysql_fdw是一款开源插件。openGauss基于开源的mysql_fdwRelease2.5.3版本进行开发适配。编译和使用mysql_fdw需要环境上包含MariaDB的开发包,所以openGauss默认不编译mysql_fdw,下面依次介绍如何编译和使用mysql_fdw。编译mysql_fdw编译mysql_fdw需要安装MariaDB的......
  • linux系统 centos7禁止root账号登录
    没有账号的新增账号:sudouseradd-m账号名称sudopasswd账号名称执行完上面命令会让你输入密码输入密码:xxxxxxx1、(注意:禁止root账户登陆前确保有其他账户可以正常使用)编辑配置文件`/etc/ssh/sshd_config`,将`PermitRootLoginyes`改为`PermitRootLoginno`  2、执......