LoginSignup
4
1

More than 1 year has passed since last update.

CentOS 8に、MySQL 8をyumリポジトリからインストールする

Last updated at Posted at 2021-11-11

What's?

CentOS 8に、MySQLが提供するyumリポジトリを使ってインストールしようとしたらちょっとハマったので、メモとして残しておきます。

MySQL yumリポジトリ

MySQLがyumリポジトリを提供しています。

現時点で、RHEL 6〜8、Fedora 33〜35がターゲットです。

環境

今回の環境は、こちらです。CentOS 8.4を使います。

$ cat /etc/redhat-release
CentOS Linux release 8.4.2105


$ uname -srvmpio
Linux 4.18.0-305.19.1.el8_4.x86_64 #1 SMP Wed Sep 15 15:39:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

MySQLをMySQLのyumリポジトリからインストールする

RHEL 8やCentOS 8等でのMySQLのyumリポジトリは、以下のコマンドでインストールできます。

$ sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm

ところが、こちらをインストールしてもmysql-community-servermysql-community-clientが見えません。-debugは見えるのですが。

$ dnf search mysql-community-
Last metadata expiration check: 0:00:03 ago on 2021年11月11日 19時52分16秒.
======================================================================== Name & Summary Matched: mysql-community- =========================================================================
mysql-community-client-debuginfo.x86_64 : Debug information for package mysql-community-client
mysql-community-client-plugins-debuginfo.x86_64 : Debug information for package mysql-community-client-plugins
mysql-community-libs-debuginfo.x86_64 : Debug information for package mysql-community-libs
mysql-community-server-debug-debuginfo.x86_64 : Debug information for package mysql-community-server-debug
mysql-community-server-debuginfo.x86_64 : Debug information for package mysql-community-server
mysql-community-test-debuginfo.x86_64 : Debug information for package mysql-community-test
============================================================================= Name Matched: mysql-community- ==============================================================================
mysql-community-client-plugins.x86_64 : Shared plugins for MySQL client applications
mysql-community-debuginfo.x86_64 : Debug information for package mysql-community
mysql-community-debugsource.x86_64 : Debug sources for package mysql-community
mysql-community-server-debug.x86_64 : The debug version of MySQL server

これは、以下のドキュメントに書いてありますが、RHEL 8やCentOS 8にはデフォルトでMySQLが含まれているからですね。

(EL8 システムのみ) RHEL8 や Oracle Linux 8 などの EL8-based システムには、デフォルトで有効になっている MySQL モジュールが含まれています。 このモジュールを無効にしないかぎり、MySQL リポジトリによって提供されるパッケージがマスクされます。

このように、yumリポジトリのインストール前からmysqlモジュールや

$ dnf module list mysql
Last metadata expiration check: 0:00:11 ago on 2021年11月11日 19時49分46秒.
CentOS Linux 8 - AppStream
Name                                      Stream                                      Profiles                                              Summary                                        
mysql                                     8.0 [d]                                     client, server [d]                                    MySQL Module                                   

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

パッケージが存在します。

$ dnf search mysql-
Last metadata expiration check: 0:00:56 ago on 2021年11月11日 19時49分46秒.
================================================================================== Name Matched: mysql- ===================================================================================
MySQL-zrm.noarch : MySQL backup manager
mysql-common.x86_64 : The shared files required for MySQL server and client
mysql-devel.x86_64 : Files for development of MySQL applications
mysql-errmsg.x86_64 : The error messages files required by MySQL server
mysql-libs.x86_64 : The shared libraries required for MySQL clients
mysql-mmm.noarch : Multi-Master Replication Manager for MySQL
mysql-mmm-agent.noarch : MMM Database Server Agent Daemon and Libraries
mysql-mmm-monitor.noarch : MMM Monitor Server Daemon and Libraries
mysql-mmm-tools.noarch : MMM Control Scripts and Libraries
mysql-selinux.noarch : SELinux policy modules for MySQL and MariaDB packages
mysql-server.x86_64 : The MySQL server and related files
mysql-test.x86_64 : The test suite distributed with MySQL
python3-mysql-debug.x86_64 : An interface to MySQL, built for the CPython debug runtime
soci-mysql-devel.x86_64 : MySQL back-end for soci
voms-mysql-plugin.x86_64 : VOMS server plugin for MySQL
================================================================================= Summary Matched: mysql- =================================================================================
perl-Time-Piece-MySQL.noarch : MySQL-specific methods for Time::Piece

なので、もともと有効になっているmysqlモジュールを無効化すれば

$ sudo yum module disable mysql

mysql-community-servermysql-community-clientが見えるようになります。

$ dnf search mysql-community-
Last metadata expiration check: 0:03:15 ago on 2021年11月11日 19時52分16秒.
======================================================================== Name & Summary Matched: mysql-community- =========================================================================
mysql-community-client-debuginfo.x86_64 : Debug information for package mysql-community-client
mysql-community-client-plugins-debuginfo.x86_64 : Debug information for package mysql-community-client-plugins
mysql-community-libs-debuginfo.x86_64 : Debug information for package mysql-community-libs
mysql-community-server-debug-debuginfo.x86_64 : Debug information for package mysql-community-server-debug
mysql-community-server-debuginfo.x86_64 : Debug information for package mysql-community-server
mysql-community-test-debuginfo.x86_64 : Debug information for package mysql-community-test
============================================================================= Name Matched: mysql-community- ==============================================================================
mysql-community-client.x86_64 : MySQL database client applications and tools
mysql-community-client-plugins.x86_64 : Shared plugins for MySQL client applications
mysql-community-common.x86_64 : MySQL database common files for server and client libs
mysql-community-debuginfo.x86_64 : Debug information for package mysql-community
mysql-community-debugsource.x86_64 : Debug sources for package mysql-community
mysql-community-devel.x86_64 : Development header files and libraries for MySQL database client applications
mysql-community-libs.x86_64 : Shared libraries for MySQL database client applications
mysql-community-server.x86_64 : A very fast and reliable SQL database server
mysql-community-server-debug.x86_64 : The debug version of MySQL server
mysql-community-test.x86_64 : Test suite for the MySQL database server

あとはインストール。

$ sudo dnf install mysql-community-server mysql-community-client

MySQLサーバーを起動。

$ sudo systemctl start mysqld

root@localhostが作成され、パスワードはログに記録されるそうなので

スーパーユーザーアカウント'root'@'localhost が作成されます。 スーパーユーザーのパスワードが設定され、エラーログファイルに格納されます。

確認。

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

こちらでパスワードを確認してMySQLにログインして

$ mysql -uroot -p

最初はパスワードを変えるまでは操作ができないので

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

alter userで変更します(set passwordではダメみたいです)。

mysql> alter user root@localhost identified by '[パスワード]';
Query OK, 0 rows affected (0.00 sec)

パスワード設定時は、こちらに注意ですね。

validate_password はデフォルトでインストールされます。 validate_password で実装されているデフォルトのパスワードポリシーでは、パスワードに大文字、小文字、数字および特殊文字を 1 文字以上含める必要があり、パスワードの合計長は 8 文字以上である必要があります。

こちらを守れないものは、デフォルトでは設定できません。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1