[Redmine3.2構築 2/3]MariaDB10.1をCentOS6.7にソースからインストール

# 概要
CentOS6.7にRedmine環境を構築する
1. [Apache2.2をソースからインストール](https://qiita.com/fkmi/items/fe99dd6ee1867a773af9)
2. MariaDB10.1をソースからインストール（本ページ）
3. [Redmine3.2をインストール](https://qiita.com/fkmi/items/7616b3dc108d4a72e252)
## 構成
|H/S        |Name   |Version|Memo            |
|:----------|:------|------:|:---------------|
|OS         |CentOS |6.7    |                |
|Web Server |Apache |2.2.27 |ソースインストール|
|Database   |MariaDB|10.1.36|ソースインストール|
|Application|Redmime|3.2.9  |                |

## 参考手順
https://qiita.com/d-dai/items/9b20c47402a8fc5f1a6a

# 手順
### 事前準備
- MariaDB用ユーザの作成

```
# groupadd mysql
# useradd mysql -M -g mysql -s /sbin/nologin
```

- 関連ライブラリのインストール

```
# yum -y install libaio
```

### MariaDBインストール

- ダウンロード、展開

```
# cd /usr/local/src
# wget -O mariadb-10.1.36-linux-x86_64.tgz https://downloads.mariadb.org/interstitial/mariadb-10.1.36/bintar-linux-x86_64/mariadb-10.1.36-linux-x86_64.tar.gz/from/http%3A//ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/
# tar xvzf mariadb-10.1.36-linux-x86_64.tgz
```

- インストール

```
# mv mariadb-10.1.36-linux-x86_64 /usr/local/mysql
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --data=/usr/local/mysql/data
# chown -R mysql data
```

- 設定ファイル編集

```
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
# vi /etc/my.cnf
```
```/etc/my.cnf
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock
default-character-set = utf8            # ADD

[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server = utf8             # ADD

[mysqldump]
quick
max_allowed_packet = 16M
default-character-set = utf8            # ADD

[mysql]
no-auto-rehash
default-character-set = utf8            # ADD
```

- シンボリックリンクを貼る

```
# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
# ln -s /usr/local/mysql/bin/mysqldump /usr/local/bin/mysqldump
# ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config
```

- 起動、プロセス確認

```
# /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data &
Press Enter
# ps aux | grep mysql | grep -v grep
```

- パスワード設定

```
# bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):                        # Enter
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y                                               # Input & Enter
New password:password                                                    # Input PW & Enter
Re-enter new password:password                                           # Input PW & Enter
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] Y                                          # Input & Enter
 ... 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? [Y/n] Y                                    # Input & Enter
 ... Success!

By default, MariaDB 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? [Y/n] Y                           # Input & Enter
 - 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? [Y/n] Y                                     # Input & Enter
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
```

- 起動スクリプトの設定

```
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig --list mysql
```

- データベース作成

```
# mysql -uroot -prootpass
MariaDB [(none)]> CREATE database dev;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON dev.* TO 'testuser'@'localhost' IDENTIFIED BY 'password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
```

- テーブルの作成および文字コード（DEFAULT CHARSET=utf8になっているか）を確認

```
# mysql -utestuser -ppassword dev
MariaDB [dev]> create table users(userid int unsigned auto_increment primary key, name varchar(255) not null, comments text);
MariaDB [dev]> show create table users\G
MariaDB [dev]> exit
```

### 次の手順
[Redmine3.2をインストール](https://qiita.com/fkmi/items/7616b3dc108d4a72e252)