centos 6.5 yum安装 mysql 5.6

前端之家收集整理的这篇文章主要介绍了centos 6.5 yum安装 mysql 5.6前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文转自:https://my.oschina.net/lxrm/blog/542706

最近切换到很久不用的centos还略有不适应,默认yum只能安装MysqL 5.1,需要升级又不想编译。于是有了此文。

具体文档地址:

1.http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html

2. http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/


下面是我取其中的部分,完成安装MysqL 5.6 的过程


1. 查看系统里面有没有MysqL 的repo

#yumrepolistall|grepMysqL
#

2. 如果没有发现,则需要配置repo

注意,如果要使用5.7 或者其他任何版本,只能有一个是enabled=1的,其他的都得enabled=0

#vim/etc/yum.repos.d/MysqL-community.repo
#EnabletouseMysqL5.6
[MysqL56-community]
name=MysqL5.6CommunityServer
baseurl=http://repo.MysqL.com/yum/MysqL-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=

3. 再看看是否存在MysqL的repo

#yumrepolistenabled|grepMysqL
MysqL56-communityMysqL5.6CommunityServer214

ok,说明已经有了,下面就可以安装MysqL5.6了

4. 注意,

可能想当然的以为是

#yuminstallMysqL56
//你只会得到
NopackageMysqL56available

实际上官方的安装命令是

#yuminstallMysqL-community-server
//但是,失败了呢
MysqL-community-server-5.6.28-2.el6.x86_64.rpm|53MB00:10

warning:rpmts_HdrFromFdno:HeaderV3DSA/SHA1Signature,keyID5072e1f5:NOKEY
Retrievingkeyfromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL
获取GPG密钥失败:[Errno14]Couldnotopen/readfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL

5.失败乃成功的妈妈

错误提示看:需要验证 GnuPG 签名,还好可以手动,毛主席说,自己动手丰衣足食嘛。

当然,还有一招,我们暂且不用:

http://repo.MysqL.com/yum/MysqL-5.6-community/el/6/x86_64/MysqL-community-server-5.6.28-2.el6.x86_64.rpm

我们接下来按照错误处理过出来搞,把签名先搞起来,参考地址:http://dev.mysql.com/doc/refman/5.6/en/checking-gpg-signature.html

#vim/etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL
写入如下内容

-----BEGINPGPPUBLICKEYBLOCK----- Version:GnuPGv1.4.9(SunOS)

mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3
RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ
fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3
BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW
hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV
K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE
kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI
QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep
rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q2TXlTUUwgUmVs
ZWFzZSBFbmdpbmVlcmluZyA8bXlzcWwtYnVpbGRAb3NzLm9yYWNsZS5jb20+iGkE
ExECACkCGyMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAIZAQUCUwHUZgUJGmbLywAK
CRCMcY07UHLh9V+DAKCjS1gGwgVI/eut+5L+l2v3ybl+ZgCcD7ZoA341HtoroV3U
6xRD09fUgeq0O015U1FMIFBhY2thZ2Ugc2lnbmluZyBrZXkgKHd3dy5teXNxbC5j
b20pIDxidWlsZEBteXNxbC5jb20+iG8EMBECAC8FAk53Pa0oHSBidWlsZEBteXNx
bC5jb20gd2lsb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/O9Rkb
f4fmLe11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHb
uE5p/1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+
Lwqqa8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1Z
aSafanFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGo
TbOWI39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev4
2LmuQT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkK
Ht926s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUO
etdZWhe70YGNPw1yjWJT1IhUBBgRAgAMBQJOdz3tBQkT+wG4ABIHZUdQRwABAQkQ
jHGNO1By4fUUmwCbBYr2+bBEn/L2BOcnw9Z/QFWuhRMAoKVgCFm5fadQ3Afi+UQl
AcOphrnJ
=443I -----ENDPGPPUBLICKEYBLOCK-----

rpm --import /etc/pki/rpm-gpg/RPM*

好的,似乎ok了。我们再来一次吧,嘿嘿

#yuminstallMysqL-community-server

经过一系列Y/N的选择,进度条漂亮的到达了终点。

至此,MysqL 5.6 成功的从yum安装了呢 :-)

启动服务,开启新的旅程吧。


四、MysqL数据库的初始化及相关配置

我们在安装完MysqL数据库以后,会发现会多出一个MysqLd的服务,这个就是咱们的数据库服务,我们通过输入service MysqLd start命令就可以启动我们的MysqL服务。

注意:如果我们是第一次启动MysqL服务,MysqL服务器首先会进行初始化的配置,如:

[root@xiaoluo ~]# service MysqLd start

初始化 MysqL 数据库: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MysqL version. The MysqL daemon,MysqLd,should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MysqL privileges !
Installing MysqL system tables...
OK
Filling help tables...
OK

To start MysqLd at boot time you have to copy
support-files/MysqL.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MysqL root USER !
To do so,start the server,then issue the following commands:

/usr/bin/MysqLadmin -u root password new-password'
/usr/bin/MysqLadmin -u root -h xiaoluo password '

Alternatively you can run:
/usr/bin/MysqL_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MysqL daemon with:
cd /usr ; /usr/bin/MysqLd_safe &

You can test the MysqL daemon with MysqL-test-run.pl
cd /usr/MysqL-test ; perl MysqL-test-run.pl

Please report any problems with the /usr/bin/MysqLbug script!

                                                           [确定]
正在启动 MysqLd:                                            [确定]

