CentOS7安装MySQL5.7

在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。

1.下载并安装MySQL官方的 Yum Repository

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@VM_0_6_centos ~]wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
--2019-07-27 14:12:54--  http://dev.mysql.com/get/mysql57-community-release-el7-10.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 sentawaiting response... 301 Moved Permanently
Locationhttps://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [following]
--2019-07-27 14:12:55--  https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sentawaiting response... 302 Found
Locationhttps://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm [following]
--2019-07-27 14:13:01--  https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.57.113.239
Connecting to repo.mysql.com (repo.mysql.com)|23.57.113.239|:443... connected.
HTTP request sentawaiting response... 200 OK
Length25548 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-10.noarch.rpm
100%[==================================================================================>] 25,548      --.-K/s   in 0.1s    
2019-07-27 14:13:02 (213 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]
-cNo such file or directory
No URLs found in -c.
FINISHED --2019-07-27 14:13:02--
Total wall clock time7.6s
Downloaded1 files25K in 0.1s (213 KB/s)

2.使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@VM_0_6_centos ~]yum -y install mysql57-community-release-el7-10.noarch.rpm
Loaded pluginsfastestmirrorlangpacks
Examining mysql57-community-release-el7-10.noarch.rpmmysql57-community-release-el7-10.noarch
Marking mysql57-community-release-el7-10.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-10 will be installed
--> Finished Dependency Resolution
epel/7/x86_64                                                                                        | 5.3 kB  00:00:00     
epel/7/x86_64/group_gz                                                                               |  88 kB  00:00:00     
epel/7/x86_64/updateinfo                                                                             | 993 kB  00:00:00     
epel/7/x86_64/primary_db                                                                             | 6.8 MB  00:00:01     
extras/7/x86_64                                                                                      | 3.4 kB  00:00:00     
extras/7/x86_64/primary_db                                                                           | 205 kB  00:00:00     
os/7/x86_64                                                                                          | 3.6 kB  00:00:00     
os/7/x86_64/group_gz                                                                                 | 166 kB  00:00:00     
os/7/x86_64/primary_db                                                                               | 6.0 MB  00:00:00     
updates/7/x86_64                                                                                     | 3.4 kB  00:00:00     
updates/7/x86_64/primary_db                                                                          | 6.5 MB  00:00:00     
Dependencies Resolved
============================================================================================================================
 Package                            Arch            Version         Repository                                         Size
============================================================================================================================
Installing:
 mysql57-community-release          noarch          el7-10          /mysql57-community-release-el7-10.noarch           30 k
Transaction Summary
============================================================================================================================
Install  1 Package
Total size30 k
Installed size30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-10.noarch                                                                  1/1 
  Verifying  : mysql57-community-release-el7-10.noarch                                                                  1/1 
Installed:
  mysql57-community-release.noarch 0:el7-10                                                                                 
Complete!

3.开始安装MySQL服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
[root@VM_0_6_centos ~]yum -y install mysql-community-server
Loaded pluginsfastestmirrorlangpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.27-1.el7 will be installed
--> Processing Dependencymysql-community-common(x86-64) = 5.7.27-1.el7 for packagemysql-community-server-5.7.27-1.el7.x86_64
--> Processing Dependencymysql-community-client(x86-64) >= 5.7.9 for packagemysql-community-server-5.7.27-1.el7.x86_64
--> Processing Dependencylibnuma.so.1(libnuma_1.2)(64bit) for packagemysql-community-server-5.7.27-1.el7.x86_64
--> Processing Dependencylibnuma.so.1(libnuma_1.1)(64bit) for packagemysql-community-server-5.7.27-1.el7.x86_64
--> Processing Dependencylibnuma.so.1()(64bit) for packagemysql-community-server-5.7.27-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.27-1.el7 will be installed
--> Processing Dependencymysql-community-libs(x86-64) >= 5.7.9 for packagemysql-community-client-5.7.27-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.27-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 Dependencylibmysqlclient.so.18()(64bit) for package2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependencylibmysqlclient.so.18(libmysqlclient_18)(64bit) for package2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.27-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.27-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.27-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.27-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.27-1.el7                              mysql57
    -community                          165 M
Installing for dependencies:
 mysql-community-client                               x86_64                          5.7.27-1.el7                              mysql57
    -community                           24 M
 mysql-community-common                               x86_64                          5.7.27-1.el7                              mysql57
    -community                          275 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 size197 M
