ウェブサイト検索

RHEL/CentOS 8/7 および Fedora 35 に MySQL 8.0 をインストールする方法


MySQL は、GNU (一般公衆利用許諾) に基づいてリリースされたオープンソースの無料リレーショナル データベース管理システム (RDBMS) です。 。これは、作成された各データベースへのマルチユーザー アクセスを提供することにより、単一サーバー上で複数のデータベースを実行するために使用されます。

この記事では、最新の MySQL 8.0 バージョンを RHEL/CentOS 8/7/6/ にインストールして更新するプロセスについて説明します。 YUM ユーティリティ経由で MySQL Yum リポジトリを使用する Fedora

ステップ 1: MySQL Yum リポジトリの追加

1. 公式の MySQL Yum ソフトウェア リポジトリを使用します。このリポジトリは、最新バージョンの MySQL サーバー、クライアント、MySQL ユーティリティ、MySQL Workbench、Connector/ をインストールするための RPM パッケージを提供します。 ODBC、RHEL/CentOS 8/7/6/ および Fedora 30-35 用の Connector/Python。

重要: これらの手順は、サーバー上に MySQL がすでに存在する場合、MySQL の新規インストールでのみ機能します。 > サードパーティが配布する RPM パッケージを使用してインストールされている場合は、MySQL Yum リポジトリ を使用して、インストールされている MySQL パッケージをアップグレードまたは置き換えることをお勧めします。

古い MySQL パッケージをアップグレードまたは置き換える前に、MySQL データベースのバックアップ ガイドを使用して、重要なデータベースのバックアップと構成ファイルをすべて取得することを忘れないでください。

2. 次の MySQL Yum リポジトリ をダウンロードして、それぞれの Linux ディストリビューション システムのリポジトリ リストに追加して、MySQL の最新バージョン (8.0 など) をインストールします。 2018 年 7 月 27 日にリリースされました)。

--------------- On RHEL/CentOS 8 ---------------
wget https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
--------------- On RHEL/CentOS 7 ---------------
wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
--------------- On RHEL/CentOS 6 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
--------------- On Fedora 35 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc35-1.noarch.rpm
--------------- On Fedora 34 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc34-1.noarch.rpm
--------------- On Fedora 33 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc33-1.noarch.rpm

3. Linux プラットフォーム用のパッケージをダウンロードした後、次のコマンドを使用して、ダウンロードしたパッケージをインストールします。

--------------- On RHEL/CentOS 8 ---------------
yum localinstall mysql80-community-release-el8-1.noarch.rpm
--------------- On RHEL/CentOS 7 ---------------
yum localinstall mysql80-community-release-el7-1.noarch.rpm
--------------- On RHEL/CentOS 6 ---------------
yum localinstall mysql80-community-release-el6-1.noarch.rpm
--------------- On Fedora 35 ---------------
dnf localinstall mysql80-community-release-fc35-1.noarch.rpm
--------------- On Fedora 34 ---------------
dnf localinstall mysql80-community-release-fc34-1.noarch.rpm
--------------- On Fedora 33 ---------------
yum localinstall mysql80-community-release-fc33-1.noarch.rpm

上記のインストール コマンドは、MySQL Yum リポジトリをシステムのリポジトリ リストに追加し、GnuPG キーをダウンロードしてパッケージの整合性を確認します。

4. 次のコマンドを使用して、MySQL Yum リポジトリが正常に追加されたことを確認できます。

yum repolist enabled | grep "mysql.*-community.*"
dnf repolist enabled | grep "mysql.*-community.*"      [On Fedora versions]

ステップ 2: 最新の MySQL バージョンをインストールする

5. 次のコマンドを使用して、MySQL の最新バージョン (現在は 8.0) をインストールします。

yum install mysql-community-server
dnf install mysql-community-server      [On Fedora versions]

上記のコマンドは、MySQL サーバー mysql-community-servermysql-community-clientmysql-community-common に必要なすべてのパッケージをインストールします。 mysql-community-libs

ステップ 3: 異なる MySQL リリース バージョンのインストール

6. MySQL Community Server の異なるサブリポジトリを使用して、異なる MySQL バージョンをインストールすることもできます。最近の MySQL シリーズ (現在はMySQL 8.0) のサブリポジトリはデフォルトでアクティブ化され、他のすべてのバージョン (MySQL 5.x シリーズなど) のサブリポジトリはデフォルトで非アクティブ化されます。 。

特定のサブリポジトリから特定のバージョンをインストールするには、yum-config-manager を使用して --enable または --disable オプションを使用できます。または、次のようなdnf config-manager を使用します。

yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql56-community
------------------ Fedora Versions ------------------
dnf config-manager --disable mysql57-community
dnf config-manager --enable mysql56-community

ステップ 4: MySQL サーバーの起動

7. MySQL のインストールが成功したら、次のコマンドを使用して MySQL サーバーを起動して有効にします。

service mysqld start
systemctl enable mysqld.service

次のコマンドを使用して、MySQL サーバーのステータスを確認できます。

systemctl status mysqld.service
OR
service mysqld status

これは、CentOS 7 ボックスで MySQL を実行した場合のサンプル出力です。

Redirecting to /bin/systemctl status  mysqld.service
mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
   Active: active (running) since Thu 2015-10-29 05:15:19 EDT; 4min 5s ago
  Process: 5314 ExecStart=/usr/sbin/mysqld --daemonize $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5298 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5317 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─5317 /usr/sbin/mysqld --daemonize

Oct 29 05:15:19 localhost.localdomain systemd[1]: Started MySQL Server.

8. 最後に、次のコマンドを使用して、インストールされている MySQL のバージョンを確認します。

mysql --version

mysql  Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)

ステップ 5: MySQL インストールの保護

9. コマンド mysql_secure_installation を使用すると、root パスワードの設定、匿名ユーザーの削除、root ログインの削除などの重要な設定を実行して、MySQL インストールを保護できます。

: MySQL バージョン 8.0 以降では、一時的なランダムなパスワードが /var/log/mysqld.log に生成されます。取り付け後。

MySQL secure コマンドを実行する前に、以下のコマンドを使用してパスワードを確認します。

grep 'temporary password' /var/log/mysqld.log

パスワードがわかったら、次のコマンドを実行して MySQL インストールを保護できます。

mysql_secure_installation

: 新しいルート パスワードを入力することは、ファイル /var/log/mysqld.log からの一時パスワードを意味します。

ここで、画面上の指示に注意深く従ってください。参考までに、以下の上記のコマンドの出力を参照してください。

サンプル出力
Securing the MySQL server deployment.

Enter password for user root: Enter New Root Password

VALIDATE PASSWORD PLUGIN 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 plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

Estimated strength of the password: 50 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: Set New MySQL Password

Re-enter new password: Re-enter New MySQL Password

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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! 

ステップ 6: MySQL サーバーへの接続

10. ユーザー名とパスワードを指定して、新しくインストールした MySQL サーバーに接続します。

mysql -u root -p

サンプル出力:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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>

ステップ 7: Yum を使用して MySQL を更新する

11. 新規インストールのほかに、次のコマンドを使用して MySQL 製品とコンポーネントを更新することもできます。

yum update mysql-server
dnf update mysql-server       [On Fedora versions]

MySQL の新しいアップデートが利用可能になると、それらは自動的にインストールされますが、そうでない場合はアップデート対象のパッケージがマークされていないというメッセージが表示されます。

これで、MySQL 8.0 がシステムに正常にインストールされました。インストールに問題がある場合は、コメントセクションを使用して解決策を見つけてください。