1. はじめに

 UMINサーバでWordpressを使うには、MySQLをソースファイルからコンパイルして設置する必要があります1。しかし、MySQLを自力で設置することはかなり大変。当サイトは、基礎医学教育研究会ノート様の記事2を参考に設置しましたが、ソフトウェアのバージョンの違い等により、悪戦苦闘の末に設置できました。このページでは、備忘録も兼ねてMySQLを設置する方法を紹介します。なお、設置した2020年4月5日時点での情報です。

2. ソフトウェアの準備

 MySQLの設置に必要なソフトウェアをダウンロードして、Windowsにインストールします。

  • FTPクライアント (File Zillaを使用3)
  • リモートログオンクライアント (Tera Tarmを使用4)

3. ソースファイル、ライブラリファイルの準備

 FTPクライアントでUMINサーバにログインして、以下のディレクトリを作ります。
 /home/account-name/public_html/usr/local/src
 そして、ダウンロードしておいた以下のファイルを、この src ディレクトリにアップロードします。

  • mysqlソースファイル (mysql-5.7.29を使用5)
  • boostライブラリファイル (boost-1.72_0を使用6)
  • ncursesライブラリファイル (ncurses-6.2を使用7)
  • opensslライブラリファイル (openssl-1.1.1fを使用8)

 Tera Tarmでログインして、以下のコマンドで src ディレクトリに移動します。(以降、ディレクトリ移動の記載は省略)

$ cd /home/account-name/public_html/usr/local/src

 以下のコマンドで、それぞれの圧縮ファイルを展開します。

$ tar xvfz mysql-5.7.29.tar.gz
$ tar xvfz boost_1_72_0.tar.gz
$ tar xvfz ncurses-6.2.tar.gz
$ tar xvfz openssl-1.1.1f.tar.gz

4. MySQLのインストール

 最近のバージョンのMySQLでは、インストールの際にopensslライブラリを要求されるようになったらしいので、以下のコマンドでインストールしておきます。

$ ./configure --prefix=/home/account-name/public_html/usr/local/openssl --openssldir=/home/account-name/public_html/usr/local/openssl shared
$ make
$ make install

 そして、MySQLを以下のコマンドでインストールします。完了まで、30分以上待ちます。

$ cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/account-name/public_html/usr/local/src/boost_1_27_0/boost -DCMAKE_INSTALL_PREFIX=/home/account-name/public_html/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=/home/account-name/public_html/usr/local/openssl
$ make && make install

5. MySQLの設定

5-1. ファイル、ディレクトリの準備

 以下の2つのファイルを作成します。

 以下を記載した .htaccess ファイルを作成します。ここで、「port_number」は、未使用のポート番号とします。

php_value mysql.default_port port_number
php_value mysql.default_socket /home/account-name/tmp/mysql.sock

 以下を記載した .my.cnf ファイルを作成します。

[client] port=port_number
socket= /home/account-name/tmp/mysql.sock

[mysqld]
port=port_number
socket= /home/account-name/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
pid-file=/home/account-name/tmp/mysql.pid
socket = /home/account-name/tmp/mysql.sock
datadir= /home/account-name/tmp/mysql_data/
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci

[mysqldump]
quick

[mysqld_safe]
log-error=/home/account-name/tmp/mysql_data/log/mysqld.log
pid-file=/home/account-name/tmp/mysql_data/mysqld/mysqld.pid

 なお、使われているポート番号は以下のコマンドで調べられるので、ここに表示されている以外の番号を指定します。

$ netstat -nat | grep LISTEN | awk '{print $4}'   

 .htaccess ファイルと.my.cnf ファイルを以下のディレクトリに転送します。
 /home/account-name/
 また、以下のディレクトリを空の状態で作成します。
 /home/account-name/tmp/

