在 CentOS 8/RHEL 8 Linux 上安装 MySQL 5.7 |在 CentOS 8/RHEL 8 Linux 上安装 MySQL 5.7 |在 CentOS 8/RHEL 8 Linux 上安装 MySQL 5.7 |在 CentOS 8/RHEL 8 Linux 上安装 MySQL 5.7 |
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

在 CentOS 8/RHEL 8 Linux 上安装 MySQL 5.7 |

发表 admin at 2025年2月28日
类别
  • 未分类
标签

您是否正在寻找帮助您在 CentOS 8/RHEL 8 Linux 服务器/工作站上安装 MySQL 5.7 的指南? CentOS/RHEL 8 AppStream 存储库仅包含 MySQL 8.0 软件包。并非所有应用程序都支持 MySQL 8,例如,截至撰写本文时,Jira 需要 MySQL 5.7 及更低版本。那么如何在 CentOS 8/RHEL 8 上安装 MySQL 5.7 呢?

MySQL 是一个非常流行的开源关系数据库管理系统。它由 Oracle Corporation(Oracle 数据库背后的公司)开发。凭借其经过验证的可靠性、性能和易用性,MySQL 已成为基于 Web 的应用程序的领先数据库选择。

按照以下步骤在 CentOS 8/RHEL 8 系统上运行 MySQL 5.7 服务器。

第1步:添加MySQL存储库

禁用 MySQL 默认 AppStream 存储库:

sudo dnf remove @mysql
sudo dnf module reset mysql
sudo dnf module disable mysql

EL 8 没有 MySQL 存储库,因此我们将使用 EL 7 存储库。创建一个新的存储库文件。

sudo vi /etc/yum.repos.d/mysql-community.repo

将以下数据粘贴到文件中。

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0

步骤2:在CentOS 8/RHEL 8上安装MySQL 5.7

添加存储库后,现在在 CentOS 8/RHEL 8 上安装 MySQL 5.7。

禁用 MySQL 8 存储库:

sudo dnf config-manager --disable mysql80-community

然后启用 MySQL 5.7 的通道。

sudo dnf config-manager --enable mysql57-community

然后在 CentOS 8/RHEL 8 上安装 MySQL 5.7:

sudo dnf install mysql-community-server

按y开始安装。

Last metadata expiration check: 0:02:41 ago on Mon 06 Jan 2020 08:54:52 PM EAT.
Dependencies resolved.
========================================================================================================================================================
 Package                                   Arch                      Version                                 Repository                            Size
========================================================================================================================================================
Installing:
 mysql-community-server                    x86_64                    5.7.28-1.el7                            mysql57-community                    199 M
Installing dependencies:
 ncurses-compat-libs                       x86_64                    6.1-7.20180224.el8                      BaseOS                               331 k
 mysql-community-client                    x86_64                    5.7.28-1.el7                            mysql57-community                     43 M
 mysql-community-common                    x86_64                    5.7.28-1.el7                            mysql57-community                    311 k
 mysql-community-libs                      x86_64                    5.7.28-1.el7                            mysql57-community                    4.2 M

Transaction Summary
========================================================================================================================================================
Install  5 Packages

Total download size: 247 M
Installed size: 1.0 G
Is this ok [y/N]: y

检查软件包 rpm 详细信息以确认其为 5.7。

$ rpm -qi mysql-community-server 
Name        : mysql-community-server
Version     : 5.7.28
Release     : 1.el7
Architecture: x86_64
Install Date: Mon 06 Jan 2020 08:58:52 PM EAT
Group       : Applications/Databases
Size        : 910635041
License     : Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Signature   : DSA/SHA1, Mon 30 Sep 2019 11:05:08 AM EAT, Key ID 8c718d3b5072e1f5
Source RPM  : mysql-community-5.7.28-1.el7.src.rpm
Build Date  : Fri 27 Sep 2019 11:11:06 AM EAT
Build Host  : loki02.no.oracle.com
Relocations : (not relocatable)
Packager    : MySQL Release Engineering <[email >
Vendor      : Oracle and/or its affiliates
URL         : http://www.mysql.com/
Summary     : A very fast and reliable SQL database server

步骤3:在CentOS 8/RHEL 8上配置MySQL 5.7

2.1 – 安装后,启动mysqld服务。

sudo systemctl enable --now mysqld.service

2.2 – 复制生成的随机root用户密码

sudo grep 'A temporary password' /var/log/mysqld.log |tail -1

记下打印的密码:

2020-01-06T18:06:19.947403Z 1 [Note] A temporary password is generated for root@localhost: AS*5Rx%YY5+c

2.3 – 启动 MySQL 安全安装以更改

$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:

使用您生成的临时密码进行身份验证。这将要求您为 root 用户设置一个新密码。

Change the password for root ? ((Press y|Y for Yes, any other key for No) : Yes

New password: 
Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?: Yes

Remove anonymous users?: Yes
Success.

Disallow root login remotely? : Yes
Success.

Remove test database and access to it? : Yes
 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.

Reload privilege tables now? (Press y|Y for Yes) : Yes
Success.

All done!

您可以使用在线密码生成器来获取复杂的密码。

2.4 – 以 root 用户身份连接到 MySQL 数据库并创建测试数据库。

$ mysql -u root -p
Enter password: <Enter Root Password>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.28    |
+-----------+
1 row in set (0.00 sec)

mysql> QUIT
Bye

2.5 – 创建测试数据库和用户:

mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.09 sec)

mysql> CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Strong34S;#";
Query OK, 0 rows affected (0.04 sec)

mysql> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)


可以通过运行以下命令删除此测试数据库和用户:

mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.14 sec)

mysql> DROP USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.11 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> QUIT
Bye

步骤 4:配置防火墙 –(仅适用于远程连接)

要允许远程连接,请在防火墙上允许端口 3306

sudo firewall-cmd --add-service=mysql --permanent
sudo firewall-cmd --reload

您还可以限制来自受信任网络的访问:

sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
service name="mysql" source address="10.10.10.0/24" accept'

感谢您使用我们的指南在 CentOS 8/RHEL 8 上安装 MySQL 5.7。

最佳 MySQL Udemy 视频课程:

终极 MySQL 训练营:从 SQL 初学者到专家

SQL – 用于数据分析和商业智能的 MySQL

MySQL、SQL 和存储过程(从初级到高级)

SQL 初学者:使用 MySQL 和数据库设计学习 SQL

完整的 MySQL 开发人员课程

MySQL 数据库管理:初级 SQL 数据库设计

学习 MySQL 数据库设计

最佳 MySQL 学习书籍:

  • Murach 的 MySQL(第三版)
  • MySQL(第五版)(开发人员库)
  • MySQL 详解:数据库设计分步指南
  • SQL 入门 – 初学者的实践方法 – 一本简单、切题的介绍性读物,将涉及 SQL 的实际含义。在这里,向读者简要介绍了该语言的所有基础知识;
  • Head First SQL – 你的 SQL 大脑 – 学习者指南;
  • SQL Cookbook:数据库开发人员的查询解决方案和数据库技术 – 这本书充满了可应用于日常数据库管理的技巧和技巧;
  • Teach Yourself MS SQL Server – 一本相当老的书,但它在较高层次上涵盖了 SQL Server 的所有方面;
  • 有效的 SQL – 一本探索 SQL 功能的易于阅读的指南书。请记住,您可能需要一些 SQL 知识才能应用所阐述的想法。
©2015-2025 Norria support@alaica.com