CentOS8或RHEL8系统如何安装MySQL 8.0

1. 前言

本文主要介绍如何在CentOS8或者RHEL8服务器上安装MySQL 8.0。如果你是RHEL8的新手,您可以在我之前的文章Red Hat Enterprise Linux 8 (RHEL8)的新特性和评论中找到所有的RHEL8新特性。MySQL是一个多线程、多用户的SQL数据库服务器。它由MySQL服务器守护进程、mysqld和许多客户端程序组成。

CentOS8或RHEL8系统如何安装MySQL 8.0

CentOS8或RHEL8系统如何安装MySQL 8.0

1.1 MySQL 8.0增强特性

RHEL 8是随MySQL 8.0发布的,它有以下新特性:

  • 增强的JSON的功能。
  • MySQL 8.0支持角色。角色是特权的集合。
  • 它合并了一个事务性数据字典,用来存储关于数据库对象的信息。
  • 是否支持公共表表达式——递归和非递归
  • 支持窗口函数,它使用相关行对查询中的每一行执行计算。
  • 它提供了InnoDB,支持NOWAIT和跳过锁定选项锁定读语句。
CentOS8或RHEL8系统如何安装MySQL 8.0

MySQL 8.0增强特性

1.2 MySQL 8.0默认的身份验证插件

注意,MySQL 8.0服务器分布式RHEL 8配置为使用mysql_native_password作为默认身份验证插件,因为客户端工具和库在RHEL 8 caching_sha2_password方法是不相容的,默认情况下使用的上游MySQL 8.0版本。

对于MariaDB用户,我写了一篇关于MariaDB 10.3安装在RHEL8或CentOS8上的文章如下:

2. 在CentOS8或RHEL8上安装Mysql 8.0

按照这里提供的步骤在RHEL8或者CentOS8上安装MySQL 8.0。

CentOS8或RHEL8系统如何安装MySQL 8.0

在CentOS8或RHEL8上安装Mysql 8.0

2.1 步骤1:更新系统

确保您的系统已更新。

sudo yum update

2.2 步骤2:在RHEL8或CentOS8上安装MySQL 8.0

mysql 8.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!

2.3 步骤3: 在RHEL8或CentOS8上配置MySQL 8.0

CentOS8或RHEL8系统如何安装MySQL 8.0

在RHEL8或CentOS8上配置MySQL 8.0

设置MySQL 8.0开机自启动sudo systemctl enable --now mysql

检查服务状态:

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 2018-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:

Re-enter new 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, 2018, 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() |

+-----------+

| 8.0.12 |

+-----------+

1 row in set (0.00 sec)

mysql> QUIT

Bye

3. 总结

通过本文您现在已经在RHEL8或CentOS8毓上安装了MySQL 8.0数据库服务器。

https://www.linuxrumen.com/rmxx/1475.html

点击了解更多,快速查看更多的技术文章列表。


分享到:


相關文章: