Centos Yum 安装 Mysql 5.7

Centos 6 / 7 官方源安装Mysql 5.7

1 检查当前系统是否有旧版本

# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64

#  rpm -qa | grep MySQL

1.1 如有旧版本可以删除

# rpm -e  mysql-libs-5.1.71-1.el6.x86_64  --nodeps

2 下载MySQL官方 Yum Repository

根据系统下载6或7

(6) wget -i http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
(7) wget -i  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

如果发现证书错误需要添加参数:

wget --no-check-certificate  http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

3 安装和确认仓库内容

3.1 安装

# rpm -ivh mysql57-community-release-el6-7.noarch.rpm

3.2 检查有效仓库

# yum repolist enabled
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                           repo name                                          status
base                                              CentOS-6 - Base                                    6,713
extras                                            CentOS-6 - Extras                                        47
mysql-connectors-community         MySQL Connectors Community                 129
mysql-tools-community                  MySQL Tools Community                              90
mysql57-community                       MySQL 5.7 Community Server                    396
updates                                         CentOS-6 - Updates                                 1,046
repolist: 8,421

3.3 查询安装版本

# yum list mysql-community*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
mysql-community-client.i686                          5.7.30-1.el6                mysql57-community         
mysql-community-client.x86_64                        5.7.30-1.el6                mysql57-community         
mysql-community-common.i686                          5.7.30-1.el6                mysql57-community         
mysql-community-common.x86_64                        5.7.30-1.el6                mysql57-community         
mysql-community-devel.i686                           5.7.30-1.el6                mysql57-community         
mysql-community-devel.x86_64                         5.7.30-1.el6                mysql57-community         
mysql-community-embedded.i686                        5.7.30-1.el6                mysql57-community         
mysql-community-embedded.x86_64                      5.7.30-1.el6                mysql57-community         
mysql-community-embedded-devel.i686                  5.7.30-1.el6                mysql57-community         
mysql-community-embedded-devel.x86_64                5.7.30-1.el6                mysql57-community         
mysql-community-libs.i686                            5.7.30-1.el6                mysql57-community         
mysql-community-libs.x86_64                          5.7.30-1.el6                mysql57-community         
mysql-community-libs-compat.i686                     5.7.30-1.el6                mysql57-community         
mysql-community-libs-compat.x86_64                   5.7.30-1.el6                mysql57-community         
mysql-community-release.noarch                       el6-5                       mysql-connectors-community
mysql-community-server.x86_64                        5.7.30-1.el6                mysql57-community         
mysql-community-test.x86_64                          5.7.30-1.el6                mysql57-community 

 

4 安装

# yum install mysql-server
Dependencies Resolved
===========================================================================================================
 Package                         Arch            Version                  Repository                  Size
===========================================================================================================
Installing:
 mysql-community-server          x86_64          5.7.30-1.el6             mysql57-community          162 M
Installing for dependencies:
 mysql-community-client            x86_64          5.7.30-1.el6             mysql57-community           25 M
 mysql-community-common          x86_64          5.7.30-1.el6             mysql57-community          370 k
 mysql-community-libs             x86_64          5.7.30-1.el6             mysql57-community          2.4 M
 numactl                             x86_64           2.0.9-2.el6               base                             74 k

Transaction Summary
===========================================================================================================
Install       5 Package(s)

Total download size: 189 M
Installed size: 905 M
Is this ok [y/N]:

5 数据库初始化

5.1 启动mysql 服务

# service mysqld start
Initializing MySQL database:       [  OK  ]
Starting mysqld:                          [  OK  ]

5.2 查看初始密码

# grep password /var/log/mysqld.log
 [Note] A temporary password is generated for root@localhost: l#.&dX3Hgade
 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)

5.3 登录

# mysql -u root -pl#.&dX3Hgade

Server version: 5.7.30
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

5.4 更改初始密码(必须更改初始密码,默认策略大小写数字加特殊字符)

mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statemen

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password-8888';

5.5 确认和修改密码策略

mysql> show variables like '%password%';

 # vi /etc/my.cnf
添加 validate_password_policy配置
选择 0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件

# 添加validate_password_policy配置
validate_password_policy=0
# 关闭密码策略
validate_password = off

修改后重启服务

 5.6 添加远程管理权限

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

mysql > flush privileges;

 

posted @ 2020-06-22 17:11  tamatama  阅读(310)  评论(0编辑  收藏  举报
GO TOP