MariaDB(5.5)をCentOS(6.3)にインストール

# yum設定
[MariaDB - Setting up MariaDB Repositories - MariaDB](https://downloads.mariadb.org/mariadb/repositories/)
上記でyumの設定を表示してもらう。
今回は`CentOS`→`CentOS 6(32bit)`→`5.5`

```bash
# MariaDB 5.5 CentOS repository list - created 2014-05-18 13:36 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
```

rootになって、MariaDB用のrepoファイルを新規作成して、設定をコピペする。

```bash
root$ vim /etc/yum.repos.d/MariaDB.repo
```

# GPG鍵をインポート
```bash
root$ rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
```
さっきのyum設定に`gpgkey=...`とあるからやるんだよーと公式サイトが言っていた。
あとyumでもGPG鍵をインポート出来るらしいけどもやり方がわからないのでrpmで。

# インストール
公式見たらsudoでやってたのでやっぱsudoでやることにするー。

```bash
$ sudo yum install -y MariaDB-server MariaDB-client MariaDB-devel
```
※`MariaDB-devel`を追記。多分いけるはず。
5分くらい？問題なくcomplete！
標準出力ログ見たら、

```bash
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'
```
なんかMariaDB用にrootユーザをセッティングしなきゃいけないらしいですね。

# 設定
## MariaDB server用
やらなきゃいけないらしい？

```bash
$ sudo vim /etc/my.cnf.d/server.cnf

---
..
[mysqld]
character-set-server=utf8 # ←追記
..
---
```

## rootのパスワード設定とか
さっきのやつ。
### まず起動

```bash
$ sudo /etc/init.d/mysql start
Starting MySQL... SUCCESS!
$ 
```
ほう。

### パスワード等セット
```bash
$ '/usr/bin/mysql_secure_installation'
```

以下やりとりログ。

```
$ '/usr/bin/mysql_secure_installation'
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: コマンドが見つかりません

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を押すらしい。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) # ←事前にパスワード設定しちゃってたので今回はそれを入力。初回は多分出てこない。
Enter current password for root (enter for none):
OK, successfully used password, moving on...

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

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] Y ←Yを入力してEnter
New password: ←MariaDBログイン時のrootのパスワードを入力
Re-enter new password: ←もういっかい入力
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 ←Yを入力して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 ←Yを入力して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 ←Yを入力して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 ←Yを入力して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!
$
```

# 接続してみる
MariaDB用rootユーザで接続してみる。mysqlコマンドでつなぐのねー

```bash
$ mysql -u root -p
Enter password: ←上で設定したパスワード
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
```

とりあえずおっけーぽい！

# 参考
* [CentOS 6.4 に MariaDB 5.5 をインストールする](http://d.hatena.ne.jp/akishin999/20130625/1372114954)
* [Installing MariaDB with yum](https://mariadb.com/kb/en/installing-mariadb-with-yum/)
* [[CentOS] MySQLサーバーのインストールを行うの巻　～mysql_secure_installationを使ってみよう～](http://blog.trippyboy.com/2013/mysql/centos-mysql%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%82%92%E8%A1%8C%E3%81%86%E3%81%AE%E5%B7%BB%E3%80%80%EF%BD%9Emysql_secure_installatio/)