CentOS-7安装MySQL5.6

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010871004/article/details/82024479

首先,需要查看下系统中是否安装了MySQL

rpm -qa | grep mysql

对于新安装的系统通常都是没有安装mysql的,除了在安装系统的时候,勾选了mysql的选项,进行的安装。但是在CentOS7中,mysql默认安装的是Mariadb,这个数据库不是我们所需要的,所以应该卸载这个数据库。
使用命令rpm -e包名,包名可以包含版本号等信息,但是不可以有后缀.rpm。
然后我们需要通过wget来获取mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

下载好的文件,在当前的执行目录下面,在当前的目录下面执行

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

看到如下的信息,说明安装成功

Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]
[jiang@localhost ~]$ yum -qa | grep mysql
Command line error: no such option: -a
[jiang@localhost ~]$ rpm -qa | grep mysql
mysql-community-release-el7-5.noarch
[jiang@localhost ~]$ sudo yum install mysql-server
Loaded plugins: fastestmirror
mysql-connectors-community                                                                                                                      | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                           | 2.5 kB  00:00:00     
mysql56-community                                                                                                                               | 2.5 kB  00:00:00     
(1/3): mysql-tools-community/x86_64/primary_db                                                                                                  |  45 kB  00:00:00     
(2/3): mysql-connectors-community/x86_64/primary_db                                                                                             |  25 kB  00:00:00     
(3/3): mysql56-community/x86_64/primary_db                                                                                                      | 197 kB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.41-2.el7 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.41-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.41-2.el7 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
---> Package mysql-community-libs.x86_64 0:5.6.41-2.el7 will be obsoleting
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                         Arch                           Version                                Repository                                 Size
=======================================================================================================================================================================
Installing:
 mysql-community-libs                            x86_64                         5.6.41-2.el7                           mysql56-community                         2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                          x86_64                         5.6.41-2.el7                           mysql56-community                          59 M
Installing for dependencies:
 mysql-community-client                          x86_64                         5.6.41-2.el7                           mysql56-community                          19 M
 mysql-community-common                          x86_64                         5.6.41-2.el7                           mysql56-community                         257 k
 perl-Compress-Raw-Bzip2                         x86_64                         2.061-3.el7                            base                                       32 k
 perl-Compress-Raw-Zlib                          x86_64                         1:2.061-4.el7                          base                                       57 k
 perl-DBI                                        x86_64                         1.627-4.el7                            base                                      802 k
 perl-Data-Dumper                                x86_64                         2.145-3.el7                            base                                       47 k
 perl-IO-Compress                                noarch                         2.061-2.el7                            base                                      260 k
 perl-Net-Daemon                                 noarch                         0.48-5.el7                             base                                       51 k
 perl-PlRPC                                      noarch                         0.2020-14.el7                          base                                       36 k

Transaction Summary
=======================================================================================================================================================================
Install  2 Packages (+9 Dependent packages)

