CentOS安装MySQL5.7

DogJay 2019-05-18 系统运维 548人已围观


1.下载MYSQL的rpm包


[root@VM_0_4_centos ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2019-05-18 11:41:52--  http://dev.mysql.com/get/mysql57-community-release-el7-8.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/mysql57-community-release-el7-8.noarch.rpm [following]
--2019-05-18 11:41:53--  https://dev.mysql.com/get/mysql57-community-release-el7-8.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//mysql57-community-release-el7-8.noarch.rpm [following]
--2019-05-18 11:42:04--  https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.60.72.128
Connecting to repo.mysql.com (repo.mysql.com)|23.60.72.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9116 (8.9K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-8.noarch.rpm’

100%[======================================>] 9,116       25.5KB/s   in 0.3s   

2019-05-18 11:42:07 (25.5 KB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]


2.安装MySQL的yum源


[root@VM_0_4_centos ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
Marking mysql57-community-release-el7-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch   Version
                                  Repository                               Size
================================================================================
Installing:
 mysql57-community-release
                     noarch el7-8 /mysql57-community-release-el7-8.noarch 8.2 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 8.2 k
Installed size: 8.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql57-community-release-el7-8.noarch                       1/1 
  Verifying  : mysql57-community-release-el7-8.noarch                       1/1 

Installed:
  mysql57-community-release.noarch 0:el7-8                                      

Complete!


3.检查MySQL的yum源是否安装成功


[root@VM_0_4_centos ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64    MySQL Connectors Community              10
mysql-tools-community/x86_64         MySQL Tools Community                    9
mysql57-community/x86_64             MySQL 5.7 Community Server              34


4.修改默认安装的MySQL版本


[root@VM_0_4_centos ~]# vim /etc/yum.repos.d/mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$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/7/$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/7/$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/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

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

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


5.安装MySQL


[root@VM_0_4_centos ~]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.26-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.26-1.el7 for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.26-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.26-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.26-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.26-1.el7 will be installed
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.26-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.26-1.el7 will be obsoleting
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-7.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                      Arch    Version          Repository          Size
================================================================================
Installing:
 mysql-community-libs         x86_64  5.7.26-1.el7     mysql57-community  2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-libs-compat  x86_64  5.7.26-1.el7     mysql57-community  2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-server       x86_64  5.7.26-1.el7     mysql57-community  166 M
Installing for dependencies:
 mysql-community-client       x86_64  5.7.26-1.el7     mysql57-community   24 M
 mysql-community-common       x86_64  5.7.26-1.el7     mysql57-community  274 k
 numactl-libs                 x86_64  2.0.9-7.el7      os                  29 k
Updating for dependencies:
 postfix                      x86_64  2:2.10.1-7.el7   os                 2.4 M

Transaction Summary
================================================================================
Install  3 Packages (+3 Dependent packages)
Upgrade             ( 1 Dependent package)

Total download size: 197 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.26-1.el7.x86_64.rpm is not installed
(1/7): mysql-community-common-5.7.26-1.el7.x86_64.rpm      | 274 kB   00:04     
(2/7): mysql-community-client-5.7.26-1.el7.x86_64.rpm      |  24 MB   00:22     
(3/7): mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm | 2.0 MB   00:02     
(4/7): numactl-libs-2.0.9-7.el7.x86_64.rpm                 |  29 kB   00:00     
(5/7): mysql-community-libs-5.7.26-1.el7.x86_64.rpm        | 2.2 MB   00:20     
(6/7): postfix-2.10.1-7.el7.x86_64.rpm                     | 2.4 MB   00:00     
(7/7): mysql-community-server-5.7.26-1.el7.x86_64.rpm      | 166 MB   01:10     
--------------------------------------------------------------------------------
Total                                              2.1 MB/s | 197 MB  01:35     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-8.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.26-1.el7.x86_64                   1/9 
  Installing : mysql-community-libs-5.7.26-1.el7.x86_64                     2/9 
  Installing : mysql-community-client-5.7.26-1.el7.x86_64                   3/9 
  Installing : mysql-community-libs-compat-5.7.26-1.el7.x86_64              4/9 
  Installing : numactl-libs-2.0.9-7.el7.x86_64                              5/9 
  Installing : mysql-community-server-5.7.26-1.el7.x86_64                   6/9 
  Updating   : 2:postfix-2.10.1-7.el7.x86_64                                7/9 
  Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                8/9 
  Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                           9/9 
  Verifying  : mysql-community-server-5.7.26-1.el7.x86_64                   1/9 
  Verifying  : numactl-libs-2.0.9-7.el7.x86_64                              2/9 
  Verifying  : mysql-community-client-5.7.26-1.el7.x86_64                   3/9 
  Verifying  : 2:postfix-2.10.1-7.el7.x86_64                                4/9 
  Verifying  : mysql-community-common-5.7.26-1.el7.x86_64                   5/9 
  Verifying  : mysql-community-libs-compat-5.7.26-1.el7.x86_64              6/9 
  Verifying  : mysql-community-libs-5.7.26-1.el7.x86_64                     7/9 
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                           8/9 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                9/9 

Installed:
  mysql-community-libs.x86_64 0:5.7.26-1.el7                                    
  mysql-community-libs-compat.x86_64 0:5.7.26-1.el7                             
  mysql-community-server.x86_64 0:5.7.26-1.el7                                  

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.26-1.el7                                  
  mysql-community-common.x86_64 0:5.7.26-1.el7                                  
  numactl-libs.x86_64 0:2.0.9-7.el7                                             

Dependency Updated:
  postfix.x86_64 2:2.10.1-7.el7                                                 

Replaced:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                            

Complete!


6.启动MySQL并查看MySQL运行状态


[root@VM_0_4_centos ~]# systemctl start mysqld
[root@VM_0_4_centos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/sy