CentOS 7.2にMySQL 5.7.13をソースからインストール

業務ではまだまだCentOS6メインの環境なので、前回はCentOS6.7にインストールしましたが、自宅で遊ぶならCentOS7を使いたいので、今回はCentOS7.2にMySQL5.7.13をソースからインストールしてみました。
手順はほとんど同じです。CentOS7はsystemdが導入されているので、そこを確認したかったのが一番の目的です。


環境

CentOS7.2(最小構成、update済み)

 

必要なパッケージのインストール

# yum -y install wget gcc-c++ cmake ncurses-devel zlib-devel readline-devel bison

 

mysqlグループとユーザの作成

# groupadd mysql
# useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql

mysqlにスイッチできないことを確認する

# su - mysql
This account is currently not available.

 

ソースファイルのダウンロード

# cd /usr/local/src
# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

 

ソースファイル展開

# tar zxvf mysql-5.7.13.tar.gz

 

BOOSTライブラリをダウンロード

# wget  http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

確認

# pwd
/usr/local/src
# ls -l
total 131092
-rw-r--r--.  1 root root  83709983 Aug 14  2015 boost_1_59_0.tar.gz
drwxr-xr-x. 35 7161 31415     4096 May 25 15:00 mysql-5.7.13
-rw-r--r--.  1 root root  50516207 May 25 13:01 mysql-5.7.13.tar.gz

 

cmakeコマンド

# cd /usr/local/src/mysql-5.7.13

# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_BOOST=/usr/local/src

CentOS6と同じように"-DDOWNLOAD_BOOST=1"を指定すると下記のような警告がでました。

CMake Warning:
  Manually-specified variables were not used by the project:

    DOWNLOAD_BOOST


-- Build files have been written to: /usr/local/src/mysql-5.7.13

メッセージの通り今回は事前にBOOSTライブラリをダウンロードしているのでこのオプションは必要はないので、外したところWarningのメッセージは表示されませんでした。
CentOS6では特にWarningは出なかったと思いますが・・・

 

makeコマンド

# make

 

インストール

# make install

 

インストールディレクトリのオーナーとグループをmysqlにする

# chown -R mysql:mysql /usr/local/mysql

 

インストールディレクトリのパーミッションを変更

# chmod 755 /usr/local/mysql

 

設定ファイルのコピー

# mv /etc/my.cnf{,.org}
# cp -p /usr/local/src/mysql-5.7.13/support-files/my-default.cnf /etc/my.cnf

 

設定ファイルの追加

MySQLの起動確認ができればいいので、文字コードとパスワードの有効期限のパラメータだけ追加しておきます。

# vi /etc/my.cnf
[mysqld]
character-set-server = utf8
default_password_lifetime = 0

[mysql]
default-character-set = utf8

 

MySQLの初期化

# /usr/local/mysql/bin/mysqld \
--user=mysql \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/ \
--log-error-verbosity=3 \
--initialize-insecure

 

起動スクリプトのコピー

systemdに対応したUnitファイルは用意されてなそうですが、従来通り/etc/init.d配下に起動スクリプトを配置すればsystemctlコマンドで制御できるようになります。

# cp -p /usr/local/src/mysql-5.7.13/support-files/mysql.server /etc/init.d/mysql
# chown root:root /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql

 

起動スクリプトの修正

# vi /etc/init.d/mysql
# basedir=
# datadir=
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

 

MySQL起動確認

Unit定義ファイルの変更をSystemdに反映する場合は以下のコマンドを実行します。

# systemctl daemon-reload

systemctlコマンドで認識できるか確認する

# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysql)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)

起動してみる

systemctl start mysql

この段階ではまだmysqlのログの設定もしていないので、/var/log/messagesで確認するかpsコマンドでMySQLが起動していることを確認します。

view /var/log/messages
Jun 27 13:38:23 ***** mysql: Starting MySQL. SUCCESS!
# ps aux | grep mysql | grep -v grep
root      2244  0.0  0.0 115376  1680 ?        S    13:38   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/*****.pid
mysql     2377  0.0  4.5 1563156 177692 ?      Sl   13:38   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/*****.err --pid-file=/usr/local/mysql/data/*****.pid

 

パスの登録

# export PATH=$PATH:/usr/local/mysql/bin

# vi /etc/profile
# (最終行に追加)
export PATH=$PATH:/usr/local/mysql/bin

# (即時反映)
. /etc/profile

 

MySQLのセキュア設定

# /usr/local/mysql/bin/mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank 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: 0 <= 今回は0(LOW)で設定
Please set the password for root here.

New password: <= ポリシーに沿ったパスワード入力

Re-enter new 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 <= rootのリモートログイン禁止
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 -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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>

近々このWordPressをMySQL5.5から5.7へ移行しようと思います。

 

最新記事

 

参考

MySQL 5.6 ソースからCentOS7にインストール