MySQL5.7については、「Red Hat Enterprise Linux 7/ Oracle Linux 7 (アーキテクチャに依存しない)、RPM パッケージ」に含まれています。CentOSやRockyLinux、AlimaLinux等、どのバージョンのパッケージのリポジトリを使用してよいかは、「uname -r」コマンドでLinuxカーネルバージョンを確認することでわかる。
上記例は、「3.10.0-1160.80.1.el7.x86_64」と表示されているのでカーネルバージョンは、先頭3桁の「3.10.0」となる、それを下記のLinuxバージョンに照らしわせると、「RHEL 7.1 ~ RHEL 7.9」となっているため、使用するリポジトリは、「Red Hat Enterprise Linux 7」となる。
#Red Hat Enterprise Linux 8
wget https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
#Red Hat Enterprise Linux 7
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
#Red Hat Enterprise Linux 6
wget https://dev.mysql.com/get/mysql80-community-release-el6-7.noarch.rpm
[suna@localhost ~]$ sudo yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Comm 無効
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Comm 無効
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Comm 無効
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Comm 無効
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Comm 無効
mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8.0 Comm 無効
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Comm 無効
mysql-connectors-community/x86_64 MySQL Connectors Commu 有効: 206
mysql-connectors-community-debuginfo/x86_64 MySQL Connectors Commu 無効
mysql-connectors-community-source MySQL Connectors Commu 無効
mysql-tools-community/x86_64 MySQL Tools Community 有効: 94
mysql-tools-community-debuginfo/x86_64 MySQL Tools Community 無効
mysql-tools-community-source MySQL Tools Community 無効
mysql-tools-preview/x86_64 MySQL Tools Preview 無効
mysql-tools-preview-source MySQL Tools Preview - 無効
mysql57-community/x86_64 MySQL 5.7 Community Se 無効
mysql57-community-source MySQL 5.7 Community Se 無効
mysql80-community/x86_64 MySQL 8.0 Community Se 有効: 367
mysql80-community-debuginfo/x86_64 MySQL 8.0 Community Se 無効
mysql80-community-source MySQL 8.0 Community Se 無効
[suna@localhost ~]$
[suna@localhost ~]$ sudo yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 206
mysql-tools-community/x86_64 MySQL Tools Community 94
mysql57-community/x86_64 MySQL 5.7 Community Server 624
[suna@localhost ~]$
もしも、MySQL5.7以外の表示されたら、以下の手順を試してみる
(EL8 システムのみ) RHEL8 や Oracle Linux 8 などの EL8 ベースのシステムには、デフォルトで有効になっている MySQL モジュールが含まれています。このモジュールが無効にされていない限り、MySQL リポジトリによって提供されるパッケージがマスクされます。
$ sudo yum module disable mysql
MySQL5.7のインストール
$ sudo yum install mysql-community-server
正常にインストールされることを確認
MySQL5.7サーバーを起動する
$ sudo systemctl start mysqld
MySQL5.7サービスが起動されているか、起動状態を確認する。
$ sudo systemctl status mysqld
以下の状態であれば、正常に起動している。
[suna@localhost ~]$ sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 月 2022-11-14 19:38:13 JST; 1min 4s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 11534 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 11462 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 11537 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─11537 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
11月 14 19:38:09 localhost.localdomain systemd[1]: Starting MySQL Server...
11月 14 19:38:13 localhost.localdomain systemd[1]: Started MySQL Server.
[suna@localhost ~]$
[suna@localhost ~]$ cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[suna@localhost ~]$
[suna@localhost etc]$ sudo cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8mb4
default-storage-engine=InnoDB
max_allowed_packet=256M
transaction-isolation=READ-COMMITTED
[mysql]
default-character-set = utf8mb4
[mysqlcheck]
default-character-set = utf8mb4
[mysqladmin]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
[suna@localhost etc]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.40 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>