如何在CentOS 8/RHEL 8上安装Percona MySQL Server 8
欢迎来到我们的教程,了解如何在RHEL/CentOS 8上安装适用于MySQL 8.0的Percona Server。适用于MySQL的Percona Server是MySQL的免费,开源和完全兼容的替代品,具有突破性的性能和可伸缩性。该软件由Percona创建,是对Oracle MySQL关系数据库管理系统的替代。 Percona Server软件提供了非常快速,多线程,多用户且健壮的SQL(结构化查询语言)数据库服务器。
在这篇文章中,我们将在CentOS 8/RHEL 8服务器上安装用于MySQL 8.0的Percona服务器。我们可以从RPM软件包或者从Percona官方存储库中进行安装。由于无缝升级过程,我更喜欢后者。
请按照下面提供的步骤在CentOS 8/RHEL 8上安装Percona Server for MySQL 8.0。我们将介绍安装,强化和基本数据库操作,例如数据库的创建,用户和特权分配。
更新RHEL/CentOS 8服务器
我们始终确保服务器已更新。对于新安装的CentOS/RHEL 8系统,主要是这样。
sudo yum -y update
添加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。
Updating Subscription Management repositories. Last metadata expiration check: 1:44:49 ago on Sat 07 Sep 2019 06:08:03 AM EDT. percona-release-latest.noarch.rpm 11 kB/s | 17 kB 00:01 Dependencies resolved. =================================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================================== Installing: percona-release noarch 1.0-12 @commandline 17 k Transaction Summary =================================================================================================================================================== Install 1 Package Total size: 17 k Installed size: 19 k Is this ok [y/N]: y
确认在RHEL/CentOS 8上安装Percona存储库。
$rpm -qi percona-release Name : percona-release Version : 1.0 Release : 12 Architecture: noarch Install Date: Sat 07 Sep 2019 07:52:57 AM EDT Group : System Environment/Base Size : 19912 License : GPL-3.0+ Signature : DSA/SHA1, Thu 15 Aug 2019 09:38:36 AM EDT, Key ID 1c4cbdcdcd2efd2a Source RPM : percona-release-1.0-12.src.rpm Build Date : Thu 15 Aug 2019 01:38:34 PM EDT Build Host : minimal-centos-6-x32-19637 Relocations : (not relocatable) Summary : Package to install Percona GPG key and YUM repo Description : percona-release package contains Percona GPG public keys and Percona repository configuration for YUM
为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
为MySQL 8.0安装Percona Server
Percona Server适用于关键任务的高负荷生产系统。在CentOS 8/RHEL 8服务器上安装Percona Server 8.0:
sudo yum install percona-server-server percona-toolkit 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.16 Release : 7.1.el8 Architecture: x86_64 Install Date: Sat 07 Sep 2019 08:01:44 AM EDT Group : Applications/Databases Size : 404495862 License : Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.. Signature : RSA/SHA256, Wed 14 Aug 2019 12:08:05 PM EDT, Key ID 9334a25f8507efa5 Source RPM : percona-server-8.0.16-7.1.el8.src.rpm Build Date : Wed 14 Aug 2019 12:01:40 PM EDT Build Host : minimal-rhel-8-x64-19531.ci.percona.com Relocations : (not relocatable) Packager : Percona MySQL Development Team <theitroad@localhost> Vendor : Percona, Inc URL : http://www.percona.com/ Summary : Percona Server: a very fast and reliable SQL database server
启动并保护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 Sat 2019-09-07 08:05:41 EDT; 23s 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 Sep 07 08:05:31 rhel8.novalocal systemd[1]: Starting MySQL Server... Sep 07 08:05:41 rhel8.novalocal 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 theitroad@localhost: Gr8sAuo<O!5U
运行mysql_secure_installation脚本来强化数据库服务器。
$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.16-7 Percona Server (GPL), Release 7, Revision 613e312 Copyright (c) 2009-2019 Percona LLC and/or its affiliates 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 Jan 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.16-7 | +-----------+ 1 row in set (0.00 sec)
创建测试数据库和用户。
mysql> CREATE DATABASE testdb; Query OK, 1 row affected (0.02 sec) mysql> CREATE USER theitroad@localhost IDENTIFIED BY 'crHsAu56o<O!5Ux'; Query OK, 0 rows affected (0.02 sec) mysql> GRANT ALL ON testdb.* TO theitroad@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' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.16-7 Percona Server (GPL), Release 7, Revision 613e312 Copyright (c) 2009-2019 Percona LLC and/or its affiliates 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 Jan be trademarks of their respective owners. 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 theitroad@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