CentOS在线安装Mysql5.7

CentOS在线安装Mysql5.7

一、通过Yum命令安装

1.下载rpm安装源

官方地址:https://dev.mysql.com/downloads/repo/yum/

rpm文件地址:https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

1)通过wget命令下载文件

 
  1. [[email protected] ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

  2. --2018-01-08 16:57:46-- https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

  3. 正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11

  4. 正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。

  5. 已发出 HTTP 请求,正在等待回应... 302 Found

  6. 位置:https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [跟随至新的 URL]

  7. --2018-01-08 16:57:48-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm

  8. 正在解析主机 repo.mysql.com (repo.mysql.com)... 23.1.165.122

  9. 正在连接 repo.mysql.com (repo.mysql.com)|23.1.165.122|:443... 已连接。

  10. 已发出 HTTP 请求,正在等待回应... 200 OK

  11. 长度:25680 (25K) [application/x-redhat-package-manager]

  12. 正在保存至: “mysql57-community-release-el7-11.noarch.rpm”

  13.  
  14. 100%[==================================================================================================================================================================================================>] 25,680 --.-K/s 用时 0.1s

  15.  
  16. 2018-01-08 16:57:48 (232 KB/s) - 已保存 “mysql57-community-release-el7-11.noarch.rpm” [25680/25680])

  17.  
  18. [[email protected] ~]#

2.安装Mysql

 1)安装Mysql源文件

  yum localinstall -y mysql57-community-release-el7-11.noarch.rpm

 2)查看Mysql源是否安装成功

 
  1. [[email protected] ~]# yum repolist enabled | grep "mysql.*-community.*"

  2. mysql-connectors-community/x86_64 MySQL Connectors Community 42

  3. mysql-tools-community/x86_64 MySQL Tools Community 55

  4. mysql57-community/x86_64 MySQL 5.7 Community Server 227

  5. [[email protected] ~]#

 3)安装Mysql服务

 yum install -y mysql-community-server

 4)查看Mysql服务是否安装成功

 
  1. [[email protected] ~]# systemctl status mysqld

  2. ● mysqld.service - MySQL Server

  3. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

  4. Active: inactive (dead)

  5. Docs: man:mysqld(8)

  6. http://dev.mysql.com/doc/refman/en/using-systemd.html

  7. [[email protected] ~]#

3.启动Mysql

 systemctl start mysqld

4.修改root登录密码

 1)获取root默认密码(由于Mysql安全策略升级,安装完成后系统自动设置了一个随机密码)

 
  1. [[email protected] ~]# grep 'temporary password' /var/log/mysqld.log

  2. 2018-01-08T09:21:45.780623Z 1 [Note] A temporary password is generated for [email protected]: auw;Nj7J!j/J

  3. [[email protected] ~]#

 2)登录Mysql

 
  1. [[email protected] ~]# mysql -uroot -p

  2. Enter password:

  3. Welcome to the MySQL monitor. Commands end with ; or \g.

  4. Your MySQL connection id is 3

  5. Server version: 5.7.20

  6.  
  7. Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its

  10. affiliates. Other names may be trademarks of their respective

  11. owners.

  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  14.  
  15. mysql>

3)修改密码

  3.1)由于Mysql默认要求设置密码复杂度高(必须包含 大小写字母、数字、符号)

 
  1. mysql> alter user 'root'@'localhost' identified by '[email protected]';

  2. Query OK, 0 rows affected (0.00 sec)

  3.  
  4. mysql>

 3.2)关闭Mysql密码校验规则,允许设置简单密码

  3.2.1)退出mysql ,编辑etc/my.cnf数据库Mysql配置文件,在Mysql配置文件最后加入:validate_password = off

 
  1. [[email protected] ~]# vi /etc/my.cnf

  2. # For advice on how to change settings please see

  3. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

  4.  
  5. [mysqld]

  6. #

  7. # Remove leading # and set to the amount of RAM for the most important data

  8. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

  9. # innodb_buffer_pool_size = 128M

  10. #

  11. # Remove leading # to turn on a very important data integrity option: logging

  12. # changes to the binary log between backups.

  13. # log_bin

  14. #

  15. # Remove leading # to set options mainly useful for reporting servers.

  16. # The server defaults are faster for transactions and fast SELECTs.

  17. # Adjust sizes as needed, experiment to find the optimal values.

  18. # join_buffer_size = 128M

  19. # sort_buffer_size = 2M

  20. # read_rnd_buffer_size = 2M

  21. datadir=/var/lib/mysql

  22. socket=/var/lib/mysql/mysql.sock

  23.  
  24. # Disabling symbolic-links is recommended to prevent assorted security risks

  25. symbolic-links=0

  26.  
  27. log-error=/var/log/mysqld.log

  28. pid-file=/var/run/mysqld/mysqld.pid

  29.  
  30. validate_password = off

 3.2.2)重启Mysql服务生效

   systemctl restart mysqld

  4)重新登陆mysql,设置简单密码 :)

 
  1. mysql> alter user 'root'@'localhost' identified by 'root';

  2. Query OK, 0 rows affected (0.00 sec)

  3.  
  4. mysql>

5.配置远程用户登录

 
  1. mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

  2. Query OK, 0 rows affected, 1 warning (0.00 sec)

  3.  
  4. mysql>

6.设置开机启动

 systemctl enable mysqld

 systemctl daemon-reload

7. 在阿里云控制台设置防火墙规则

CentOS在线安装Mysql5.7