阿里云ECS下基于Centos7.4安装MySQL5.7.20

时间:2021-01-11 17:31:34

 1、首先登录阿里云ECS服务器,如下图所示:

阿里云ECS下基于Centos7.4安装MySQL5.7.20

2、卸载MariaDB

说明:CentOS7.x默认安装MariaDB而不是MySQL,而且yum服务器上也移除了MySQL相关的软件包。因为MariaDB和MySQL可能会冲突,故先卸载MariaDB!

阿里云ECS下基于Centos7.4安装MySQL5.7.20

3、到mysql的官网下载最新版mysql的rpm集合包。

URL如下:https://downloads.mysql.com/archives/community/

阿里云ECS下基于Centos7.4安装MySQL5.7.20

阿里云ECS下基于Centos7.4安装MySQL5.7.20

4、进入/usr/local/src目录,使用lrzsz中的rz工具进行上传。

阿里云ECS下基于Centos7.4安装MySQL5.7.20

阿里云ECS下基于Centos7.4安装MySQL5.7.20

或者直接使用linux 下的wget工具进行下载:wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar(如果没有wget工具,使用yum install -y wget进行安装)

阿里云ECS下基于Centos7.4安装MySQL5.7.20

阿里云ECS下基于Centos7.4安装MySQL5.7.20

 5、上传mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar到Linux服务器,并解压tar包。

阿里云ECS下基于Centos7.4安装MySQL5.7.20

阿里云ECS下基于Centos7.4安装MySQL5.7.20

6、使用rpm -ivh命令进行安装。

阿里云ECS下基于Centos7.4安装MySQL5.7.20

阿里云ECS下基于Centos7.4安装MySQL5.7.20

安装过程中缺少依赖包libaio,使用 yum install -y libaio 进行安装。

阿里云ECS下基于Centos7.4安装MySQL5.7.20

再次使用rpm -ivh 安装

阿里云ECS下基于Centos7.4安装MySQL5.7.20

6、上面几个包有依赖关系,执行有先后顺序。

使用rpm安装方式安装mysql,安装的路径如下:

a. 数据库目录
/var/lib/mysql/
b. 配置文件
/usr/share/mysql(mysql.server命令及配置文件)
c. 相关命令
/usr/bin(mysqladmin mysqldump等命令)
d. 启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)

e. /etc/my.conf(mysql数据库配置文件)

 Xshell 5 (Build 1326)
Copyright (c) 2002-2017 NetSarang Computer, Inc. All rights reserved. Type `help' to learn how to use Xshell prompt.
[c:\~]$ Connecting to 47.95.234.20:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'. Last login: Mon Feb 19 10:27:46 2018 from 114.240.255.235 Welcome to Alibaba Cloud Elastic Compute Service ! [root@iZqmo9i3j77p7eZ ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@iZqmo9i3j77p7eZ ~]# uname -a
Linux iZqmo9i3j77p7eZ 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@iZqmo9i3j77p7eZ ~]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@iZqmo9i3j77p7eZ ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@iZqmo9i3j77p7eZ ~]# rpm -qa | grep -i mariadb
[root@iZqmo9i3j77p7eZ ~]# cd /usr/local/src/
[root@iZqmo9i3j77p7eZ src]# yum install -y lrzsz
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
epel | 4.7 kB 00:00
extras | 3.4 kB 00:00
mysql57-community | 2.5 kB 00:00
nginx | 2.9 kB 00:00
updates | 3.4 kB 00:00
(1/3): epel/x86_64/updateinfo | 882 kB 00:00
(2/3): epel/x86_64/primary_db | 6.2 MB 00:00
(3/3): mysql57-community/x86_64/primary_db | 134 kB 00:00
Determining fastest mirrors
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package lrzsz-0.12.20-36.el7.x86_64 already installed and latest version
Nothing to do
[root@iZqmo9i3j77p7eZ src]# cd /usr/local/src/
[root@iZqmo9i3j77p7eZ src]# yum install -y lrzsz
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package lrzsz-0.12.20-36.el7.x86_64 already installed and latest version
Nothing to do
[root@iZqmo9i3j77p7eZ src]# rz -y
[root@iZqmo9i3j77p7eZ ~]# ls
mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
[root@iZqmo9i3j77p7eZ ~]# tar xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar -C /root/
[root@iZqmo9i3j77p7eZ ~]# ll
total 1158760
-rw-r--r-- 1 root root 593274880 Sep 14 23:52 mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415 25090196 Sep 14 23:44 mysql-community-client-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 278300 Sep 14 23:44 mysql-community-common-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 3778120 Sep 14 23:44 mysql-community-devel-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 46238924 Sep 14 23:44 mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 24077232 Sep 14 23:44 mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 128440800 Sep 14 23:44 mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2238604 Sep 14 23:44 mysql-community-libs-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2115892 Sep 14 23:44 mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 55538708 Sep 14 23:44 mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 171597916 Sep 14 23:45 mysql-community-server-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 15256460 Sep 14 23:45 mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 118609776 Sep 14 23:45 mysql-community-test-5.7.20-1.el7.x86_64.rpm
[root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.20-1.e################################# [100%]
[root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.20-1.el7################################# [100%]
[root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.20-1.e################################# [100%]
[root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
[root@iZqmo9i3j77p7eZ ~]# yum install -y libaio
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =============================================================================================================
Package Arch Version Repository Size
=============================================================================================================
Installing:
libaio x86_64 0.3.109-13.el7 base 24 k Transaction Summary
=============================================================================================================
Install 1 Package Total download size: 24 k
Installed size: 38 k
Downloading packages:
libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
Installing : libaio-0.3.109-13.el7.x86_64 1/1
Verifying : libaio-0.3.109-13.el7.x86_64 1/1 Installed:
libaio.x86_64 0:0.3.109-13.el7 Complete!
[root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.20-1.e################################# [100%]
[root@iZqmo9i3j77p7eZ ~]# cat /etc/passwd|grep mysql
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/false
[root@iZqmo9i3j77p7eZ ~]# mysqld --initialize --user=mysql
[root@iZqmo9i3j77p7eZ ~]# cat /var/log/mysqld.log
2018-02-19T03:15:04.391013Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-19T03:15:06.462877Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-02-19T03:15:06.788535Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-02-19T03:15:06.852414Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 15cbe9f9-1523-11e8-ac67-00163e08bafc.
2018-02-19T03:15:06.854816Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-02-19T03:15:06.855447Z 1 [Note] A temporary password is generated for root@localhost: monb3&s#kXfC#此处为MySQL生成的随机密码。
[root@iZqmo9i3j77p7eZ ~]# systemctl start mysqld.service
[root@iZqmo9i3j77p7eZ ~]# netstat -lntup|grep mysql
tcp6 0 0 :::3306 :::* LISTEN 8124/mysqld
[root@iZqmo9i3j77p7eZ ~]# ps -aux|grep mysql
mysql 8124 1.2 9.0 1125360 171300 ? Sl 11:16 0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 8158 0.0 0.0 112660 972 pts/1 R+ 11:16 0:00 grep --color=auto mysql
[root@iZqmo9i3j77p7eZ ~]# mysql -u root -h localhost -P 3306 -p#登录MySQL
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20 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> set password = password('123456');#设置密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';#授权远程访问连接MySQL
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;#将操作即时生效
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
[root@iZqmo9i3j77p7eZ ~]# systemctl enable mysqld.service#加入开机自启动