Total download size: 82 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.41-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY32 ETA 
Public key for mysql-community-common-5.6.41-2.el7.x86_64.rpm is not installed
(1/11): mysql-community-common-5.6.41-2.el7.x86_64.rpm                                                                                          | 257 kB  00:00:01     
(2/11): mysql-community-libs-5.6.41-2.el7.x86_64.rpm                                                                                            | 2.0 MB  00:00:15     
perl-DBI-1.627-4.el7.x86_64.rp FAILED                                                                                                ] 434 kB/s | 6.6 MB  00:02:58 ETA 
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/perl-DBI-1.627-4.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known"
Trying other mirror.
(3/11): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                                                                                          |  32 kB  00:00:00     
(4/11): perl-IO-Compress-2.061-2.el7.noarch.rpm                                                                                                 | 260 kB  00:00:00     
(5/11): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                                                                   |  51 kB  00:00:00     
(6/11): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                                                                     |  36 kB  00:00:00     
(7/11): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                                                                 |  47 kB  00:00:02     
(8/11): perl-DBI-1.627-4.el7.x86_64.rpm                                                                                                         | 802 kB  00:00:02     
perl-Compress-Raw-Zlib-2.061-4 FAILED                                          ===-                                                  ] 206 kB/s |  12 MB  00:05:49 ETA 
http://mirrors.aliyuncs.com/centos/7/os/x86_64/Packages/perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
(9/11): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                                                                                           |  57 kB  00:00:00     
(10/11): mysql-community-client-5.6.41-2.el7.x86_64.rpm                                                                                         |  19 MB  00:02:04     
(11/11): mysql-community-server-5.6.41-2.el7.x86_64.rpm                                                                                         |  59 MB  00:19:17     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   72 kB/s |  82 MB  00:19:35     
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql-community-release-el7-5.noarch (installed)
 From       : file:/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
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-5.6.41-2.el7.x86_64                                                                                                         1/12 
  Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                2/12 
  Installing : mysql-community-libs-5.6.41-2.el7.x86_64                                                                                                           3/12 
  Installing : mysql-community-client-5.6.41-2.el7.x86_64                                                                                                         4/12 
  Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                                                                         5/12 
  Installing : perl-Net-Daemon-0.48-5.el7.noarch                                                                                                                  6/12 
  Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                                                                        7/12 
  Installing : perl-IO-Compress-2.061-2.el7.noarch                                                                                                                8/12 
  Installing : perl-PlRPC-0.2020-14.el7.noarch                                                                                                                    9/12 
  Installing : perl-DBI-1.627-4.el7.x86_64                                                                                                                       10/12 
  Installing : mysql-community-server-5.6.41-2.el7.x86_64                                                                                                        11/12 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                12/12 
  Verifying  : mysql-community-server-5.6.41-2.el7.x86_64                                                                                                         1/12 
  Verifying  : mysql-community-client-5.6.41-2.el7.x86_64                                                                                                         2/12 
  Verifying  : mysql-community-libs-5.6.41-2.el7.x86_64                                                                                                           3/12 
  Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                4/12 
  Verifying  : mysql-community-common-5.6.41-2.el7.x86_64                                                                                                         5/12 
  Verifying  : perl-IO-Compress-2.061-2.el7.noarch                                                                                                                6/12 
  Verifying  : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                                                                        7/12 
  Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                                                                                                                  8/12 
  Verifying  : perl-DBI-1.627-4.el7.x86_64                                                                                                                        9/12 
  Verifying  : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                                                                        10/12 
  Verifying  : perl-PlRPC-0.2020-14.el7.noarch                                                                                                                   11/12 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                12/12 

Installed:
  mysql-community-libs.x86_64 0:5.6.41-2.el7                                        mysql-community-server.x86_64 0:5.6.41-2.el7                                       

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.41-2.el7           mysql-community-common.x86_64 0:5.6.41-2.el7           perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7          
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7            perl-DBI.x86_64 0:1.627-4.el7                          perl-Data-Dumper.x86_64 0:2.145-3.el7                 
  perl-IO-Compress.noarch 0:2.061-2.el7                  perl-Net-Daemon.noarch 0:0.48-5.el7                    perl-PlRPC.noarch 0:0.2020-14.el7                     

Replaced:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                                                   

Complete!

然后通过执行

mysql -uroot

登录mysql数据库,可能会爆出来这个问题

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

这个是因为当前的用户没有在这个目录下执行的权限,我们给当前用户给个权限

sudo chown -R jiang:jiang /var/lib/mysql

服务器重启

sudo systemctl restart mysql.service

如果需要远程登录的话,我们还需要防火前开了3306的端口号

sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent

执行完后,需要重新加载防火墙

sudo firewall-cmd --reload

然后进入数据库中,给root用户,配置个密码

use mysql;
update user set password=password('123456') where user='root';

然后,给root用户,赋上远程登录的权限,登录需要用密码123456来识别。

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";

最终,mysql数据安装完毕。

猜你喜欢

转载自blog.csdn.net/u010871004/article/details/82024479