目标:
记录Centos 下安装 Oracle版本的MySQL
步骤:
系统信息
[root@cacheserver1 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@cacheserver1 ~]# uname -a
Linux cache1 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
下载 MySQL Yum Repository
访问 https://dev.mysql.com/downloads/repo/yum/ 找到系统对象的 rpm包
下载 Red Hat Enterprise Linux 7
https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@cacheserver1 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
--2020-12-31 10:24:03-- https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [跟随至新的 URL]
--2020-12-31 10:24:05-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 96.17.188.242
正在连接 repo.mysql.com (repo.mysql.com)|96.17.188.242|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:26024 (25K) [application/x-redhat-package-manager]
正在保存至: “mysql80-community-release-el7-3.noarch.rpm”
100%[===========================================================================================================================================================>] 26,024 141KB/s 用时 0.2s
2020-12-31 10:24:07 (141 KB/s) - 已保存 “mysql80-community-release-el7-3.noarch.rpm” [26024/26024])
安装MySQL Yum Repository
[root@cacheserver1 ~]# rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
警告:mysql80-community-release-el7-3.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql80-community-release-el7-3 ################################# [100%]
查询 mysql-community-server 是否已经可用
[root@cacheserver1 ~]# yum info mysql-community-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
可安装的软件包
名称 :mysql-community-server
架构 :x86_64
版本 :8.0.22
发布 :1.el7
大小 :510 M
源 :mysql80-community/x86_64
简介 : A very fast and reliable SQL database server
网址 :http://www.mysql.com/
协议 : Copyright (c) 2000, 2020, Oracle and/or its affiliates. Under GPLv2 license as shown in the Description field.
描述 : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
: and robust SQL (Structured Query Language) database server. MySQL Server
: is intended for mission-critical, heavy-load production systems as well
: as for embedding into mass-deployed software. MySQL is a trademark of
: Oracle and/or its affiliates
:
: The MySQL software has Dual Licensing, which means you can use the MySQL
: software free of charge under the GNU General Public License
: (http://www.gnu.org/licenses/). You can also purchase commercial MySQL
: licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
: the GPL. See the chapter "Licensing and Support" in the manual for
: further info.
:
: The MySQL web site (http://www.mysql.com/) provides the latest news and
: information about the MySQL software. Also please see the documentation
: and the manual for more information.
:
: This package includes the MySQL server binary as well as related utilities
: to run and administer a MySQL server.
安装MySQL
从官网下载资源,需要时间,等待…
[root@cacheserver1 ~]# yum install mysql-community-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.8.0.22-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.22-1.el7,它被软件包 mysql-community-server-8.0.22-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.11,它被软件包 mysql-community-server-8.0.22-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mariadb.x86_64.1.5.5.68-1.el7 将被 取代
---> 软件包 mysql-community-client.x86_64.0.8.0.22-1.el7 将被 舍弃
--> 正在处理依赖关系 mysql-community-client-plugins = 8.0.22-1.el7,它被软件包 mysql-community-client-8.0.22-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.11,它被软件包 mysql-community-client-8.0.22-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.8.0.22-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-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-client-plugins.x86_64.0.8.0.22-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.8.0.22-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.22-1.el7 将被 舍弃
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================================================================================
正在安装:
mysql-community-client x86_64 8.0.22-1.el7 mysql80-community 48 M
替换 mariadb.x86_64 1:5.5.68-1.el7
mysql-community-libs x86_64 8.0.22-1.el7 mysql80-community 4.6 M
替换 mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 8.0.22-1.el7 mysql80-community 1.2 M
替换 mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 8.0.22-1.el7 mysql80-community 510 M
为依赖而安装:
mysql-community-client-plugins x86_64 8.0.22-1.el7 mysql80-community 235 k
mysql-community-common x86_64 8.0.22-1.el7 mysql80-community 616 k
事务概要
=====================================================================================================================================================================================================
安装 4 软件包 (+2 依赖软件包)
总下载量:564 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY ] 158 kB/s | 169 kB 01:01:00 ETA
mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm 的公钥尚未安装
(1/6): mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm | 235 kB 00:00:01
(2/6): mysql-community-common-8.0.22-1.el7.x86_64.rpm | 616 kB 00:00:00
(3/6): mysql-community-libs-8.0.22-1.el7.x86_64.rpm | 4.6 MB 00:00:01
(4/6): mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm | 1.2 MB 00:00:01
(5/6): mysql-community-client-8.0.22-1.el7.x86_64.rpm | 48 MB 00:00:17
(6/6): mysql-community-server-8.0.22-1.el7.x86_64.rpm | 510 MB 00:02:36
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 3.5 MB/s | 564 MB 00:02:42
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指纹 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
软件包 : mysql80-community-release-el7-3.noarch (installed)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : mysql-community-common-8.0.22-1.el7.x86_64 1/8
正在安装 : mysql-community-client-plugins-8.0.22-1.el7.x86_64 2/8
正在安装 : mysql-community-libs-8.0.22-1.el7.x86_64 3/8
正在安装 : mysql-community-client-8.0.22-1.el7.x86_64 4/8
正在安装 : mysql-community-server-8.0.22-1.el7.x86_64 5/8
正在安装 : mysql-community-libs-compat-8.0.22-1.el7.x86_64 6/8
正在删除 : 1:mariadb-5.5.68-1.el7.x86_64 7/8
正在删除 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
验证中 : mysql-community-libs-8.0.22-1.el7.x86_64 1/8
验证中 : mysql-community-server-8.0.22-1.el7.x86_64 2/8
验证中 : mysql-community-client-plugins-8.0.22-1.el7.x86_64 3/8
验证中 : mysql-community-common-8.0.22-1.el7.x86_64 4/8
验证中 : mysql-community-client-8.0.22-1.el7.x86_64 5/8
验证中 : mysql-community-libs-compat-8.0.22-1.el7.x86_64 6/8
验证中 : 1:mariadb-libs-5.5.68-1.el7.x86_64 7/8
验证中 : 1:mariadb-5.5.68-1.el7.x86_64 8/8
已安装:
mysql-community-client.x86_64 0:8.0.22-1.el7 mysql-community-libs.x86_64 0:8.0.22-1.el7 mysql-community-libs-compat.x86_64 0:8.0.22-1.el7 mysql-community-server.x86_64 0:8.0.22-1.el7
作为依赖被安装:
mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 mysql-community-common.x86_64 0:8.0.22-1.el7
替代:
mariadb.x86_64 1:5.5.68-1.el7 mariadb-libs.x86_64 1:5.5.68-1.el7
完毕!
配置 MySQL服务
查询服务状态
[root@cacheserver1 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Active显示 inactive,未启动
配置为随机启动
[root@cacheserver1 ~]# systemctl enable mysqld
禁用随机启动 systemctl disable mysqld
启动服务和再次查询状态
[root@cacheserver1 ~]# systemctl start mysqld
[root@cacheserver1 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2020-12-30 01:03:20 CST; 1 day 14h ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 4131 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─4131 /usr/sbin/mysqld
12月 30 01:03:15 root@cacheserver1 systemd[1]: Starting MySQL Server...
12月 30 01:03:20 root@cacheserver1 systemd[1]: Started MySQL Server.
Active显示已启动
停止服务器使用 systemctl stop mysql
查看初始密码
在日志文件中查看初始密码
[root@cacheserver1 ~]# grep "password" /var/log/mysqld.log
2020-12-29T17:03:17.790047Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ULP2ataN>ftx
修改密码及添加用户
在本地使用mysql登录服务器,使用上面的密码
[root@cache2 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 8.0.22 MySQL Community Server - GPL
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>
修改新密码,替换下面的“new password”,密码有复杂度要求
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
修改密码复杂度
set global validate_password_policy=LOW;
开启远程访问,
1) 创建用户 2)授权权限
不限定主机可用%代替IP地址
CREATE USER 'root'@'192.168.0.1' IDENTIFIED with mysql_native_password BY 'password';
grant all privileges on *.* to 'root'@'192.168.0.1';
如果客户端连接不上,则增加 with mysql_native_password ,使用老密码加密即可
alter user 'root'@'%' identified with mysql_native_password by 'password';
mysql8.0 引入了新特性 caching_sha2_password;这种密码加密方式客户端不支持;
刷新权限,使权限生效
mysql> flush privileges;
其他版本系统 请看官方的 Quick Guide https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/