centos 6.5 yum安装 mysql 5.6
扫描二维码
随时随地手机看文章
最近切换到很久不用的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
# yum repolist all | grep mysql #
2. 如果没有发现,则需要配置repo
注意,如果要使用5.7 或者其他任何版本,只能有一个是 enabled=1的,其他的都得enabled=0。
#vim /etc/yum.repos.d/mysql-community.repo # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=
3. 再看看是否存在mysql的repo
# yum repolist enabled | grep mysql mysql56-community MySQL 5.6 Community Server 214
ok,说明已经有了,下面就可以安装mysql5.6了
4. 注意,
可能想当然的以为是
# yum install mysql56 //你只会得到 No package mysql56 available
实际上官方的安装命令是
# yum install mysql-community-server //但是,失败了呢 mysql-community-server-5.6.28-2.el6.x86_64.rpm | 53 MB 00:10 warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 获取 GPG 密钥失败:[Errno 14] Could not open/read file:///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 写入如下内容 -----BE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DsDD9MZ1Z aSafanFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGo TbOWI39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev4 2LmuQT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkK Ht926s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUO etdZWhe70YGNPw1yjWJT1IhUBBgRAgAMBQJOdz3tBQkT+wG4ABIHZUdQRwABAQkQ jHGNO1By4fUUmwCbBYr2+bBEn/L2BOcnw9Z/QFWuhRMAoKVgCFm5fadQ3Afi+UQl AcOphrnJ =443I -----END PGP PUBLIC KEY BLOCK-----
rpm --import /etc/pki/rpm-gpg/RPM*
好的,似乎ok了。我们再来一次吧,嘿嘿
# yum install mysql-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 'new-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 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
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月 6 22:01 ib_logfile0 -rw-rw----. 1 mysql mysql 5242880 4月 6 21:59 ib_logfile1 drwx------. 2 mysql mysql 4096 4月 6 21:59 mysql // 这两个是mysql数据库安装时默认的两个数据库文件 srwxrwxrwx. 1 mysql mysql 0 4月 6 22:01 mysql.sock drwx------. 2 mysql mysql 4096 4月 6 21:59 test // 这两个是mysql数据库安装时默认的两个数据库文件
我们可以自己创建一个数据库,来验证一下该数据库文件的存放位置
创建一个我们自己的数据库: mysql> create database xiaoluo; Query OK, 1 row affected (0.00 sec) [root@xiaoluo mysql]# ls -l 总用量 20492 -rw-rw----. 1 mysql mysql 10485760 4月 6 22:01 ibdata1 -rw-rw----. 1 mysql mysql 5242880 4月 6 22:01 ib_logfile0 -rw-rw----. 1 mysql mysql 5242880 4月 6 21:59 ib_logfile1 drwx------. 2 mysql mysql 4096 4月 6 21:59 mysql srwxrwxrwx. 1 mysql mysql 0 4月 6 22:01 mysql.sock drwx------. 2 mysql mysql 4096 4月 6 21:59 test drwx------. 2 mysql mysql 4096 4月 6 22:15 xiaoluo // 这个就是我们刚自己创建的xiaoluo数据库 [root@xiaoluo mysql]# cd xiaoluo/ [root@xiaoluo xiaoluo]# ls db.opt
3./var/log mysql数据库的日志输出存放位置
我们的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数据库!!!!