5-2. 初期化

 以下のコマンドでMySQLを初期化します。最後に表示された、「…for root@localhost: YYYyyyYYYyyy」の12桁の文字列「YYYyyyYYYyyy」が初期パスワードです(ここでは、仮に「YYYyyyYYYyyy」と書いて説明しています)。

$ /home/account-name/public_html/usr/local/mysql/bin/mysqld --initialize 

 以下のディレクトリを空の状態で作成します。
/home/account-name/tmp/mysql_data/log/
/home/account-name/tmp//mysql_data/mysqld/

 そして、以下のコマンドでMySQLを起動します。

$ /home/account-name/public_html/usr/local/mysql/support-files/mysql.server start

 以下のコマンドでMySQLにログインします。パスワードは初期パスワードを入力します。

$ /home/account-name/public_html/usr/local/mysql/bin/mysql -u root -p

 以下のコマンドで、正式のパスワードを設定します(ここでは、仮に「ZZZZZZZZZZZZ」と書いて説明しています)。

mysql> set password='ZZZZZZZZZZZZ';

 「quit;」とタイプして、一旦ログアウトします。

mysql> quit;
Bye
5-3. 初期設定

 セキュアモードでログインして、質問に回答しながら、設定を行います。設問は以下の回答で良いようです。

  1. Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
  2. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  3. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  4. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
  5. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
$ /home/account-name/public_html/usr/local/mysql/bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

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: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
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
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) : n

 ... skipping.
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 に root でログインして、データベース名とユーザ名を設定します。

 ここでは仮に、データベース名:database-name、ユーザ名:user-name、パスワード:password、として記載しているので、適宜変更してください。

$ /home/account-name/public_html/usr/local/mysql/bin/mysql -u root -p
mysql> create database database-name;

mysql> create user 'user-name'@'localhost' identified by 'password';

mysql> grant all privileges on database-name.* to 'user-name'@'localhost';

mysql> select user, host, db from mysql.db;

mysql> quit;
5-4. 設定の確認

 設定したユーザ名で再ログインして、確認します。

$ /home/account-name/public_html/usr/local/mysql/bin/mysql -u user-name -p

mysql> use database-name;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| database-name    |
+------------+
1 row in set (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | port_number |
+---------------+-------+
1 row in set (0.05 sec)

mysql> quit;

 以下のコマンドで、ローカルホストのホストネームを確認しておきます。

 ここでは hostname.umin.ac.jp だったとして記載しています。

$ hostname -f
hostname.umin.ac.jp

6. wp-config.phpへの反映

 wp-config.phpは、以下の記載とすると良いようです。

// ** MySQL 設定 - この情報はホスティング先から入手してください。 ** //
/** WordPress のためのデータベース名 */
define( 'DB_NAME', 'database-name' );

/** MySQL データベースのユーザー名 */
define( 'DB_USER', 'user-name' );

/** MySQL データベースのパスワード */
define( 'DB_PASSWORD', 'password' );

/** MySQL のホスト名 */
define( 'DB_HOST', 'hostname.umin.ac.jp:port_number' );

/** データベースのテーブルを作成する際のデータベースの文字セット */
define( 'DB_CHARSET', 'utf8' );

/** データベースの照合順序 (ほとんどの場合変更する必要はありません) */
define( 'DB_COLLATE', '' );

 アップデートやプラグインのインストールなどを自動で行うようにするために、wp-config.phpの末尾に以下の記載を追加しておくと便利なようです。

define('FTP_HOST', 'plaza.umin.ac.jp');
define('FTP_USER' , 'account-name');
define('FTP_PASS' , 'uminから通知されているパスワード');

References

  1. UMIN一般公開ホームページサービスFAQ
  2. 基礎医学教育研究会ノート(移転)
  3. FileZilla プロジェクト
  4. Tera Term プロジェクト
  5. MySQL Community Downloads
  6. Boost Downloads
  7. https://invisible-mirror.net/archives/ncurses/
  8. OpenSSL ソースコードダウンロード