环境:
CENTOS 7.8
一.安装步骤
安装前准备
cd /etc/yum.repos.d
/**下载mysql源安装包 */
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
/** 安装mysql源*/
yum localinstall mysql57-community-release-el7-8.noarch.rpm
/**以上两步都是必须的,以下就是检测源是否安装成功*/
yum repolist enabled | grep "mysql.*-community.*" //成功后结果如下图
运行记录
[root@10-31-1-119 yum.repos.d]# cd /etc/yum.repos.d
[root@10-31-1-119 yum.repos.d]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2020-08-20 11:35:12-- http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm [跟随至新的 URL]
--2020-08-20 11:35:12-- https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [跟随至新的 URL]
--2020-08-20 11:35:16-- https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.211.97.88
正在连接 repo.mysql.com (repo.mysql.com)|23.211.97.88|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9116 (8.9K) [application/x-redhat-package-manager]
正在保存至: “mysql57-community-release-el7-8.noarch.rpm”
100%[==================================================================================================================================================================>] 9,116 --.-K/s 用时 0s
2020-08-20 11:35:18 (64.4 MB/s) - 已保存 “mysql57-community-release-el7-8.noarch.rpm” [9116/9116])
[root@10-31-1-119 yum.repos.d]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
已加载插件:fastestmirror, langpacks
正在检查 mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
mysql57-community-release-el7-8.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql57-community-release.noarch.0.el7-8 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================================================================
正在安装:
mysql57-community-release noarch el7-8 /mysql57-community-release-el7-8.noarch 8.2 k
事务概要
============================================================================================================================================================================================================
安装 1 软件包
总计:8.2 k
安装大小:8.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql57-community-release-el7-8.noarch 1/1
验证中 : mysql57-community-release-el7-8.noarch 1/1
已安装:
mysql57-community-release.noarch 0:el7-8
完毕!
[root@10-31-1-119 yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 165
mysql-tools-community/x86_64 MySQL Tools Community 115
mysql57-community/x86_64 MySQL 5.7 Community Server 444
[root@10-31-1-119 yum.repos.d]#
开始安装
yum install mysql-community-server //安装mysql服务,此处看网速有快有慢
systemctl start mysqld //安装后,启动mysql服务
systemctl status mysqld //查看mysqld服务,此处要是查看到activity状态是running那就表明已经
//安装成功了
systemctl enable mysqld //设置开机启动
systemctl daemon-reload //重载服务
//mysql5.7安装时会产生一个默认的密码,查看此密码的文件一般存在于/var/log/mysqld.log上
grep 'temporary password' /var/log/mysqld.log //查看密码
运行记录
[root@10-31-1-119 yum.repos.d]# yum install mysql-community-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.31-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.31-1.el7,它被软件包 mysql-community-server-5.7.31-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.31-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.31-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.31-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.7.31-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.65-1.el7 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
---> 软件包 mysql-community-libs.x86_64.0.5.7.31-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.31-1.el7 将被 舍弃
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================================================================
正在安装:
mysql-community-libs x86_64 5.7.31-1.el7 mysql57-community 2.3 M
替换 mariadb-libs.x86_64 1:5.5.65-1.el7
mysql-community-libs-compat x86_64 5.7.31-1.el7 mysql57-community 1.2 M
替换 mariadb-libs.x86_64 1:5.5.65-1.el7
mysql-community-server x86_64 5.7.31-1.el7 mysql57-community 173 M
为依赖而安装:
mysql-community-client x86_64 5.7.31-1.el7 mysql57-community 25 M
mysql-community-common x86_64 5.7.31-1.el7 mysql57-community 311 k
事务概要
============================================================================================================================================================================================================
安装 3 软件包 (+2 依赖软件包)
总下载量:202 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY ] 96 kB/s | 521 kB 00:36:00 ETA
mysql-community-common-5.7.31-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mysql-community-common-5.7.31-1.el7.x86_64.rpm | 311 kB 00:00:03
(2/5): mysql-community-libs-5.7.31-1.el7.x86_64.rpm | 2.3 MB 00:00:06
(3/5): mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm | 1.2 MB 00:00:02
(4/5): mysql-community-client-5.7.31-1.el7.x86_64.rpm | 25 MB 00:00:34
(5/5): mysql-community-server-5.7.31-1.el7.x86_64.rpm | 173 MB 00:02:35
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 1.2 MB/s | 202 MB 00:02:47
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
用户ID : "MySQL Release Engineering "
指纹 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
软件包 : mysql57-community-release-el7-8.noarch (@/mysql57-community-release-el7-8.noarch)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-common-5.7.31-1.el7.x86_64 1/6
正在安装 : mysql-community-libs-5.7.31-1.el7.x86_64 2/6
正在安装 : mysql-community-client-5.7.31-1.el7.x86_64 3/6
正在安装 : mysql-community-server-5.7.31-1.el7.x86_64 4/6
正在安装 : mysql-community-libs-compat-5.7.31-1.el7.x86_64 5/6
正在删除 : 1:mariadb-libs-5.5.65-1.el7.x86_64 6/6
验证中 : mysql-community-libs-compat-5.7.31-1.el7.x86_64 1/6
验证中 : mysql-community-common-5.7.31-1.el7.x86_64 2/6
验证中 : mysql-community-server-5.7.31-1.el7.x86_64 3/6
验证中 : mysql-community-client-5.7.31-1.el7.x86_64 4/6
验证中 : mysql-community-libs-5.7.31-1.el7.x86_64 5/6
验证中 : 1:mariadb-libs-5.5.65-1.el7.x86_64 6/6
已安装:
mysql-community-libs.x86_64 0:5.7.31-1.el7 mysql-community-libs-compat.x86_64 0:5.7.31-1.el7 mysql-community-server.x86_64 0:5.7.31-1.el7
作为依赖被安装:
mysql-community-client.x86_64 0:5.7.31-1.el7 mysql-community-common.x86_64 0:5.7.31-1.el7
替代:
mariadb-libs.x86_64 1:5.5.65-1.el7
完毕!
[root@10-31-1-119 yum.repos.d]# systemctl start mysqld
[root@10-31-1-119 yum.repos.d]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2020-08-20 11:43:10 CST; 8s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4326 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4263 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4329 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─4329 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
8月 20 11:43:05 10-31-1-119 systemd[1]: Starting MySQL Server...
8月 20 11:43:10 10-31-1-119 systemd[1]: Started MySQL Server.
[root@10-31-1-119 yum.repos.d]# systemctl enable mysqld
[root@10-31-1-119 yum.repos.d]# systemctl daemon-reload
[root@10-31-1-119 yum.repos.d]#
[root@10-31-1-119 yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2020-08-20T03:43:08.233767Z 1 [Note] A temporary password is generated for root@localhost: *r>CfBm#P2fn
[root@10-31-1-119 yum.repos.d]#
修改密码
-- 登陆mysql 密码上一步的密码
mysql -uroot -p
set password for 'root'@'localhost'=password('Abc123456!');
flush privileges;
exit
--重启mysql服务
systemctl restart mysqld
运行记录
[root@10-31-1-119 yum.repos.d]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31
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> set password for 'root'@'localhost'=password('Abc123!');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>
mysql>
mysql> set password for 'root'@'localhost'=password('Abc123456!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@10-31-1-119 yum.repos.d]# systemctl restart mysqld
如果是测试环境,可以要求简单的密码
set global validate_password_policy=0;
set global validate_password_length=6;
set password for 'root'@'localhost'=password('abc123');
-- 重启mysql服务
systemctl restart mysqld
参考文献: