1. 下载mysql安装包
$ wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2018-11-26 13:21:40-- https://dev.mysql.com/get/mysql57-community-release-el7-9.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|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm [following]
--2018-11-26 13:21:41-- https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 125.56.213.148
Connecting to repo.mysql.com (repo.mysql.com)|125.56.213.148|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’
100%[=================================================================================================================================>] 9,224 --.-K/s in 0s
2018-11-26 13:21:42 (132 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]
2. 用yum命令安装mysql
$ sudo yum localinstall mysql57-community-release-el7-9.noarch.rpm
[sudo] password for lmg:
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-9.noarch.rpm: mysql57-community-release-el7-9.noarch
Marking mysql57-community-release-el7-9.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-9 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================
Installing:
mysql57-community-release noarch el7-9 /mysql57-community-release-el7-9.noarch 8.6 k
Transaction Summary
===========================================================================================================================================================================
Install 1 Package
Total size: 8.6 k
Installed size: 8.6 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql57-community-release-el7-9.noarch 1/1
Verifying : mysql57-community-release-el7-9.noarch 1/1
Installed:
mysql57-community-release.noarch 0:el7-9
Complete!
3. 检查mysql是否安装成功,如下则显示Mysqla安装成功
$ yum repolist enabled |grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 74
mysql-tools-community/x86_64 MySQL Tools Community 74
mysql57-community/x86_64 MySQL 5.7 Community Server 307
4. 安装Mysql
$ sudo yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* rpmforge: mirrors.neusoft.edu.cn
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql57-community | 2.5 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 29 kB 00:00:00
(2/3): mysql-tools-community/x86_64/primary_db | 48 kB 00:00:00
(3/3): mysql57-community/x86_64/primary_db | 162 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.24-1.el7 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.24-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.24-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 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.24-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.24-1.el7 mysql57-community 2.2 M
replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5
mysql-community-libs-compat x86_64 5.7.24-1.el7 mysql57-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5
mysql-community-server x86_64 5.7.24-1.el7 mysql57-community 165 M
Installing for dependencies:
libaio x86_64 0.3.109-13.el7 base 24 k
mysql-community-client x86_64 5.7.24-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.24-1.el7 mysql57-community 274 k
Transaction Summary
===========================================================================================================================================================================
Install 3 Packages (+3 Dependent packages)
Total download size: 194 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.24-1.el7.x86_64.rpm is not installed
(2/6): mysql-community-common-5.7.24-1.el7.x86_64.rpm | 274 kB 00:00:00
(3/6): mysql-community-libs-5.7.24-1.el7.x86_64.rpm | 2.2 MB 00:00:00
(4/6): mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm | 2.0 MB 00:00:00
(5/6): mysql-community-client-5.7.24-1.el7.x86_64.rpm | 24 MB 00:00:03
(6/6): mysql-community-server-5.7.24-1.el7.x86_64.rpm | 165 MB 00:00:15
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 12 MB/s | 194 MB 00:00:16
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-9.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.24-1.el7.x86_64 1/7
Installing : mysql-community-libs-5.7.24-1.el7.x86_64 2/7
Installing : mysql-community-client-5.7.24-1.el7.x86_64 3/7
Installing : libaio-0.3.109-13.el7.x86_64 4/7
Installing : mysql-community-server-5.7.24-1.el7.x86_64 5/7
Installing : mysql-community-libs-compat-5.7.24-1.el7.x86_64 6/7
Erasing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 7/7
Verifying : mysql-community-server-5.7.24-1.el7.x86_64 1/7
Verifying : mysql-community-libs-compat-5.7.24-1.el7.x86_64 2/7
Verifying : mysql-community-libs-5.7.24-1.el7.x86_64 3/7
Verifying : mysql-community-common-5.7.24-1.el7.x86_64 4/7
Verifying : libaio-0.3.109-13.el7.x86_64 5/7
Verifying : mysql-community-client-5.7.24-1.el7.x86_64 6/7
Verifying : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 7/7
Installed:
mysql-community-libs.x86_64 0:5.7.24-1.el7 mysql-community-libs-compat.x86_64 0:5.7.24-1.el7 mysql-community-server.x86_64 0:5.7.24-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.24-1.el7 mysql-community-common.x86_64 0:5.7.24-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.60-1.el7_5
Complete!
5. 启动Mysql
$ systemctl start mysqld
6. 查看Mysql启动状态,显示如下状态代表Mysql启动成功
# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2018-11-26 14:23:33 CST; 10s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4317 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4300 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4321 (mysqld)
CGroup: /system.slice/mysqld.service
└─4321 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 26 14:23:33 systemd[1]: Starting MySQL Server...
Nov 26 14:23:33 systemd[1]: Started MySQL Server.
7. 配置默认编码为UTF8
vim /etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
"/etc/my.cnf" 29L, 1016C
重新启动mysql服务
# systemctl restart mysqld