Linux( CentOS)安装Mysql

在CentOS上安装Mysql,留存记录,待以后查看。参考Mysql官网的 Installing MySQL on Linux Using the MySQL Yum Repository

安装准备

系统信息

命令:uname -a

[root@localhost /]# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

检测是否安装

命令:rpm -qa | grep mysql,搜索指定rpm包是否安装。

安装前先检测系统中是否安装有mysql,如果有则可以先将原有的数据库卸载。我已经安装好了,信息为:

[root@localhost /]# rpm -qa | grep mysql
mysql-community-devel-5.6.35-2.el7.x86_64
mysql-community-libs-5.6.35-2.el7.x86_64
mysql-community-release-el7-5.noarch
mysql-community-client-5.6.35-2.el7.x86_64
mysql-community-server-5.6.35-2.el7.x86_64
mysql-community-common-5.6.35-2.el7.x86_64

删除已有软件

如果已经有安装过,可以通过 rpm -e 命令 或者 rpm -e –nodeps 命令来卸载。

  • 普通删除模式
[root@localhost /]# rpm -e mysql-community-devel

删除时也会报错,无法删除,因为有依赖关系存在:

[root@localhost /]# rpm -e mysql-community-libs 
error: Failed dependencies:
    libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    mysql-community-libs(x86-64) >= 5.6.10 is needed by (installed) mysql-community-client-5.6.35-2.el7.x86_64
  • 强力删除模式

如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除。

[root@localhost /]# rpm -e --nodeps mysql-community-common  

在删除完以后可以通过 rpm -qa | grep mysql 命令来查看mysql是否已经卸载成功!!

安装

客户端

使用 yum install mysql,安装成功,过程提示:

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror.premi.st
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1:mariadb-5.5.52-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                          Arch                                       Version                                            Repository                                Size
===============================================================================================================================================================================================
Installing:
 mariadb                                          x86_64                                     1:5.5.52-1.el7                                     base                                     8.7 M
Installing for dependencies:
 mariadb-libs                                     x86_64                                     1:5.5.52-1.el7                                     base                                     761 k

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 9.5 M
Installed size: 53 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): mariadb-libs-5.5.52-1.el7.x86_64.rpm                                                                                                                             | 761 kB  00:00:00     
(2/2): mariadb-5.5.52-1.el7.x86_64.rpm                                                                                                                                  | 8.7 MB  00:00:08     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                          1.1 MB/s | 9.5 MB  00:00:08     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 6 pre-existing rpmdb problem(s), 'yum check' output follows:
perl-DBD-MySQL-4.023-5.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
perl-DBD-MySQL-4.023-5.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils >= ('0', '1.6', None)
  Installing : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                                          1/2 
  Installing : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                                               2/2 
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                                               1/2 
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                                          2/2 

Installed:
  mariadb.x86_64 1:5.5.52-1.el7                                                                                                                                                                

Dependency Installed:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                                                                                                                                           

Complete!

服务端

使用 yum install mysql-server 时,无法安装,提示:

[root@localhost /]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror.premi.st
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
No package mysql-server available.
Error: Nothing to do

需要自己去下载,然后安装,下载地址:
Download MySQL Community Server,根据系统选择好版本。

[root@localhost /]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
--2017-02-27 22:51:57--  http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm [following]
--2017-02-27 22:51:58--  https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm [following]
--2017-02-27 22:51:59--  https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 69.192.245.30
Connecting to repo.mysql.com (repo.mysql.com)|69.192.245.30|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ?.ysql-community-release-el7-5.noarch.rpm?

100%[=====================================================================================================================================================>] 6,140       --.-K/s   in 0s      

2017-02-27 22:52:00 (585 MB/s) - ?.ysql-community-release-el7-5.noarch.rpm?.saved [6140/6140]

下载完成后,安装并显示进度:

[root@localhost application]# rpm -ivh mysql-community-release-el7-5.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]

再安装 server :

[root@localhost application]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror.premi.st
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.35-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.35-2.el7 for package: mysql-community-server-5.6.35-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.35-2.el7.x86_64
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be obsoleted
---> Package mysql-community-client.x86_64 0:5.6.35-2.el7 will be obsoleting
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.35-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.35-2.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted
---> Package mysql-community-libs.x86_64 0:5.6.35-2.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                              Arch                                 Version                                       Repository                                       Size
===============================================================================================================================================================================================
Installing:
 mysql-community-client                               x86_64                               5.6.35-2.el7                                  mysql56-community                                19 M
     replacing  mariadb.x86_64 1:5.5.52-1.el7
 mysql-community-libs                                 x86_64                               5.6.35-2.el7                                  mysql56-community                               2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-server                               x86_64                               5.6.35-2.el7                                  mysql56-community                                59 M
Installing for dependencies:
 mysql-community-common                               x86_64                               5.6.35-2.el7                                  mysql56-community                               257 k

Transaction Summary
===============================================================================================================================================================================================
Install  3 Packages (+1 Dependent package)

