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

MySQLの知識は5.5で止まったまま。WordPressの推奨動作環境がMySQL5.6以上であり、周りでもMySQL5.7の誕生にちょっとざわついているので、5.6はスキップして5.7で遊ぶことにしました。

 


環境

CentOS6.8(最小構成、update済み)

 

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

CentOS6の標準リポジトリでインストールされるgccは4.4.7で、これが原因でコンパイル中にwarningが頻発するので、devtools-2からCentOS7と同じgccのバージョン4.8を入れておきます。

# yum install wget
# wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
# yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++

devtools-2でインストールしたパッケージを有効化します。

# scl enable devtoolset-2 bash

バージョンとPATHを確認

# gcc --version | head -n 1
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
# which gcc
/opt/rh/devtoolset-2/root/usr/bin/gcc

# c++ --version | head -n 1
c++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
# which c++
/opt/rh/devtoolset-2/root/usr/bin/c++

 

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

# yum install cmake
# yum install ncurses-devel
# yum install zlib-devel
# yum install readline-devel
# yum install bison

まとめてインストールしてもいいです。-yオプションもお好みで。

# 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ライブラリをダウンロード

BOOSTというオープンソースライブラリが必要のようです。
cmakeコマンドでコンパイル時に"-DDOWNLOAD_BOOST=1"のオプションで自動でダウンロードしれくれますが結構タイムアウトになったりします。
デフォルトのタイムアウト600秒を"-DOWNLOAD_BOOST_TIMEOUT"オプションで変更もできそうでが、それでもタイムアウトになったりすると非常に残念な気持ちになるので、今回は事前にダウンロードしておいて"-WITH_BOOST"オプションで読み込ませるようにします。

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

※補足:必要なバージョンはソースファイル内の以下のファイルで確認できます

# vi /usr/local/src/mysql-5.7.13/cmake/boost.cmake

SET(BOOST_PACKAGE_NAME "boost_1_59_0")
SET(BOOST_TARBALL "${BOOST_PACKAGE_NAME}.tar.gz")
SET(BOOST_DOWNLOAD_URL
  "http://sourceforge.net/projects/boost/files/boost/1.59.0/${BOOST_TARBALL}"
  )

確認

# pwd
/usr/local/src
# ls
boost_1_59_0.tar.gz  mysql-5.7.13  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 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/src

 

makeコマンド

# make

 

インストール

# make install

 

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

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

 

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

# chmod 755 /usr/local/mysql

 

起動スクリプトのコピー

# 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

 

シンボリックリンク

rpm的なパスもほしければ

# ln -s /usr/local/mysql /var/lib/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

5.5からmysqldの文字コード設定が変わったので入れておく。
5.7から追加された"default_password_lifetime"はデフォルトでパスワードの有効期限が365日に設定されていて、ログイン時にパスワード変更を促されるようです。
"0"指定で無効にできる。
5.7.11からデフォルトで無効になったみたいですがおまじないで入れたい気分。

 

パスの登録

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

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

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

 

MySQLの初期化

--initializeでrootの初期パスワードあり
--initialize-insecureでrootの初期パスワードなし
今回はなしで初期化します。

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

※--initializeで(rootの初期パスワードあり)で実行した場合、初期化実行直後に流れるログに初期パスワードが流れるので確認しておきます。mysql_secure_installation(MySQLのセキュア設定)の実行で始めに聞かれます。

2016-06-24T08:38:51.987036Z 1 [Note] A temporary password is generated for root@localhost: ************

 

MySQL起動確認

# /etc/init.d/mysql start
Starting MySQL. SUCCESS!

 

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

 

メモ

冒頭でもお伝えしましたが、CentOS6の標準のgccバージョン4.4.7だとcmakeとboost_1_59_0の組み合わせで以下のようなwarningが頻発します。

/usr/local/src/mysql-5.7.13/include/boost_1_59_0/patches/boost/geometry/index/detail/rtree/pack_create.hpp:264: warning: ‘elements_box.boost::geometry::index::detail::rtree::pack<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, long unsigned int>, boost::geometry::index::detail::rtree::options<boost::geometry::index::quadratic<64ul, 19ul>, boost::geometry::index::detail::rtree::insert_default_tag, boost::geometry::index::detail::rtree::choose_by_content_diff_tag, boost::geometry::index::detail::rtree::split_default_tag, boost::geometry::index::detail::rtree::quadratic_tag, boost::geometry::index::detail::rtree::node_variant_static_tag>, boost::geometry::index::detail::translator<boost::geometry::index::indexable<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, long unsigned int> >, boost::geometry::index::equal_to<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, long unsigned int> > >, boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, boost::geometry::index::detail::rtree::allocators<std::allocator<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, long unsigned int> >, std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, long unsigned int>, boost::geometry::index::quadratic<64ul, 19ul>, boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >, boost::geometry::index::detail::rtree::node_variant_static_tag> >::expandable_box<boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> > >::m_box.boost::geometry::model::box<boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian> >::m_min_corner.boost::geometry::model::point<double, 2ul, boost::geometry::cs::cartesian>::m_values[0ul]’ may be used uninitialized in this function
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-unused-local-typedefs"

バグとして報告されているようです。
Bug #79338:gcc 4.4 include boost1.5.9 indicating that parameter is uninitialized
gcc/c++のバージョンを4.8に上げてこちらの問題は解決しました。

 

最新記事

 

参考

MySQLサーバ構築手順(CentOS 6.6にMySQL 5.7.5をソースからインストールする)
MYSQL5.7.11をソースからインストールする時にハマったこと
CentOS6.5にdevtoolset-2を使ってgcc4.8をインストールする