您的位置:首页 > 运维架构 > Linux

CentOS7下yum方式安装mysql5.6

2016-04-07 13:04 826 查看
在Centos7中用MariaDB代替了mysql数据库。所以在新安装MySQL前必须做好对系统的清理工作。

一.清理CentOS7下的MariaDB。

[root@localhost~]#rpm-qa|grempmariadb

[root@localhost~]#rpm-e--nodepsmariadb.x86_64[code]1
:5.5.41-2.el7_0[/code]
二.下载MySQL的yum包

Linux系统自带的repo是不会自动更新每个软件的最新版本(基本都是比较靠后的稳定版),所以无法通过yum方式安装MySQL的高级版本。所以我们需要先安装带有当前可用的mysql5系列社区版资源的rpm包(确保电脑联网)。

[root@localhost~]#wgethttp://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@localhost~]#rpm-ivhmysql-community-release-el7-5.noarch.rpm

查看当前可用的mysql安装资源

[root@localhost~]#yumrepolistenabled|grep"mysql.*-community.*"

mysql-connectors-community/x86_64MySQLConnectorsCommunity21

mysql-tools-community/x86_64MySQLToolsCommunity33

mysql56-community/x86_64MySQL5.6CommunityServer214

安装mysql

[root@localhost~]#yuminstallmysql-community-server

已加载插件:fastestmirror,langpacks

base|3.6kB00:00

extras|3.4kB00:00

mysql-connectors-community|2.5kB00:00

mysql-tools-community|2.5kB00:00

mysql56-community|2.5kB00:00

updates|3.4kB00:00

(1/5):extras/7/x86_64/primary_db|117kB00:00

(2/5):mysql-connectors-community/x86_64/primary_db|9.8kB00:00

(3/5):mysql-tools-community/x86_64/primary_db|25kB00:01

(4/5):mysql56-community/x86_64/primary_db|115kB00:01

(5/5):updates/7/x86_64/primary_db|3.9MB00:01

Determiningfastestmirrors

*base:mirrors.pubyun.com

*extras:mirrors.pubyun.com

*updates:mirrors.pubyun.com

正在解决依赖关系

-->正在检查事务

--->软件包mysql-community-server.x86_64.0.5.6.29-2.el7将被安装

-->正在处理依赖关系mysql-community-common(x86-64)=5.6.29-2.el7,它被软件包mysql-community-server-5.6.29-2.el7.x86_64需要

-->正在处理依赖关系mysql-community-client(x86-64)=5.6.29-2.el7,它被软件包mysql-community-server-5.6.29-2.el7.x86_64需要

-->正在检查事务

--->软件包mysql-community-client.x86_64.0.5.6.29-2.el7将被安装

-->正在处理依赖关系mysql-community-libs(x86-64)=5.6.29-2.el7,它被软件包mysql-community-client-5.6.29-2.el7.x86_64需要

--->软件包mysql-community-common.x86_64.0.5.6.29-2.el7将被安装

-->正在检查事务

--->软件包mysql-community-libs.x86_64.0.5.6.29-2.el7将被安装

-->解决依赖关系完成

依赖关系解决

=================================================================

Package架构版本源大小

=================================================================

正在安装:

mysql-community-serverx86_645.6.29-2.el7mysql56-community58M

为依赖而安装:

mysql-community-clientx86_645.6.29-2.el7mysql56-community19M

mysql-community-commonx86_645.6.29-2.el7mysql56-community256k

mysql-community-libsx86_645.6.29-2.el7mysql56-community2.0M

事务概要

=================================================================

安装1软件包(+3依赖软件包)

总下载量:79M

安装大小:344M

Isthisok[y/d/N]:y

Downloadingpackages:

警告:/var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.29-2.el7.x86_64.rpm:头V3DSA/SHA1Signature,密钥ID5072e1f5:NOKEY

mysql-community-common-5.6.29-2.el7.x86_64.rpm的公钥尚未安装

(1/4):mysql-community-common-5.6.29-2.el7.x86_64.rpm|256kB00:01

(2/4):mysql-community-libs-5.6.29-2.el7.x86_64.rpm|2.0MB00:02

(3/4):mysql-community-server-5.6.29-2.el7.x86_64.rpm|58MB00:29

mysql-community-client-5.6.29-FAILED
http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-client-5.6.29-2.el7.x86_64.rpm:[Errno12]Timeoutonhttp://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-client-5.6.29-2.el7.x86_64.rpm:(28,'Operationtooslow.Lessthan1000bytes/sectransferredthelast30seconds')

正在尝试其它镜像。

