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;
  • 完成,测试。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,602评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,442评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,878评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,306评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,330评论 5 373
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,071评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,382评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,006评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,512评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,965评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,094评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,732评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,283评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,286评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,512评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,536评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,828评论 2 345

推荐阅读更多精彩内容