Red Hat Enterprise Linux release 8にMySQLをインストールします。

rhel8にMySQLをインストールします。タイプはMySQL Community Editionです。
公式(https://www.mysql.com/jp/products/community/)では、「MySQL Community Editionは、世界で最も多く使用されているオープンソース・データベースの、無償で自由にダウンロードして利用することができるバージョンです。GPLライセンスに従って利用することができ、多くのオープンソース・デベロッパーが参加する、巨大で活発なコミュニティによるサポートを享受することができます。」と記述してあります。

それでは進めていきましょう。
まずはデフォルトでインストールできるMySQLを調べておきます。

dnf info mysql

下記が表示されました。
Available Packages
Name         : mysql
Version      : 8.0.21
Release      : 1.module+el8.2.0+7793+cfe2b687
Architecture : x86_64
Size         : 12 M
Source       : mysql-8.0.21-1.module+el8.2.0+7793+cfe2b687.src.rpm
Repository   : ol8_appstream
Summary      : MySQL client programs and shared libraries
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL
             : is a client/server implementation consisting of a server daemon
             : (mysqld) and many different client programs and libraries. The
             : base package contains the standard MySQL client programs and
             : generic MySQL files.

これで全く問題はありませんが、学習がてらリポジトリを追加してインストールします。
次のURLにアクセスして「Download MySQL Community Edition »」をクリックします。
https://www.mysql.com/jp/products/community/


ダウンロード種類一覧では「MySQL Yum Repository」をクリックして、目的のパッケージのダウンロードボタンをクリックします。次のページにある「No thanks, just start my download.」のリンクを右クリックなどでコピーしておきます。


ここからはssh接続して作業を進めます。どんなリポジトリがインストール済みであるか確認します。

sudo dnf repolist all

リポジトリをインストールします。
URLの部分が先ほどコピーした内容です。

sudo rpm -Uvh http://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

インストール前にリポジトリ一覧にあったデフォルトのmysqlを無効にしておきます。

sudo dnf module disable mysql

再度、リポジトリ一覧を確認します。

repo id repo name status
epel Extra Packages for Enterprise Linux enabled
epel-debuginfo Extra Packages for Enterprise Linux disabled
epel-modular Extra Packages for Enterprise Linux enabled
epel-modular-debuginfo Extra Packages for Enterprise Linux disabled
epel-modular-source Extra Packages for Enterprise Linux disabled
epel-playground Extra Packages for Enterprise Linux disabled
epel-playground-debuginfo Extra Packages for Enterprise Linux disabled
epel-playground-source Extra Packages for Enterprise Linux disabled
epel-source Extra Packages for Enterprise Linux disabled
epel-testing Extra Packages for Enterprise Linux disabled
epel-testing-debuginfo Extra Packages for Enterprise Linux disabled
epel-testing-modular Extra Packages for Enterprise Linux disabled
epel-testing-modular-debuginfo Extra Packages for Enterprise Linux disabled
epel-testing-modular-source Extra Packages for Enterprise Linux disabled
epel-testing-source Extra Packages for Enterprise Linux disabled
mysql-cluster-8.0-community MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community – Source disabled
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community – Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community – Source disabled
mysql-tools-preview MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview – Source disabled
mysql80-community MySQL 8.0 Community Server enabled
mysql80-community-source MySQL 8.0 Community Server – Source disabled
nginx-mainline nginx mainline repo enabled
nginx-stable nginx stable repo enabled
ol8_MySQL80 MySQL 8.0 for Oracle Linux 8 (x86_64 enabled
ol8_MySQL80_connectors_community MySQL 8.0 Connectors Community for O enabled
ol8_MySQL80_tools_community MySQL 8.0 Tools Community for Oracle enabled
ol8_UEKR6 Latest Unbreakable Enterprise Kernel enabled
ol8_UEKR6_RDMA Oracle Linux 8 UEK6 RDMA (x86_64) disabled
ol8_addons Oracle Linux 8 Addons (x86_64) enabled
ol8_appstream Oracle Linux 8 Application Stream (x enabled
ol8_baseos_latest Oracle Linux 8 BaseOS Latest (x86_64 enabled
ol8_codeready_builder Oracle Linux 8 CodeReady Builder (x8 disabled
ol8_developer Oracle Linux 8 Development Packages disabled
ol8_developer_EPEL Oracle Linux 8 EPEL Packages for Dev enabled
ol8_developer_UEKR6 Developer Preview of UEK Release 6 ( disabled
ol8_distro_builder Oracle Linux 8 Distro Builder (x86_6 disabled
ol8_ksplice Ksplice for Oracle Linux 8 (x86_64) enabled
ol8_oci Oracle Linux 8 OCI Packages (x86_64) enabled
ol8_oci_included Oracle Software for OCI users on Ora enabled
ol8_u0_baseos_base Oracle Linux 8 BaseOS GA (x86_64) disabled
ol8_u1_baseos_base Oracle Linux 8.1 BaseOS (x86_64) disabled
ol8_u2_baseos_base Oracle Linux 8.2 BaseOS (x86_64) disabled
ol8_u3_baseos_base Oracle Linux 8.3 BaseOS (x86_64) disabled
remi Remi’s RPM repository for Enterprise disabled
remi-debuginfo Remi’s RPM repository for Enterprise disabled
remi-modular Remi’s Modular repository for Enterp enabled
remi-modular-test Remi’s Modular testing repository fo disabled
remi-safe Safe Remi’s RPM repository for Enter enabled
remi-safe-debuginfo Remi’s RPM repository for Enterprise disabled
remi-test Remi’s test RPM repository for Enter disabled
remi-test-debuginfo Remi’s test RPM repository for Enter disabled

MySQL Community Editionをインストールします。
mysql80-communityがリポジトリになっているので成功です。

sudo dnf install mysql-community-server

バージョンも確認します。

mysqld --version

インストールが無事終わったのでmysqlの状態を見てみましょう。インストールした直後は起動してないようです。起動します。

sudo systemctl status mysqld
sudo systemctl start mysqld

それでは初期設定をおこないましょう。次のコマンドを入力して指示通り進めていきます。

mysql_secure_installation

ここでrootのパスワード入力を求められます。
rootの初期パスワードは特定のディレクトリにあるログファイルに記述してあります。mysqld.logに記述されているので抽出しておきます。

最初に限りこのパスワードを使用し、新しいパスワードに変更しておきます。大文字小文字に数字、記号が必要です。

sudo cat /var/log/mysqld.log | grep root

初期設定の続きをします。

Securing the MySQL server deployment.

Enter password for user root:
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) : n

変更したパスワードを使用するのでNを選択します。

… 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!

最後にmysqlに接続をしてみます。新しく決めたパスワードを使用します。

mysql -u root -p

教育

Posted by admin