如何在 CentOS 8 上安装 MySQL 8 数据库服务器如何在 CentOS 8 上安装 MySQL 8 数据库服务器如何在 CentOS 8 上安装 MySQL 8 数据库服务器如何在 CentOS 8 上安装 MySQL 8 数据库服务器
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 CentOS 8 上安装 MySQL 8 数据库服务器

在此页

  1. 先决条件
  2. 从 MySQL 存储库安装 MySQL 8.0
  3. 从 AppStream 存储库安装 MySQL 8.0
  4. 结论

MySQL 是一个免费的开源数据库,是全球最受欢迎的数据库系统之一。它是一个由 Oracle 云提供支持的关系数据库管理平台。它使用结构化查询语言来添加、访问和管理数据库中的内容。它以其经过验证的可靠性、快速处理、易用性和使用灵活性而闻名。 MySQL 8 中添加了几个新功能,包括 JSON 支持、事务数据字典、持久运行时配置、文档存储、优化器提示、SQL 角色、CTE 和窗口函数、不可见索引等等。

注意:在安装 MySQL 8 之前,请参考官方文档,因为 MySQL 8 有一些新功能和更改,导致某些应用程序与此版本不兼容。

在本教程中,我们将向您展示如何在 CentOS 8 服务器上安装 MySQL 8 数据库。

先决条件

  • 一台运行 CentOS 8 的服务器。
  • 在您的服务器上设置了根密码。

从 MySQL 存储库安装 MySQL 8.0

默认情况下,CentOS 8 默认存储库中不提供 MySQL 8.0。因此,您需要将 MySQL 8.0 社区存储库安装到您的系统中。您可以使用以下命令安装它:

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

您应该看到以下输出:

Retrieving https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
warning: /var/tmp/rpm-tmp.hF0m5V: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el8-1  ################################# [100%]

接下来,使用以下命令验证 MySQL 8.0 存储库是否已启用:

dnf repolist all | grep mysql | grep enabled

您应该看到以下输出:

CentOS-8 - AppStream                            3.1 MB/s | 6.5 MB     00:02    
CentOS-8 - Base                                 3.0 MB/s | 5.0 MB     00:01    
CentOS-8 - Extras                               5.3 kB/s | 2.1 kB     00:00    
MySQL 8.0 Community Server                       24 MB/s | 543 kB     00:00    
MySQL Connectors Community                      1.9 MB/s |  19 kB     00:00    
MySQL Tools Community                           677 kB/s |  62 kB     00:00    
mysql-connectors-community         MySQL Connectors Community     enabled:    42
mysql-tools-community              MySQL Tools Community          enabled:    19
mysql80-community                  MySQL 8.0 Community Server     enabled:    31

接下来,暂时禁用 AppStream 存储库并使用以下命令从 MySQL 社区存储库安装最新版本的 MySQL 8.0:

dnf --disablerepo=AppStream install mysql-community-server -y

安装成功完成后,您可以使用以下命令验证安装的 MySQL 版本:

mysql -Version

您应该看到以下输出:

mysql  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)

接下来,使用以下命令启动 MySQL 服务并使其在系统重启后启动:

systemctl start mysqld
systemctl enable mysqld

您还可以使用以下命令检查 MySQL 的状态:

systemctl status mysqld

您应该看到以下输出:

? mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-03-05 09:37:46 EST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3244 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3329 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 12537)
   Memory: 587.7M
   CGroup: /system.slice/mysqld.service
           ??3329 /usr/sbin/mysqld

Mar 05 09:37:01 centos8 systemd[1]: Starting MySQL Server...
Mar 05 09:37:46 centos8 systemd[1]: Started MySQL Server.

接下来,运行 mysql_secure_installation 脚本以启用一些额外的安全功能总是一个好主意,包括设置新的 MySQL root 密码、删除匿名用户和禁用远程登录。

首先,使用以下命令找到 MySQL 默认的 root 密码:

cat /var/log/mysqld.log | grep -i 'temporary password'

输出:

2020-03-05T14:37:40.273796Z 5 [Note] [MY-010454] [Server] A temporary password is generated for : GN2uNx-vPqwS

请记下上述密码并使用 mysql_secure_installation 脚本更改它。

mysql_secure_installation

如下图所示回答所有问题:

Securing the MySQL server deployment.

Enter password for user root:   Provide your temporary MySQL root password

The existing password for the user account root has expired. Please set a new password.

New password:   Provide new root password

Re-enter new password:   Re-enter new root password
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N  Type N and Enter to continue

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

从 AppStream 存储库安装 MySQL 8.0

您还可以从 CentOS 8 上的默认 AppStream 存储库安装 MySQL 8.0。您可以使用以下命令安装它:

dnf install @mysql -y

安装完成后,使用以下命令检查MySQL的版本:

mysql -Version

您应该看到以下输出:

mysql  Ver 8.0.17 for Linux on x86_64 (Source distribution)

接下来,使用以下命令启动 MySQL 服务并使其在系统重启后启动:

systemctl start mysqld
systemctl enable mysqld

默认情况下,CentoS 8 中没有设置 MySQL root 密码。因此您需要使用 mysql_secure_installation 脚本设置它。

mysql_secure_installation

如下图所示回答所有问题:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 

结论

在上面的指南中,您了解了如何从 MySQL 社区存储库和 CentOS 8 上的 AppStream 存储库安装 MySQL 8。您现在可以开始创建新的数据库和数据库用户。

©2015-2025 艾丽卡 support@alaica.com