(4/4):mysql-community-client-5.6.29-2.el7.x86_64.rpm|19MB12:12

-----------------------------------------------------------------

总计105kB/s|79MB12:51

从file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql检索密钥

导入GPGkey0x5072E1F5:

用户ID:"MySQLReleaseEngineering<mysql-build@oss.oracle.com>"

指纹:a4a9406876fcbd3c456770c88c718d3b5072e1f5

软件包:mysql-community-release-el7-5.noarch(installed)

来自:file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

是否继续?[y/N]:y

Runningtransactioncheck

Runningtransactiontest

Transactiontestsucceeded

Runningtransaction

警告:RPM数据库已被非yum程序修改。

正在安装:mysql-community-common-5.6.29-2.el7.x86_641/4

正在安装:mysql-community-libs-5.6.29-2.el7.x86_642/4

正在安装:mysql-community-client-5.6.29-2.el7.x86_643/4

正在安装:mysql-community-server-5.6.29-2.el7.x86_644/4

warning:/etc/my.cnfcreatedas/etc/my.cnf.rpmnew

验证中:mysql-community-common-5.6.29-2.el7.x86_641/4

验证中:mysql-community-libs-5.6.29-2.el7.x86_642/4

验证中:mysql-community-client-5.6.29-2.el7.x86_643/4

验证中:mysql-community-server-5.6.29-2.el7.x86_644/4

已安装:

mysql-community-server.x86_640:5.6.29-2.el7

作为依赖被安装:

mysql-community-client.x86_640:5.6.29-2.el7

mysql-community-common.x86_640:5.6.29-2.el7

mysql-community-libs.x86_640:5.6.29-2.el7

完毕!

三.MySQL安装完成后,进行相关配置

a)[code]#######安装成功后,将其加入开机启动

systemctlenablemysqld

b)
#######
启动mysql服务进程

systemctl
startmysqld[/code]
c)#######配置mysql(设置密码等)

mysql_secure_installation


NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMySQL

SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!


InordertologintoMySQLtosecureit,we'llneedthecurrent

passwordfortherootuser.Ifyou'vejustinstalledMySQL,and

youhaven'tsettherootpasswordyet,thepasswordwillbeblank,

soyoushouldjustpressenterhere.


Entercurrentpasswordforroot(enterfornone):

OK,successfullyusedpassword,movingon...


SettingtherootpasswordensuresthatnobodycanlogintotheMySQL

rootuserwithouttheproperauthorisation.


Setrootpassword?[Y/n]y[设置root用户密码]

Newpassword:

Re-enternewpassword:

Passwordupdatedsuccessfully!

Reloadingprivilegetables..

...Success!


Bydefault,aMySQLinstallationhasananonymoususer,allowinganyone

tologintoMySQLwithouthavingtohaveauseraccountcreatedfor

them.Thisisintendedonlyfortesting,andtomaketheinstallation

goabitsmoother.Youshouldremovethembeforemovingintoa

productionenvironment.


Removeanonymoususers?[Y/n]y[删除匿名用户]

...Success!


Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This

ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.


Disallowrootloginremotely?[Y/n]y[禁止root远程登录]

...Success!


Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecan

access.Thisisalsointendedonlyfortesting,andshouldberemoved

beforemovingintoaproductionenvironment.


Removetestdatabaseandaccesstoit?[Y/n]y[删除test数据库]

-Droppingtestdatabase...

ERROR1008(HY000)atline1:Can'tdropdatabase'test';[code]databasedoesn'texist

...Failed!Notcritical,keepmoving...

-Removingprivilegesontestdatabase...

...Success!


Reloadingtheprivilegetableswillensurethatallchangesmadesofar

willtakeeffectimmediately.


Re
loadprivilegetablesnow?[Y/n]y[刷新权限][/code]
...Success!


Alldone!Ifyou'vecompletedalloftheabovesteps,yourMySQL

installationshouldnowbesecure.


ThanksforusingMySQL!


Cleaningup...


四.Yum安装后mysql的文件所在的位置:

/usr/bin(客户端程序和脚本)

/usr/sbin(mysql服务器)

/var/lib/mysql/(日志文件和数据库)

/usr/share/doc/packages(文档)

/usr/include/mysql(包含(头)文件)

/usr/lib/mysql(库文件)

/usr/share/mysql/(错误消息和字符集文件)

/usr/share/sql-bench(基准程序)

五.Yum安装的优缺点

优点:安装简单,适合初学者学习使用

缺点:需要单独下载客户端和服务器;安装路径不灵活,默认路径不能修改,一台服务器只能安装一个MySQL
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: