阿里雲ECS下基於Centos7.4安裝MySQL5.7.20

 一、首先登陸阿里雲ECS服務器,以下圖所示:node

二、卸載MariaDBmysql

說明:CentOS7.x默認安裝MariaDB而不是MySQL,並且yum服務器上也移除了MySQL相關的軟件包。由於MariaDB和MySQL可能會衝突,故先卸載MariaDB!linux

三、到mysql的官網下載最新版mysql的rpm集合包。nginx

URL以下:https://downloads.mysql.com/archives/community/sql

四、進入/usr/local/src目錄,使用lrzsz中的rz工具進行上傳。shell

 或者直接使用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進行安裝)數據庫

 五、上傳mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar到Linux服務器,並解壓tar包。服務器

六、使用rpm -ivh命令進行安裝。tcp

安裝過程當中缺乏依賴包libaio,使用 yum install -y libaio 進行安裝。ide

再次使用rpm -ivh 安裝

六、上面幾個包有依賴關係,執行有前後順序。

使用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數據庫配置文件)

  1 Xshell 5 (Build 1326)
  2 Copyright (c) 2002-2017 NetSarang Computer, Inc. All rights reserved.
  3 
  4 Type `help' to learn how to use Xshell prompt.
  5 [c:\~]$ 
  6 
  7 Connecting to 47.95.234.20:22...
  8 Connection established.
  9 To escape to local shell, press 'Ctrl+Alt+]'.
 10 
 11 Last login: Mon Feb 19 10:27:46 2018 from 114.240.255.235
 12 
 13 Welcome to Alibaba Cloud Elastic Compute Service !
 14 
 15 [root@iZqmo9i3j77p7eZ ~]# cat /etc/redhat-release 
 16 CentOS Linux release 7.4.1708 (Core) 
 17 [root@iZqmo9i3j77p7eZ ~]# uname -a
 18 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
 19 [root@iZqmo9i3j77p7eZ ~]# rpm -qa | grep -i mariadb
 20 mariadb-libs-5.5.56-2.el7.x86_64
 21 [root@iZqmo9i3j77p7eZ ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
 22 [root@iZqmo9i3j77p7eZ ~]# rpm -qa | grep -i mariadb
 23 [root@iZqmo9i3j77p7eZ ~]# cd /usr/local/src/
 24 [root@iZqmo9i3j77p7eZ src]# yum install -y lrzsz
 25 Loaded plugins: fastestmirror
 26 base                                              | 3.6 kB     00:00     
 27 epel                                              | 4.7 kB     00:00     
 28 extras                                            | 3.4 kB     00:00     
 29 mysql57-community                                 | 2.5 kB     00:00     
 30 nginx                                             | 2.9 kB     00:00     
 31 updates                                           | 3.4 kB     00:00     
 32 (1/3): epel/x86_64/updateinfo                       | 882 kB   00:00     
 33 (2/3): epel/x86_64/primary_db                       | 6.2 MB   00:00     
 34 (3/3): mysql57-community/x86_64/primary_db          | 134 kB   00:00     
 35 Determining fastest mirrors
 36  * base: mirrors.aliyun.com
 37  * epel: mirrors.aliyun.com
 38  * extras: mirrors.aliyun.com
 39  * updates: mirrors.aliyun.com
 40 Package lrzsz-0.12.20-36.el7.x86_64 already installed and latest version
 41 Nothing to do
 42 [root@iZqmo9i3j77p7eZ src]# cd /usr/local/src/
 43 [root@iZqmo9i3j77p7eZ src]# yum install -y lrzsz
 44 Loaded plugins: fastestmirror
 45 Loading mirror speeds from cached hostfile
 46  * base: mirrors.aliyun.com
 47  * epel: mirrors.aliyun.com
 48  * extras: mirrors.aliyun.com
 49  * updates: mirrors.aliyun.com
 50 Package lrzsz-0.12.20-36.el7.x86_64 already installed and latest version
 51 Nothing to do
 52 [root@iZqmo9i3j77p7eZ src]# rz -y
 53 [root@iZqmo9i3j77p7eZ ~]# ls
 54 mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
 55 [root@iZqmo9i3j77p7eZ ~]# tar xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar -C /root/
 56 [root@iZqmo9i3j77p7eZ ~]# ll
 57 total 1158760
 58 -rw-r--r-- 1 root root  593274880 Sep 14 23:52 mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
 59 -rw-r--r-- 1 7155 31415  25090196 Sep 14 23:44 mysql-community-client-5.7.20-1.el7.x86_64.rpm
 60 -rw-r--r-- 1 7155 31415    278300 Sep 14 23:44 mysql-community-common-5.7.20-1.el7.x86_64.rpm
 61 -rw-r--r-- 1 7155 31415   3778120 Sep 14 23:44 mysql-community-devel-5.7.20-1.el7.x86_64.rpm
 62 -rw-r--r-- 1 7155 31415  46238924 Sep 14 23:44 mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
 63 -rw-r--r-- 1 7155 31415  24077232 Sep 14 23:44 mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
 64 -rw-r--r-- 1 7155 31415 128440800 Sep 14 23:44 mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
 65 -rw-r--r-- 1 7155 31415   2238604 Sep 14 23:44 mysql-community-libs-5.7.20-1.el7.x86_64.rpm
 66 -rw-r--r-- 1 7155 31415   2115892 Sep 14 23:44 mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
 67 -rw-r--r-- 1 7155 31415  55538708 Sep 14 23:44 mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
 68 -rw-r--r-- 1 7155 31415 171597916 Sep 14 23:45 mysql-community-server-5.7.20-1.el7.x86_64.rpm
 69 -rw-r--r-- 1 7155 31415  15256460 Sep 14 23:45 mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
 70 -rw-r--r-- 1 7155 31415 118609776 Sep 14 23:45 mysql-community-test-5.7.20-1.el7.x86_64.rpm
 71 [root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
 72 warning: mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 73 Preparing...                          ################################# [100%]
 74 Updating / installing...
 75    1:mysql-community-common-5.7.20-1.e################################# [100%]
 76 [root@iZqmo9i3j77p7eZ ~]# rpm -ivh  mysql-community-libs-5.7.20-1.el7.x86_64.rpm
 77 warning: mysql-community-libs-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 78 Preparing...                          ################################# [100%]
 79 Updating / installing...
 80    1:mysql-community-libs-5.7.20-1.el7################################# [100%]
 81 [root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
 82 warning: mysql-community-client-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 83 Preparing...                          ################################# [100%]
 84 Updating / installing...
 85    1:mysql-community-client-5.7.20-1.e################################# [100%]
 86 [root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
 87 warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 88 error: Failed dependencies:
 89     libaio.so.1()(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
 90     libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
 91     libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
 92 [root@iZqmo9i3j77p7eZ ~]# yum install -y libaio
 93 Loaded plugins: fastestmirror
 94 Loading mirror speeds from cached hostfile
 95  * base: mirrors.aliyun.com
 96  * epel: mirrors.aliyun.com
 97  * extras: mirrors.aliyun.com
 98  * updates: mirrors.aliyun.com
 99 Resolving Dependencies
100 --> Running transaction check
101 ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
102 --> Finished Dependency Resolution
103 
104 Dependencies Resolved
105 
106 =============================================================================================================
107  Package                 Arch                    Version                         Repository             Size
108 =============================================================================================================
109 Installing:
110  libaio                  x86_64                  0.3.109-13.el7                  base                   24 k
111 
112 Transaction Summary
113 =============================================================================================================
114 Install  1 Package
115 
116 Total download size: 24 k
117 Installed size: 38 k
118 Downloading packages:
119 libaio-0.3.109-13.el7.x86_64.rpm                                                      |  24 kB  00:00:00     
120 Running transaction check
121 Running transaction test
122 Transaction test succeeded
123 Running transaction
124 Warning: RPMDB altered outside of yum.
125 ** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
126 2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
127 2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
128   Installing : libaio-0.3.109-13.el7.x86_64                                                              1/1 
129   Verifying  : libaio-0.3.109-13.el7.x86_64                                                              1/1 
130 
131 Installed:
132   libaio.x86_64 0:0.3.109-13.el7                                                                             
133 
134 Complete!
135 [root@iZqmo9i3j77p7eZ ~]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
136 warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
137 Preparing...                          ################################# [100%]
138 Updating / installing...
139    1:mysql-community-server-5.7.20-1.e################################# [100%]
140 [root@iZqmo9i3j77p7eZ ~]# cat /etc/passwd|grep mysql
141 mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/false
142 [root@iZqmo9i3j77p7eZ ~]# mysqld --initialize --user=mysql
143 [root@iZqmo9i3j77p7eZ ~]# cat /var/log/mysqld.log 
144 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).
145 2018-02-19T03:15:06.462877Z 0 [Warning] InnoDB: New log files created, LSN=45790
146 2018-02-19T03:15:06.788535Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
147 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.
148 2018-02-19T03:15:06.854816Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
149 2018-02-19T03:15:06.855447Z 1 [Note] A temporary password is generated for root@localhost: monb3&s#kXfC#此處爲MySQL生成的隨機密碼。
150 [root@iZqmo9i3j77p7eZ ~]# systemctl start mysqld.service
151 [root@iZqmo9i3j77p7eZ ~]# netstat -lntup|grep mysql
152 tcp6       0      0 :::3306                 :::*                    LISTEN      8124/mysqld         
153 [root@iZqmo9i3j77p7eZ ~]# ps -aux|grep mysql
154 mysql     8124  1.2  9.0 1125360 171300 ?      Sl   11:16   0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
155 root      8158  0.0  0.0 112660   972 pts/1    R+   11:16   0:00 grep --color=auto mysql
156 [root@iZqmo9i3j77p7eZ ~]# mysql -u root -h localhost -P 3306 -p#登陸MySQL
157 Enter password: 
158 Welcome to the MySQL monitor.  Commands end with ; or \g.
159 Your MySQL connection id is 3
160 Server version: 5.7.20
161 
162 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
163 
164 Oracle is a registered trademark of Oracle Corporation and/or its
165 affiliates. Other names may be trademarks of their respective
166 owners.
167 
168 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
169 mysql> set password = password('123456');#設置密碼
170 Query OK, 0 rows affected, 1 warning (0.00 sec)
171 mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';#受權遠程訪問鏈接MySQL
172 Query OK, 0 rows affected, 1 warning (0.01 sec)
173 mysql> flush privileges;#將操做即時生效
174 Query OK, 0 rows affected (0.00 sec)
175 mysql> quit;
176 Bye
177 [root@iZqmo9i3j77p7eZ ~]# systemctl enable mysqld.service#加入開機自啓動
View Code
相關文章
相關標籤/搜索