这时我们会看到第一次启动MysqL服务器以后会提示非常多的信息,目的就是对MysqL数据库进行初始化操作,当我们再次重新启动MysqL服务时,就不会提示这么多信息了,如:

[root@xiaoluo ~]# service MysqLd restart
停止 MysqLd:                                             [确定]
正在启动 MysqLd:                                          [确定]

我们在使用MysqL数据库时,都得首先启动MysqLd服务,我们可以 通过chkconfig --list | grep MysqLd命令来查看MysqL服务是不是开机自动启动,如:

[root@xiaoluo ~]# chkconfig --list | grep MysqLd
MysqLd             0:关闭    1:关闭    2:关闭    3:关闭    4:关闭    5:关闭    6:关闭

我们发现MysqLd服务并没有开机自动启动,我们当然可以通过chkconfig MysqLd on命令来将其设置成开机启动,这样就不用每次都去手动启动了

[root@xiaoluo ~]# chkconfig MysqLd on
[root@xiaoluo ~]# chkconfig --list | grep MysqL
MysqLd             2:启用    3:启用    4:启用    5:启用     MysqL数据库安装完以后只会有一个root管理员账号,但是此时的root账号还并没有为其设置密码,在第一次启动MysqL服务时,会进行数据库的一些初始化工作,在输出的一大串信息中,我们看到有这样一行信息 :

/usr/bin/MysqLadmin -u root password 'new-password'  // 为root账号设置密码

所以我们可以通过 该命令来给我们的root账号设置密码(注意这个root账号是MysqL的root账号,非Linux的root账号)

[root@xiaoluo ~]# MysqLadmin -u root password root'  // 通过该命令给root账号设置密码为 root

此时我们就可以通过MysqL -u root -p命令来登录我们的MysqL数据库

五、MysqL数据库的主要配置文件

1./etc/my.cnf这是MysqL的主配置文件

我们可以查看一下这个文件的一些信息

[root@xiaoluo etc]# ls my.cnf 
my.cnf
[root@xiaoluo etc]#
cat my.cnf [MysqLd] datadir=/var/lib/MysqL socket=/var/lib/MysqL/MysqL.sock user=MysqL # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [MysqLd_safe] log-error=/var/log/MysqLd.log pid-file=/var/run/MysqLd/MysqLd.pid

2./var/lib/MysqL MysqL数据库数据库文件存放位置

我们的MysqL数据库数据库文件通常是存放在了/ver/lib/MysqL这个目录下

[root@xiaoluo ~]# cd /var/lib/MysqL/
[root@xiaoluo MysqL]# ls -l
总用量 20488
-rw-rw----. 1 MysqL MysqL 10485760 4月   6 22:01 ibdata1
-rw-rw----. 1 MysqL MysqL  5242880 4月   01 ib_logfile0
-rw-rw----. 21:59 ib_logfile1
drwx------. 2 MysqL MysqL     4096 4月   59 MysqL  // 这两个是MysqL数据库安装时默认的两个数据库文件
srwxrwxrwx. 1 MysqL MysqL        0 4月   01 MysqL.sock
drwx------. 59 test  // 这两个是MysqL数据库安装时默认的两个数据库文件

我们可以自己创建一个数据库,来验证一下该数据库文件的存放位置

创建一个我们自己的数据库
MysqL> create database xiaoluo;
Query OK,1 row affected (0.00 sec)

[root@xiaoluo MysqL]# 20492
-rw-rw----. 59 MysqL
srwxrwxrwx. 59 test
drwx------. 15 xiaoluo  // 这个就是我们刚自己创建的xiaoluo数据库
[root@xiaoluo MysqL]# cd xiaoluo/
[root@xiaoluo xiaoluo]# ls
db.opt

3./var/logMysqL数据库的日志输出存放位置

我们的MysqL数据库的一些日志输出存放位置都是在/var/log这个目录下

[root@xiaoluo xiaoluo]# cd 
[root@xiaoluo ~]# cd /var/log
[root@xiaoluo log]# ls
amanda                cron           maillog-20130331   spice-vdagent.log
anaconda.ifcfg.log    cron-20130331  mcelog             spooler
anaconda.log          cups           messages           spooler-20130331
anaconda.program.log  dirsrv         messages-20130331  sssd
anaconda.storage.log  dmesg          MysqLd.log         tallylog
anaconda.syslog       dmesg.old      ntpstats           tomcat6
anaconda.xlog         dracut.log     piranha            wpa_supplicant.log
anaconda.yum.log      gdm            pm-powersave.log   wtmp
audit                 httpd          ppp                Xorg.0.log
boot.log              ibacm.log      prelink            Xorg.0.log.old
btmp                  lastlog        sa                 Xorg.1.log
btmp-20130401         libvirt        samba              Xorg.2.log
cluster               luci           secure             Xorg.9.log
ConsoleKit            maillog        secure-20130331    yum.log

其中MysqLd.log 这个文件就是我们存放我们跟MysqL数据库进行操作而产生的一些日志信息,通过查看该日志文件,我们可以从中获得很多信息

因为我们的MysqL数据库是可以通过网络访问的,并不是一个单机版数据库,其中使用的协议是 tcp/ip 协议,我们都知道MysqL数据库绑定的端口号是 3306 ,所以我们可以通过netstat -anp命令来查看一下,Linux系统是否在监听 3306 这个端口号:

结果如上所示,Linux系统监听的3306端口号就是我们的MysqL数据库!!!!

原文链接:https://www.f2er.com/centos/378644.html

猜你在找的CentOS相关文章