Total download size190 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.27-1.el7.x86_64.rpmHeader V3 DSA/SHA1 Signaturekey ID 5072e1f5
    : NOKEYMB  00:01:27 ETA 
Public key for mysql-community-client-5.7.27-1.el7.x86_64.rpm is not installed
(1/2)mysql-community-client-5.7.27-1.el7.x86_64
    .rpm                                                                                                     |  24 MB  00:00:25     
(2/2)mysql-community-server-5.7.27-1.el7.x86_64
    .rpm                                                                                                     | 165 MB  00:04:04     
----------------------------------------------------------------------------------------------------------------------------------------------------------------
    -----------------
Total                                                                                                                                            795 kB
    /s | 190 MB  00:04:04     
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>"
 Fingerprinta4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.27-1.el7
    .x86_64                                                                                                                    1/9 
  Installing : mysql-community-libs-5.7.27-1.el7
    .x86_64                                                                                                                      2/9 
  Installing : mysql-community-libs-compat-5.7.27-1.el7
    .x86_64                                                                                                               3/9 
  Installing : mysql-community-client-5.7.27-1.el7
    .x86_64                                                                                                                    4/9 
  Installing : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                  
                 5/9 
  Installing : mysql-community-server-5.7.27-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-libs-compat-5.7.27-1.el7
    .x86_64                                                                                                               1/9 
  Verifying  : mysql-community-common-5.7.27-1.el7
    .x86_64                                                                                                                    2/9 
  Verifying  : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                  
                 3/9 
  Verifying  : 2:postfix-2.10.1-7.el7.x86_64                                                                                                                    
                 4/9 
  Verifying  : mysql-community-server-5.7.27-1.el7
    .x86_64                                                                                                                    5/9 
  Verifying  : mysql-community-client-5.7.27-1.el7
    .x86_64                                                                                                                    6/9 
  Verifying  : mysql-community-libs-5.7.27-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.27-1.el7             mysql-community-libs-compat.x86_64 0:5.7.27-1.el7             mysql-community-server.x86_64 0:5.7.27-1
    .el7            
Dependency Installed:
  mysql-community-client.x86_64 0:5.7.27-1.el7                  mysql-community-common.x86_64 0:5.7.27-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!

4.启动MySQL服务

1
[root@VM_0_6_centos ~]systemctl start  mysqld.service

5.查看MySQL运行状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@VM_0_6_centos ~]systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loadedloaded (/usr/lib/systemd/system/mysqld.serviceenabledvendor presetdisabled)
   Activeactive (running) since Sat 2019-07-27 14:44:57 CST49s ago
     Docsman:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process25426 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exitedstatus=0/SUCCESS)
  Process25346 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exitedstatus=0/SUCCESS)
 Main PID25429 (mysqld)
   CGroup/system.slice/mysqld.service
           └─25429 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jul 27 14:44:51 VM_0_6_centos systemd[1]Starting MySQL Server...
Jul 27 14:44:57 VM_0_6_centos systemd[1]Started MySQL Server.

6.查看MySQL临时密码

1
2
[root@VM_0_6_centos ~]grep "password" /var/log/mysqld.log
2019-07-27T06:44:52.609948Z 1 [Note] A temporary password is generated for root@localhostLi32o6nZtd!8

7.登录MySQL数据库服务器修改密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@VM_0_6_centos ~]mysql -uroot -p
Enter password
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version5.7.27
Copyright (c) 20002019Oracle and/or its affiliatesAll rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliatesOther names may be trademarks of their respective
owners.
Type 'help;' or '\h' for helpType '\c' to clear the current input statement.
mysql> 

8.修改MySQL密码

1
2
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'QWERTYUIOP@123456';
Query OK0 rows affected (0.00 sec)

 9.设置MySQL可以远程连接

1
2
3
4
5
6
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'AiSiZhe@2019'
    -> ;
Query OK0 rows affected1 warning (0.00 sec)
mysql> flush privileges;
Query OK0 rows affected (0.00 sec)

10设置MySQL开机启动

1
2
[root@VM_0_6_centos ~]systemctl enable mysqld
[root@VM_0_6_centos ~]systemctl daemon-reload

 

 

全部评论

联系我们

025-66041049

在线咨询:点击这里给我发消息

邮件:face2obejct@gmail.com

工作时间:8:00-23:50

QR code