yum安装mysql-5.7

一、简述:

Centos 默认yum安装的mysql版本是5.1的相对比较老了,我们有时想安装高点的版本又不想去编译安装时,可以试试用这个方法来进行yum安装5.5-5.7版本的mysql


二、默认的Centos yum安装mysql时:

[root@zabbixclient ~]# rpm -qa |grep mysql  
mysql-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
[root@zabbixclient ~]#

三、yum 安装5.6版本的:

3.1 先卸载原有的rpm包 --nodeps (不验证依赖关系)
[root@zabbixclient ~]# rpm -e --nodeps mysql-5.1.73-8.el6_8.x86_64 
[root@zabbixclient ~]# rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
[root@zabbixclient ~]# rpm -e --nodeps mysql-server-5.1.73-8.el6_8.x86_64
3.2 下载yum的mysql更新包并安装:
[root@zabbixclient ~]# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
[root@zabbixclient ~]# rpm -ivh mysql-community-release-el6-5.noarch.rpm
3.3 可能会出现这个报错
.
.
Total download size: 79 M
Downloading Packages:
(1/7): mysql-community-client-5.6.36-2.el6.x86_64.rpm                                                             |  18 MB     00:05     
(2/7): mysql-community-common-5.6.36-2.el6.x86_64.rpm                                                             | 308 kB     00:00     
(3/7): mysql-community-libs-5.6.36-2.el6.x86_64.rpm                                                               | 1.9 MB     00:00     
(4/7): mysql-community-libs-compat-5.6.36-2.el6.x86_64.rpm                                                        | 1.6 MB     00:00     
(5/7): mysql-community-server-5.6.36-2.el6.x86_64.rpm                                                             |  55 MB     00:20     
(6/7): postfix-2.6.6-8.el6.x86_64.rpm                                                                             | 2.0 MB     00:01     


Error Downloading Packages:
  perl-DBI-1.609-4.el6.x86_64: failure: Packages/perl-DBI-1.609-4.el6.x86_64.rpm from Centos6.5: [Errno 256] No more mirrors to try.
3.4 提示

系统找不到perl-DBI的包,我们需要去其他地方下载并安装它 >>

[root@zabbixclient ~]# wget ftp://ftp.linux.ro/centos/6.8/os/x86_64/Packages/perl-DBI-1.609-4.el6.x86_64.rpm
[root@zabbixclient ~]# rpm -ivh perl-DBI-1.609-4.el6.x86_64.rpm 
3.5 再次yum安装并验证
[root@zabbixclient ~]# yum -y install mysql-community-server 
.
.
Installed:
  mysql-community-libs.x86_64 0:5.6.36-2.el6                       mysql-community-libs-compat.x86_64 0:5.6.36-2.el6                    
  mysql-community-server.x86_64 0:5.6.36-2.el6                    

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.36-2.el6                        mysql-community-common.x86_64 0:5.6.36-2.el6                       

Dependency Updated:
  postfix.x86_64 2:2.6.6-8.el6                                                                                                           

Replaced:
  mysql-libs.x86_64 0:5.1.71-1.el6                                                                                                       
[root@zabbixclient ~]# service mysqld start

[root@zabbixclient ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye
[root@zabbixclient ~]# 

四、版本选择

用该方法默认是安装mysql5.6的版本,如需要安装5.5或5.7的版本可在更新mysql的yum源后在
/etc/yum.re/mysql-community.repo 的yum配置文件选择需要安装的版本信息

[root@zabbixclient ~]# cat /etc/yum.repos.d/mysql-community.repo 
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# 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=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[root@zabbixclient ~]# 

安装后如修改了 /etc/my.cnf 后需先进行初始化,再操作

# --initialize-insecure 初始化data目录的同时,会自动生成无密码的root用户
mysqld --initialize-insecure   --user=mysql --datadir=/data/mysql/    

# 或者 有密码
mysqld --initialize --datadir=/data/mysql/  --user=mysql   
comments powered by Disqus