Total download size: 81 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): mysql-community-common-5.6.35-2.el7.x86_64.rpm                                                                                                                   | 257 kB  00:00:02     
mysql-community-libs-5.6.35-2. FAILED                                             5% [====                                                                   ]   28 B/s | 4.8 MB 778:23:21 ETA 
http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-libs-5.6.35-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-libs-5.6.35-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
mysql-community-client-5.6.35- FAILED                                             3% [==-                                                                    ] 6.8 kB/s | 2.9 MB  03:15:45 ETA 
http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-client-5.6.35-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-client-5.6.35-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
mysql-community-server-5.6.35- FAILED                                           13% [=========-                                                            ]  0.6 B/s |  11 MB 31677:54:44 ETA 
http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.35-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.35-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(2/4): mysql-community-libs-5.6.35-2.el7.x86_64.rpm                                                                                                                     | 2.0 MB  00:00:00     
(3/4): mysql-community-client-5.6.35-2.el7.x86_64.rpm                                                                                                                   |  19 MB  00:14:10     
mysql-community-server-5.6.35- FAILED                                            44% [===============================                                       ]  7.7 B/s |  36 MB 1690:36:00 ETA 
http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.35-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.35-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
mysql-community-server-5.6.35- FAILED                                            52% [====================================                                  ]  7.6 B/s |  42 MB 1489:03:48 ETA 
http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.35-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-server-5.6.35-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(4/4): mysql-community-server-5.6.35-2.el7.x86_64.rpm                                                                                                                   |  59 MB  00:20:16     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                           21 kB/s |  81 MB  01:06:44     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils >= ('0', '1.6', None)
  Installing : mysql-community-common-5.6.35-2.el7.x86_64                                                                                                                                  1/6 
  Installing : mysql-community-libs-5.6.35-2.el7.x86_64                                                                                                                                    2/6 
  Installing : mysql-community-client-5.6.35-2.el7.x86_64                                                                                                                                  3/6 
  Installing : mysql-community-server-5.6.35-2.el7.x86_64                                                                                                                                  4/6 
  Erasing    : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                                               5/6 
  Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                                          6/6 
  Verifying  : mysql-community-client-5.6.35-2.el7.x86_64                                                                                                                                  1/6 
  Verifying  : mysql-community-libs-5.6.35-2.el7.x86_64                                                                                                                                    2/6 
  Verifying  : mysql-community-common-5.6.35-2.el7.x86_64                                                                                                                                  3/6 
  Verifying  : mysql-community-server-5.6.35-2.el7.x86_64                                                                                                                                  4/6 
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                                               5/6 
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                                          6/6 

Installed:
  mysql-community-client.x86_64 0:5.6.35-2.el7                    mysql-community-libs.x86_64 0:5.6.35-2.el7                    mysql-community-server.x86_64 0:5.6.35-2.el7                   

Dependency Installed:
  mysql-community-common.x86_64 0:5.6.35-2.el7                                                                                                                                                 

Replaced:
  mariadb.x86_64 1:5.5.52-1.el7                                                               mariadb-libs.x86_64 1:5.5.52-1.el7                                                              

Complete!

开发包

服务端安装好后,需要安装 mysql-devel,包含了所需要的库和文件,如果需要编译其他Mysql客户程序,必须要安装。这里有一个解释:

That is what RPM-based Linuxes typically call the MySQL development 
files package.  Typically this is packaged separately from the MySQL 
database program itself and the client programs.

安装过程:

[root@localhost /]# yum install mysql-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror.premi.st
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.6.35-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                              Arch                                  Version                                     Repository                                        Size
===============================================================================================================================================================================================
Installing:
 mysql-community-devel                                x86_64                                5.6.35-2.el7                                mysql56-community                                3.4 M

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package

Total download size: 3.4 M
Installed size: 21 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-devel-5.6.35-2.el7.x86_64.rpm                                                                                                                           | 3.4 MB  00:01:11     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-devel-5.6.35-2.el7.x86_64                                                                                                                                   1/1 
  Verifying  : mysql-community-devel-5.6.35-2.el7.x86_64                                                                                                                                   1/1 

Installed:
  mysql-community-devel.x86_64 0:5.6.35-2.el7                                                                                                                                                  

Complete!

到这里就算安装成功了,还有对Mysql的一些配置,参见另外一篇文章。

总结

  • 查看系统信息:uname -a;
  • 查看是否安装:rpm -qa | grep mysql;
  • 删除已安装软件:rpm -e mysql-community-devel 或 rpm -e –nodeps mysql-community-common ;
  • 安装客户端:yum install mysql;
  • 安装服务端:yum install mysql-server ,如果失败:
  1. 下载 wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  2. 安装 rpm -ivh mysql-community-release-el7-5.noarch.rpm ;
  3. 服务端:yum install mysql-community-server;
  • 安装开发包:yum install mysql-devel;
  • 完成,测试。
    原文作者:Impact
    原文地址: https://www.jianshu.com/p/15a1659bc38d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