使用yum源的方式, 在centos8上安装MySQL8.0的社区版
步骤如下
1 添加MySQL的yum源到仓库
mysql yum源的下载地址: https://dev.mysql.com/downloads/repo/yum/
根据操作系统版本, 选择对应的yum源:
[root@centos-8-server01 ~]# mkdir -p /app
[root@centos-8-server01 ~]# cd /app/
[root@centos-8-server01 app]# ls
[root@centos-8-server01 app]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
--2020-03-31 13:22:05-- https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 104.70.237.54
正在连接 repo.mysql.com (repo.mysql.com)|104.70.237.54|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:30388 (30K) [application/x-redhat-package-manager]
正在保存至: “mysql80-community-release-el8-1.noarch.rpm”
mysql80-community-release-el8-1.noarch. 100%[============================================================================>] 29.68K 115KB/s 用时 0.3s
2020-03-31 13:22:07 (115 KB/s) - 已保存 “mysql80-community-release-el8-1.noarch.rpm” [30388/30388])
[root@centos-8-server01 app]#
[root@centos-8-server01 app]#
[root@centos-8-server01 app]# ls -lltr
总用量 32
-rw-r--r--. 1 root root 30388 10月 4 15:31 mysql80-community-release-el8-1.noarch.rpm
[root@centos-8-server01 app]# yum localinstall mysql80-community-release-el8-1.noarch.rpm
上次元数据过期检查:0:14:01 前,执行于 2020年03月31日 星期二 13时08分15秒。
依赖关系解决。
=============================================================================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================================================================
安装:
mysql80-community-release noarch el8-1 @commandline 30 k
事务概要
=============================================================================================================================================================
安装 1 软件包
总计:30 k
安装大小:29 k
确定吗?[y/N]: y
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : mysql80-community-release-el8-1.noarch 1/1
验证 : mysql80-community-release-el8-1.noarch 1/1
已安装:
mysql80-community-release-el8-1.noarch
完毕!
验证mysql yum源是否加入到仓库:
[root@centos-8-server01 app]# yum repolist enabled | grep "mysql.*-community.*"
CentOS-8 - AppStream 8.9 kB/s | 4.3 kB 00:00
CentOS-8 - Base 6.7 kB/s | 3.8 kB 00:00
CentOS-8 - Extras 3.4 kB/s | 1.5 kB 00:00
MySQL 8.0 Community Server 151 kB/s | 543 kB 00:03
MySQL Connectors Community 13 kB/s | 19 kB 00:01
MySQL Tools Community 29 kB/s | 62 kB 00:02
mysql-connectors-community MySQL Connectors Community 42
mysql-tools-community MySQL Tools Community 19
mysql80-community MySQL 8.0 Community Server 31
2 选择一个发行版本
使用mysql yum源,默认安装MySQL 8.0。
3 禁用默认的MySQL模块(module)
redhat 8 /centos 8 都是默认带mysql组件的,需要禁用。
[root@centos-8-server01 app]# yum module disable mysql
上次元数据过期检查:0:04:19 前,执行于 2020年03月31日 星期二 13时23分39秒。
依赖关系解决。
=============================================================================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================================================================
禁用模块:
mysql
事务概要
=============================================================================================================================================================
确定吗?[y/N]: y
完毕!
4 安装mysql
[root@centos-8-server01 app]# yum install mysql-community-server
上次元数据过期检查:0:05:45 前,执行于 2020年03月31日 星期二 13时23分39秒。
依赖关系解决。
=============================================================================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================================================================
安装:
mysql-community-server x86_64 8.0.19-1.el8 mysql80-community 53 M
安装依赖关系:
mysql-community-client x86_64 8.0.19-1.el8 mysql80-community 12 M
mysql-community-common x86_64 8.0.19-1.el8 mysql80-community 609 k
mysql-community-libs x86_64 8.0.19-1.el8 mysql80-community 1.4 M
事务概要
=============================================================================================================================================================
安装 4 软件包
总下载:67 M
安装大小:383 M
确定吗?[y/N]: y
下载软件包:
(1/4): mysql-community-common-8.0.19-1.el8.x86_64.rpm 198 kB/s | 609 kB 00:03
(2/4): mysql-community-libs-8.0.19-1.el8.x86_64.rpm 394 kB/s | 1.4 MB 00:03
(3/4): mysql-community-client-8.0.19-1.el8.x86_64.rpm 1.1 MB/s | 12 MB 00:10
(4/4): mysql-community-server-8.0.19-1.el8.x86_64.rpm 783 kB/s | 53 MB 01:09
-------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 950 kB/s | 67 MB 01:12
警告:/var/cache/dnf/mysql80-community-b1f1ed5ba88ce0f8/packages/mysql-community-client-8.0.19-1.el8.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
MySQL 8.0 Community Server 27 MB/s | 27 kB 00:00
导入 GPG 公钥 0x5072E1F5:
Userid: "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指纹: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
确定吗?[y/N]: y
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : mysql-community-common-8.0.19-1.el8.x86_64 1/4
安装 : mysql-community-libs-8.0.19-1.el8.x86_64 2/4
运行脚本: mysql-community-libs-8.0.19-1.el8.x86_64 2/4
安装 : mysql-community-client-8.0.19-1.el8.x86_64 3/4
运行脚本: mysql-community-server-8.0.19-1.el8.x86_64 4/4
安装 : mysql-community-server-8.0.19-1.el8.x86_64 4/4
运行脚本: mysql-community-server-8.0.19-1.el8.x86_64 4/4
验证 : mysql-community-client-8.0.19-1.el8.x86_64 1/4
验证 : mysql-community-common-8.0.19-1.el8.x86_64 2/4
验证 : mysql-community-libs-8.0.19-1.el8.x86_64 3/4
验证 : mysql-community-server-8.0.19-1.el8.x86_64 4/4
已安装:
mysql-community-server-8.0.19-1.el8.x86_64 mysql-community-client-8.0.19-1.el8.x86_64 mysql-community-common-8.0.19-1.el8.x86_64
mysql-community-libs-8.0.19-1.el8.x86_64
完毕!
5 启动mysql
[root@centos-8-server01 app]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@centos-8-server01 app]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-03-31 13:32:15 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 30714 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 30794 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 9049)
Memory: 479.0M
CGroup: /system.slice/mysqld.service
└─30794 /usr/sbin/mysqld
3月 31 13:32:08 centos-8-server01 systemd[1]: Starting MySQL Server...
3月 31 13:32:15 centos-8-server01 systemd[1]: Started MySQL Server.
在首次启动mysql的是时候, 会进行数据的初始化 , 并会有一个默认的超级账户root@localhost, 通过以下方式查看口令:
[root@centos-8-server01 app]# grep 'temporary password' /var/log/mysqld.log
2020-03-31T05:32:12.523374Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: C)nmM-wmK2r.
在部署完毕后, 需要尽快修改其口令:
[root@centos-8-server01 app]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Query OK, 0 rows affected (0.02 sec)
mysql>
6 初始化数据目录
这一步已经做完, 因为只有使用源代码安装、或者使用zip解压缩的方式安装的才需要进行数据目录初始化。
7 进行测试
查看版本
[root@centos-8-server01 app]# mysqladmin -uroot -pMyNewPass4! version
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin Ver 8.0.19 for Linux on x86_64 (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.
Server version 8.0.19
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 9 min 15 sec
Threads: 2 Questions: 15 Slow queries: 0 Opens: 147 Flush tables: 3 Open tables: 64 Queries per second avg: 0.027
[root@centos-8-server01 app]#
验证关闭、启动server
[root@centos-8-server01 app]# mysqladmin -uroot -pMyNewPass4! shutdown
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@centos-8-server01 app]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2020-03-31 13:43:24 CST; 16s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 30794 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 30714 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 30794 (code=exited, status=0/SUCCESS)
Status: "Server shutdown complete"
3月 31 13:32:08 centos-8-server01 systemd[1]: Starting MySQL Server...
3月 31 13:32:15 centos-8-server01 systemd[1]: Started MySQL Server.
[root@centos-8-server01 app]# systemctl start mysqld
[root@centos-8-server01 app]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-03-31 13:43:59 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 30975 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 31002 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 9049)
Memory: 440.8M
CGroup: /system.slice/mysqld.service
└─31002 /usr/sbin/mysqld
3月 31 13:43:56 centos-8-server01 systemd[1]: Starting MySQL Server...
3月 31 13:43:59 centos-8-server01 systemd[1]: Started MySQL Server.
[root@centos-8-server01 app]#
查看存在的数据库和表
[root@centos-8-server01 app]# mysqlshow -uroot -pMyNewPass4!
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@centos-8-server01 app]# mysqlshow -uroot -pMyNewPass4! mysql
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: mysql
+---------------------------+
| Tables |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
[root@centos-8-server01 app]#
进行一次查询
[root@centos-8-server01 app]# mysql -uroot -pMyNewPass4! -e 'select user,host,plugin from mysql.user' mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
至此,可以确认, mysql已经部署完毕,你可以进行访问了。