在 CentOS 8/RHEL 8 上安装 Percona MySQL Server 8
欢迎阅读我们有关如何在 RHEL/CentOS 8 Linux 服务器上安装 Percona Server for MySQL 8.0 的指南。 Percona Server for MySQL 是一款免费、开源且完全兼容的 MySQL 替代品,可提供突破性的性能和可扩展性。该软件由 Percona 创建,作为 Oracle MySQL 关系数据库管理系统的替代品。 Percona Server 软件提供了一个非常快速、多线程、多用户且强大的 SQL(结构化查询语言)数据库服务器。
在这篇博文中,我们将在 CentOS 8/RHEL 8 服务器上安装 Percona Server for MySQL 8.0。您可以从 RPM 包或官方 Percona 存储库进行安装。我更喜欢后者,因为无缝升级过程。
按照下一节中提供的步骤在 CentOS 8/RHEL 8 上安装 Percona Server for MySQL 8.0。我们将介绍安装、强化和基本数据库操作,例如创建数据库、用户和权限分配。
第1步:更新RHEL/CentOS 8服务器
我们始终确保我们的服务器已更新。对于新安装的 CentOS/RHEL 8 系统来说尤其如此。
sudo yum -y update
第 2 步:添加 Percona YUM 存储库
Percona Server for MySQL 软件存储库提供了即用型软件包。 Percona yum 存储库支持流行的基于 RPM 的操作系统,包括 CentOS、RHEL、Fedora 和 >Amazon Linux AMI。
通过使用 sudo 运行以下命令来安装 Percona 存储库。
sudo yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
当提示完成交易时,按y。
....
Dependencies resolved.
======================================================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================================================
Installing:
percona-release noarch 1.0-27 @commandline 20 k
Transaction Summary
======================================================================================================================================================================================================
Install 1 Package
Total size: 20 k
Installed size: 32 k
Is this ok [y/N]: y
确认在 RHEL/CentOS 8 上安装 Percona 存储库。
$ rpm -qi percona-release
Name : percona-release
Version : 1.0
Release : 27
Architecture: noarch
Install Date: Thu 17 Aug 2023 08:06:39 PM UTC
Group : System Environment/Base
Size : 33154
License : GPL-3.0+
Signature : DSA/SHA1, Tue 17 Aug 2021 02:59:47 PM UTC, Key ID 1c4cbdcdcd2efd2a
Source RPM : percona-release-1.0-27.src.rpm
Build Date : Mon 16 Aug 2021 04:45:48 PM UTC
Build Host : minimal-centos-6-x32-773
Relocations : (not relocatable)
...
步骤 3:启用 MySQL 8.0 存储库
安装程序在 /etc/yum.repos.d/percona-original-release.repo 中创建了一个新的存储库文件。我们需要使用下一个命令启用 Percona Server 8.0 存储库。
sudo percona-release setup ps80
系统会提示您禁用 MySQL 的 RHEL 8 模块,这可以通过运行以下命令手动实现:
sudo dnf module disable mysql -y
步骤 4:安装 Percona Server for MySQL 8.0
Percona Server 旨在用于关键任务、重负载生产系统。在 CentOS 8/RHEL 8 服务器上安装 Percona Server 8.0:
sudo yum install percona-server-server percona-toolkit -y
sudo percona-release enable-only tools release
sudo yum install percona-xtrabackup-80
有关服务器包的更多信息:
$ rpm -qi percona-server-server
Name : percona-server-server
Version : 8.0.33
Release : 25.1.el8
Architecture: x86_64
Install Date: Thu 17 Aug 2023 08:08:55 PM UTC
Group : Applications/Databases
Size : 471045739
License : Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field..
Signature : RSA/SHA256, Wed 07 Jun 2023 10:00:54 PM UTC, Key ID 9334a25f8507efa5
Source RPM : percona-server-8.0.33-25.1.el8.src.rpm
Build Date : Wed 07 Jun 2023 02:54:25 PM UTC
Build Host : ip-10-199-2-187.eu-west-1.compute.internal
....
第 5 步:启动并保护 Percona MySQL 服务器
现在 Percona Server 8.0 已安装,启动并将 mysqld 服务设置为在系统启动时启动。
sudo systemctl enable --now mysqld
检查服务状态。
$ systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2023-08-17 20:10:29 UTC; 13s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 8568 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 8647 (mysqld)
Status: "SERVER_OPERATING"
Tasks: 39 (limit: 23876)
Memory: 571.9M
CGroup: /system.slice/mysqld.service
└─8647 /usr/sbin/mysqld
ug 17 20:10:23 rocky8.mylab.io systemd[1]: Starting MySQL Server...
Aug 17 20:10:29 rocky8.mylab.io systemd[1]: Started MySQL Server.
复制生成的 root 密码以进行初始访问。
$ sudo grep "temporary password" /var/log/mysqld.log
2019-09-07T12:05:37.130661Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Gr8sAuo<O!5U
运行mysql_secure_installation脚本来强化您的数据库服务器。
$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: <Paste-copied-password>
The existing password for the user account root has expired. Please set a new password.
New password: <Enter-new-password>
Re-enter new password: <Retype-new-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) :
… 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!
尝试使用新设置的密码以 root 用户身份访问数据库 CLI。
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.33-25
Copyright (c) 2009-2023 Percona LLC and/or its affiliates
Copyright (c) 2000-2023, Oracle and/or its affiliates.
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>
显示 MySQL 服务器版本。
mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.33-25 |
+-----------+
1 row in set (0.00 sec)
创建测试数据库和用户。
mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.02 sec)
mysql> CREATE USER testuser@localhost IDENTIFIED BY 'crHsAu56o<O!5Ux';
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT ALL ON testdb.* TO testuser@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> QUIT
Bye
检查testuser是否可以访问数据库。
$ mysql -u testuser -p'crHsAu56o<O!5Ux'
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| testdb |
+--------------------+
2 rows in set (0.00 sec)
mysql> QUIT
Bye
删除测试数据库和用户。
$ mysql -u root -p
mysql> DROP DATABASE testdb;
Query OK, 0 rows affected (0.02 sec)
mysql> DROP USER testuser@localhost;
Query OK, 0 rows affected (0.02 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> QUIT
Bye
推荐的 MySQL 书籍:
- 学习 MySQL/MariaDB 数据库的最佳书籍
其他 MySQL 相关文章。