翼度科技»论坛 编程开发 mysql 查看内容

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

7

主题

7

帖子

21

积分

新手上路

Rank: 1

积分
21
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安装包
  1. [root@2a792e360945 ~]# tar -xvf /root/temp/mysql-5.7.41-1.el7.x86_64.rpm-bundle.
  2. tar -C /usr/local/MySQL
  3. mysql-community-client-5.7.41-1.el7.x86_64.rpm
  4. mysql-community-common-5.7.41-1.el7.x86_64.rpm
  5. mysql-community-devel-5.7.41-1.el7.x86_64.rpm
  6. mysql-community-embedded-5.7.41-1.el7.x86_64.rpm
  7. mysql-community-embedded-compat-5.7.41-1.el7.x86_64.rpm
  8. mysql-community-embedded-devel-5.7.41-1.el7.x86_64.rpm
  9. mysql-community-libs-5.7.41-1.el7.x86_64.rpm
  10. mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm
  11. mysql-community-server-5.7.41-1.el7.x86_64.rpm
  12. mysql-community-test-5.7.41-1.el7.x86_64.rpm
复制代码
3.安装RPM包
因为是使用RPM安装软件包,所以需要手动解决依赖关系,一般安装 MySQL 时需要按照以下顺序安装这些软件包。首先切换到MySQL的安装路径cd /usr/local/MySQL,然后依次执行下列安装命令
  1. rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm
  2. rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm
  3. rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
  4. 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是新安装的镜像,没有安装任何依赖项,有如下输出信息
  1. [root@2a792e360945 MySQL]# rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
  2. warning: mysql-community-server-5.7.41-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
  3. error: Failed dependencies:
  4.         /usr/bin/perl is needed by mysql-community-server-5.7.41-1.el7.x86_64
  5.         libaio.so.1()(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  6.         libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  7.         libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  8.         libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  9.         libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  10.         libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  11.         perl(Getopt::Long) is needed by mysql-community-server-5.7.41-1.el7.x86_64
  12.         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
  1. [root@2a792e360945 MySQL]# yum list installed | grep mysql
  2. mysql-community-client.x86_64           5.7.41-1.el7                   installed
  3. mysql-community-common.x86_64           5.7.41-1.el7                   installed
  4. mysql-community-libs.x86_64             5.7.41-1.el7                   installed
  5. 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

再次确认是否卸载成功
  1. [root@2a792e360945 MySQL]# rpm -qa | grep mysql
  2. [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
点击查看代码
  1. [root@2a792e360945 MySQL]# yum-config-manager --disable mysql80-community
  2. Loaded plugins: fastestmirror, ovl
  3. ======================================== repo: mysql80-community =========================================
  4. [mysql80-community]
  5. async = True
  6. bandwidth = 0
  7. base_persistdir = /var/lib/yum/repos/x86_64/7
  8. baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64
  9. cache = 0
  10. cachedir = /var/cache/yum/x86_64/7/mysql80-community
  11. check_config_file_age = True
  12. compare_providers_priority = 80
  13. cost = 1000
  14. deltarpm_metadata_percentage = 100
  15. deltarpm_percentage =
  16. enabled = 0
  17. enablegroups = True
  18. exclude =
  19. failovermethod = priority
  20. ftp_disable_epsv = False
  21. gpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadir
  22. gpgcakey =
  23. gpgcheck = True
  24. gpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdir
  25. gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023,
  26.    file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,
  27.    file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  28. hdrdir = /var/cache/yum/x86_64/7/mysql80-community/headers
  29. http_caching = all
  30. includepkgs =
  31. ip_resolve =
  32. keepalive = True
  33. keepcache = False
  34. mddownloadpolicy = sqlite
  35. mdpolicy = group:small
  36. mediaid =
  37. metadata_expire = 21600
  38. metadata_expire_filter = read-only:present
  39. metalink =
  40. minrate = 0
  41. mirrorlist =
  42. mirrorlist_expire = 86400
  43. name = MySQL 8.0 Community Server
  44. old_base_cache_dir =
  45. password =
  46. persistdir = /var/lib/yum/repos/x86_64/7/mysql80-community
  47. pkgdir = /var/cache/yum/x86_64/7/mysql80-community/packages
  48. proxy = False
  49. proxy_dict =
  50. proxy_password =
  51. proxy_username =
  52. repo_gpgcheck = False
  53. retries = 10
  54. skip_if_unavailable = False
  55. ssl_check_cert_permissions = True
  56. sslcacert =
  57. sslclientcert =
  58. sslclientkey =
  59. sslverify = True
  60. throttle = 0
  61. timeout = 30.0
  62. ui_id = mysql80-community/x86_64
  63. ui_repoid_vars = releasever,
  64.    basearch
  65. username =
  66. [root@2a792e360945 MySQL]# yum-config-manager --enable mysql57-community
  67. Loaded plugins: fastestmirror, ovl
  68. ======================================== repo: mysql57-community =========================================
  69. [mysql57-community]
  70. async = True
  71. bandwidth = 0
  72. base_persistdir = /var/lib/yum/repos/x86_64/7
  73. baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64
  74. cache = 0
  75. cachedir = /var/cache/yum/x86_64/7/mysql57-community
  76. check_config_file_age = True
  77. compare_providers_priority = 80
  78. cost = 1000
  79. deltarpm_metadata_percentage = 100
  80. deltarpm_percentage =
  81. enabled = 1
  82. enablegroups = True
  83. exclude =
  84. failovermethod = priority
  85. ftp_disable_epsv = False
  86. gpgcadir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgcadir
  87. gpgcakey =
  88. gpgcheck = True
  89. gpgdir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgdir
  90. gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023,
  91.    file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,
  92.    file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  93. hdrdir = /var/cache/yum/x86_64/7/mysql57-community/headers
  94. http_caching = all
  95. includepkgs =
  96. ip_resolve =
  97. keepalive = True
  98. keepcache = False
  99. mddownloadpolicy = sqlite
  100. mdpolicy = group:small
  101. mediaid =
  102. metadata_expire = 21600
  103. metadata_expire_filter = read-only:present
  104. metalink =
  105. minrate = 0
  106. mirrorlist =
  107. mirrorlist_expire = 86400
  108. name = MySQL 5.7 Community Server
  109. old_base_cache_dir =
  110. password =
  111. persistdir = /var/lib/yum/repos/x86_64/7/mysql57-community
  112. pkgdir = /var/cache/yum/x86_64/7/mysql57-community/packages
  113. proxy = False
  114. proxy_dict =
  115. proxy_password =
  116. proxy_username =
  117. repo_gpgcheck = False
  118. retries = 10
  119. skip_if_unavailable = False
  120. ssl_check_cert_permissions = True
  121. sslcacert =
  122. sslclientcert =
  123. sslclientkey =
  124. sslverify = True
  125. throttle = 0
  126. timeout = 30.0
  127. ui_id = mysql57-community/x86_64
  128. ui_repoid_vars = releasever,
  129.    basearch
  130. username =
复制代码
③安装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

举报 回复 使用道具