ins-vue

Centos7 安装mysql5.7 (基于阿里云)

2018-08-27  本文已影响1人  youins

1. 前言

CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用MariaDB代替了,MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

2. 卸载MariaDB

2.1 检查MariaDB是否安装

yum list installed | grep mariadb

如果存在这个数据库的安装包,那么我们选择全部卸载掉!

2.2 卸载MariaDB数据库

 yum -y remove mariadb*

卸载输出日志如下:

[root@IMUKL ~]# yum -y remove mariadb*
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: php-mysql-                                           5.4.16-45.el7.x86_64
--> 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 pa                                           ckage: php-mysql-5.4.16-45.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for pa                                           ckage: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package php-mysql.x86_64 0:5.4.16-45.el7 will be erased
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.1-2                                           7.el7.centos.1.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch        Version                  Repository      Size
================================================================================
Removing:
 mariadb-libs         x86_64      1:5.5.56-2.el7           @anaconda      4.4 M
Removing for dependencies:
 php-mysql            x86_64      5.4.16-45.el7            @base          232 k
 postfix              x86_64      2:2.10.1-6.el7           @anaconda       12 M
 redhat-lsb-core      x86_64      4.1-27.el7.centos.1      @base           45 k

Transaction Summary
================================================================================
Remove  1 Package (+3 Dependent packages)

Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : redhat-lsb-core-4.1-27.el7.centos.1.x86_64                   1/4
  Erasing    : php-mysql-5.4.16-45.el7.x86_64                               2/4
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                3/4
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                           4/4
  Verifying  : php-mysql-5.4.16-45.el7.x86_64                               1/4
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                           2/4
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                3/4
  Verifying  : redhat-lsb-core-4.1-27.el7.centos.1.x86_64                   4/4

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

Dependency Removed:
  php-mysql.x86_64 0:5.4.16-45.el7               postfix.x86_64 2:2.10.1-6.el7
  redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1

Complete!

3. 安装mysql

3.1 下载mysql安装包

wget -P /home/install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

这样将mysql安装包下载到/home/install目录

3.2 执行mysql安装包

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

3.3 检查mysql的YUM源是否安装成功

yum repolist enabled | grep "mysql.*-community.*" 

3.4 查看mysql版本

yum repolist all | grep mysql

可以看到 5.5, 5.6,8.0 版本是默认禁用的.

3.5 查看当前的启用的 MySQL 版本

yum repolist enabled | grep mysql

3.6 安装MySQL

  yum install mysql-community-server -y

4. 验证mysql

4.1 启动mysql

systemctl start mysqld

4.2 查看mysql状态

systemctl status mysqld

4.3 登陆mysql

mysql -u root -p

mysql会提示输入密码,但是此时您并不知道密码是多少,可以执行如下命令,查看初始密码.

grep 'temporary password' /var/log/mysqld.log

查询内容如下:

2018-08-27T06:25:51.999521Z 1 [Note] A temporary password is generated for root@localhost: <JJq*=Dg-1w%

然后'<JJq*=Dg-1w%'即为root初始密码.

4.4 设置root账户密码

经过4.3的步骤,我们成功登陆了mysql,下一步可以对root账户的密码进行重新设置。

SET PASSWORD = PASSWORD('root账户密码');

这行,报如下问题,原来mysql在5.7这个版本中,加入了验证密码这个机制。必须是大小写+数字+特殊符号 。

4.5 允许以root账户以任意ip登陆mysql

以root账户重新登陆mysql,并执行如下两条命令

// 允许任意ip以root账户访问mysql
grant all privileges on *.* to root@'%'  identified by 'root账户的密码;
// 立即生效
flush privileges;

4.6 配置阿里云端口开放规则

开通3306端口!

上一篇下一篇

猜你喜欢

热点阅读