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

點擊瞭解更多,快速查看更多的技術文章列表。


分享到:


相關文章: