如何在CentOS 8/RHEL 8上安装MySQL 8.0
时间:2020-02-23 14:40:57 来源:igfitidea点击:
这是有关如何在CentOS 8/RHEL 8服务器上安装MySQL 8.0的分步教程。
MySQL是一个多线程,多用户SQL数据库服务器。它由MySQL服务器守护程序,mysqld和许多客户端程序组成。
MySQL 8.0增强功能
RHEL 8随MySQL 8.0一起发布,它具有以下新功能:增强的JSON功能.MySQL 8.0支持角色。角色是特权的集合。支持带有锁定读取语句的NOWAIT和SKIP LOCKED选项。
默认身份验证插件
请注意,随RHEL 8分发的MySQL 8.0服务器被配置为使用mysql_native_password作为默认身份验证插件,因为RHEL 8中的客户端工具和库与缺省在上游MySQL中使用的caching_sha2_password方法不兼容。 8.0版本。
请按照此处提供的步骤在RHEL 8/CentOS 8上安装MySQL 8.0。
更新系统
确保系统已更新。
sudo yum update
在RHEL 8/CentOS 8上安装MySQL 8.0
mysql8.0软件包可在AppStream存储库中找到,并可以通过运行以下命令进行安装:
sudo dnf install @mysql:8.0
出现提示时确认安装
Transaction Summary ======================================================================================================================================================= Install 7 Packages Total download size: 35 M Installed size: 229 M Is this ok [y/N]: y
将安装以下软件包
Installed: mysql-8.0.12-6.el8+1923+5642a751.x86_64 mysql-server-8.0.12-6.el8+1923+5642a751.x86_64 mecab-0.996-1.el8+1521+e4919bed.9.x86_64 mysql-common-8.0.12-6.el8+1923+5642a751.x86_64 mariadb-connector-c-config-3.0.6-2.el8.noarch protobuf-lite-3.5.0-7.el8.x86_64 mysql-errmsg-8.0.12-6.el8+1923+5642a751.x86_64 Complete!
在RHEL 8上配置MySQL 8.0
激活mysqld
服务
sudo systemctl enable --now mysqld
确认服务状态:
$sudo systemctl status mysqld ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2016-12-05 15:32:50 EST; 16s ago Process: 4387 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 4262 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Process: 4238 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 4345 (mysqld) Status: "SERVER_OPERATING" Tasks: 37 (limit: 5056) Memory: 358.9M CGroup: /system.slice/mysqld.service └─4345 /usr/libexec/mysqld --basedir=/usr Dec 05 15:32:42 rhel8.localdomain systemd[1]: Starting MySQL 8.0 database server... Dec 05 15:32:42 rhel8.localdomain mysql-prepare-db-dir[4262]: Initializing MySQL database Dec 05 15:32:50 rhel8.localdomain systemd[1]: Started MySQL 8.0 database server.
服务启动后,运行命令mysql_secure_installation加固MySQL数据库服务器。
$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: Please set the password for root here. New password: <ENTER NEW PASSWORD> Re-enter new password: <CONFIRM PASSWORD> 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用户密码删除匿名用户禁止root用户远程登录删除测试数据库并对其进行访问
完成后,使用root用户测试访问权限
$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.12 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.00 sec) mysql> QUIT Bye
现在,我们已经在RHEL 8上安装了MySQL 8.0数据库服务器。