環境
インストールを行った環境は、以下の通りです。
- OS:CentOS 7.4
インストールするものは、以下です。
- MySQL 5.6
事前準備
mariaDB(MySQL互換のDBサーバ)がインストールされている場合は、削除しておきます。
# rpm -qa | grep -i maria
mariadb-libs-5.5.56-2.el7.x86_64
# yum remove mariadb-libs
# rm -rf /usr/lib64/mysql/
MySQL 公式 yum リポジトリの追加
CentOS 7の標準yumリポジトリでは MySQL が提供されていないので、MySQL公式のyumリポジトリを使います。
さっそく、MySQL公式のyumリポジトリを追加しましょう。
# yum install http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
結果を確認してみます。
MySQL 5.5~5.7までのバージョンが見えていて、5.7 が enabled となっていますね。
# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 94
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 78
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - S disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - S disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 327
mysql57-community-source MySQL 5.7 Community Server - S disabled
インストールするバージョンの切り替え
基本的には、最新バージョンをインストールすればいいと思いますが、何らかの理由で古いバージョンをインストールしたい場合は、以下のように有効なバージョンを変更することができます。
今回は、諸般の事情により、5.7 を disabled にして 5.6 を enabled にしました。
# yum -y install yum-utils
# yum-config-manager --disable mysql57-community
# yum-config-manager --enable mysql56-community
# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 94
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 78
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - S disabled
mysql56-community/x86_64 MySQL 5.6 Community Server enabled: 512
mysql56-community-source MySQL 5.6 Community Server - S disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - S disabled
MySQL のインストール
続いて、MySQLをインストールします。
yumコマンドでさっとインストールできます。
5.6.44 というバージョンがインストールされました。
# yum -y install mysql-community-server
# mysqld -V
mysqld Ver 5.6.44 for Linux on x86_64 (MySQL Community Server (GPL))
# mysql -V
mysql Ver 14.14 Distrib 5.6.44, for Linux (x86_64) using EditLine wrapper
自動起動設定
MySQLをインストールしたら、自動起動の設定を行っておきます。
# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
systemctlコマンドではなく、chkconfigコマンドを使えとのことなので、そうしました。
# chkconfig mysqld on
# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
起動
では MySQL を起動してみましょう。
# systemctl start mysqld
# ps -ef | grep mysqld
root 3599 1 0 19:31 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 3803 3599 7 19:31 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
無事に起動しました。
自動起動設定はchkconfigコマンドを使う必要がありましたが、プロセス起動はserviceコマンドではなくsystemctlコマンドで問題なさそうです。