haiju's 開発メモ

開発に必要な情報を自分用にメモ

Win7(x64)のVMのCentOS7.2(x64)にMariaDBを再インストール

CentOS7.2(x64)にMariaDBのバージョンを上げて

再インストールしてCakePHP2.xのテストで使える

ようにした。

[手順]

1. MariaDBのバージョンを確認して、5.5.xだったら削除。

# root at localhost.localdomain in ~ [12:14:30]
rpm -qa | grep -i "mariadb"
mariadb-5.5.50-1.el7_2.x86_64
mariadb-server-5.5.50-1.el7_2.x86_64
mariadb-libs-5.5.50-1.el7_2.x86_64

※5.5.xなので削除を実行。

mariadb自動起動設定している場合は、予め解除。

# root at localhost.localdomain in ~ [12:14:43]

yum remove mariadb mariadb-libs
読み込んだプラグイン:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ mariadb.x86_64 1:5.5.50-1.el7_2 を 削除
--> 依存性の処理をしています: mariadb(x86-64) = 1:5.5.50-1.el7_2 のパッケージ: 1:mariadb-server-5.5.50-1.el7_2.x86_64
---> パッケージ mariadb-libs.x86_64 1:5.5.50-1.el7_2 を 削除
--> 依存性の処理をしています: libmysqlclient.so.18()(64bit) のパッケージ: perl-DBD-MySQL-4.023-5.el7.x86_64
--> 依存性の処理をしています: libmysqlclient.so.18()(64bit) のパッケージ: 2:postfix-2.10.1-6.el7.x86_64
--> 依存性の処理をしています: libmysqlclient.so.18(libmysqlclient_18)(64bit) のパッケージ: perl-DBD-MySQL-4.023-5.el7.x86_64
--> 依存性の処理をしています: libmysqlclient.so.18(libmysqlclient_18)(64bit) のパッケージ: 2:postfix-2.10.1-6.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ mariadb-server.x86_64 1:5.5.50-1.el7_2 を 削除
---> パッケージ perl-DBD-MySQL.x86_64 0:4.023-5.el7 を 削除
---> パッケージ postfix.x86_64 2:2.10.1-6.el7 を 削除
--> 依存性の処理をしています: /usr/sbin/sendmail のパッケージ: redhat-lsb-core-4.1-27.el7.centos.1.x86_64
--> 新しい変更と依存性の解決を再開しています。
--> トランザクションの確認を実行しています。
---> パッケージ redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1 を 削除
--> 依存性の処理をしています: redhat-lsb-core(x86-64) = 4.1-27.el7.centos.1 のパッケージ: redhat-lsb-languages-4.1-27.el7.centos.1.x86_64
--> 依存性の処理をしています: redhat-lsb-core(x86-64) = 4.1-27.el7.centos.1 のパッケージ: redhat-lsb-cxx-4.1-27.el7.centos.1.x86_64
--> 依存性の処理をしています: redhat-lsb-core(x86-64) = 4.1-27.el7.centos.1 のパッケージ: redhat-lsb-4.1-27.el7.centos.1.x86_64
--> 依存性の処理をしています: redhat-lsb-core(x86-64) = 4.1-27.el7.centos.1 のパッケージ: redhat-lsb-printing-4.1-27.el7.centos.1.x86_64
--> 依存性の処理をしています: redhat-lsb-core(x86-64) = 4.1-27.el7.centos.1 のパッケージ: redhat-lsb-desktop-4.1-27.el7.centos.1.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ redhat-lsb.x86_64 0:4.1-27.el7.centos.1 を 削除
--> 依存性の処理をしています: lsb >= 4.0 のパッケージ: google-chrome-stable-54.0.2840.100-1.x86_64
---> パッケージ redhat-lsb-cxx.x86_64 0:4.1-27.el7.centos.1 を 削除
---> パッケージ redhat-lsb-desktop.x86_64 0:4.1-27.el7.centos.1 を 削除
---> パッケージ redhat-lsb-languages.x86_64 0:4.1-27.el7.centos.1 を 削除
---> パッケージ redhat-lsb-printing.x86_64 0:4.1-27.el7.centos.1 を 削除
--> トランザクションの確認を実行しています。
---> パッケージ google-chrome-stable.x86_64 0:54.0.2840.100-1 を 削除
--> 依存性解決を終了しました。
base/7/x86_64 | 3.6 kB 00:00:00
base/7/x86_64/group_gz | 155 kB 00:00:00
base/7/x86_64/primary_db | 5.6 MB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
extras/7/x86_64/primary_db | 183 kB 00:00:00
google-chrome | 951 B 00:00:00
google-chrome/primary | 2.0 kB 00:00:00
remi-safe | 2.9 kB 00:00:00
remi-safe/primary_db | 897 kB 00:00:03
updates/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 1.3 MB 00:00:00

依存性を解決しました

======================================================================================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
======================================================================================================================================================================================
削除中:
mariadb x86_64 1:5.5.50-1.el7_2 @updates 49 M
mariadb-libs x86_64 1:5.5.50-1.el7_2 @updates 4.4 M
依存性関連での削除をします:
google-chrome-stable x86_64 54.0.2840.100-1 @/google-chrome-stable_current_x86_64 170 M
mariadb-server x86_64 1:5.5.50-1.el7_2 @updates 56 M
perl-DBD-MySQL x86_64 4.023-5.el7 @base 323 k
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M
redhat-lsb x86_64 4.1-27.el7.centos.1 @base 0.0
redhat-lsb-core x86_64 4.1-27.el7.centos.1 @base 45 k
redhat-lsb-cxx x86_64 4.1-27.el7.centos.1 @base 0.0
redhat-lsb-desktop x86_64 4.1-27.el7.centos.1 @base 0.0
redhat-lsb-languages x86_64 4.1-27.el7.centos.1 @base 814
redhat-lsb-printing x86_64 4.1-27.el7.centos.1 @base 0.0

トランザクションの要約
======================================================================================================================================================================================
削除 2 パッケージ (+10 個の依存関係のパッケージ)

インストール容量: 291 M
上記の処理を行います。よろしいでしょうか? [y/N]y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
削除中 : 1:mariadb-server-5.5.50-1.el7_2.x86_64 1/12
警告: /var/log/mariadb/mariadb.log は /var/log/mariadb/mariadb.log.rpmsave として保存されました。
警告: /etc/my.cnf.d/server.cnf は /etc/my.cnf.d/server.cnf.rpmsave として保存されました。
削除中 : google-chrome-stable-54.0.2840.100-1.x86_64 2/12
削除中 : redhat-lsb-4.1-27.el7.centos.1.x86_64 3/12
削除中 : redhat-lsb-cxx-4.1-27.el7.centos.1.x86_64 4/12
削除中 : redhat-lsb-desktop-4.1-27.el7.centos.1.x86_64 5/12
削除中 : redhat-lsb-languages-4.1-27.el7.centos.1.x86_64 6/12
削除中 : redhat-lsb-printing-4.1-27.el7.centos.1.x86_64 7/12
削除中 : redhat-lsb-core-4.1-27.el7.centos.1.x86_64 8/12
削除中 : 2:postfix-2.10.1-6.el7.x86_64 9/12
削除中 : 1:mariadb-5.5.50-1.el7_2.x86_64 10/12
削除中 : perl-DBD-MySQL-4.023-5.el7.x86_64 11/12
削除中 : 1:mariadb-libs-5.5.50-1.el7_2.x86_64 12/12
警告: /etc/my.cnf は /etc/my.cnf.rpmsave として保存されました。
検証中 : 1:mariadb-server-5.5.50-1.el7_2.x86_64 1/12
検証中 : google-chrome-stable-54.0.2840.100-1.x86_64 2/12
検証中 : redhat-lsb-desktop-4.1-27.el7.centos.1.x86_64 3/12
検証中 : redhat-lsb-4.1-27.el7.centos.1.x86_64 4/12
検証中 : 1:mariadb-libs-5.5.50-1.el7_2.x86_64 5/12
検証中 : redhat-lsb-languages-4.1-27.el7.centos.1.x86_64 6/12
検証中 : 2:postfix-2.10.1-6.el7.x86_64 7/12
検証中 : redhat-lsb-core-4.1-27.el7.centos.1.x86_64 8/12
検証中 : perl-DBD-MySQL-4.023-5.el7.x86_64 9/12
検証中 : 1:mariadb-5.5.50-1.el7_2.x86_64 10/12
検証中 : redhat-lsb-printing-4.1-27.el7.centos.1.x86_64 11/12
検証中 : redhat-lsb-cxx-4.1-27.el7.centos.1.x86_64 12/12

削除しました:
mariadb.x86_64 1:5.5.50-1.el7_2 mariadb-libs.x86_64 1:5.5.50-1.el7_2

依存性の削除をしました:
google-chrome-stable.x86_64 0:54.0.2840.100-1 mariadb-server.x86_64 1:5.5.50-1.el7_2 perl-DBD-MySQL.x86_64 0:4.023-5.el7
postfix.x86_64 2:2.10.1-6.el7 redhat-lsb.x86_64 0:4.1-27.el7.centos.1 redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1
redhat-lsb-cxx.x86_64 0:4.1-27.el7.centos.1 redhat-lsb-desktop.x86_64 0:4.1-27.el7.centos.1 redhat-lsb-languages.x86_64 0:4.1-27.el7.centos.1
redhat-lsb-printing.x86_64 0:4.1-27.el7.centos.1

完了しました!

2. 再度、検索コマンドを試して何も表示されなければ削除完了。

# root at localhost.localdomain in ~ [12:16:39]
rpm -qa | grep -i "mariadb"  

3.  新しいパッケージをインストールするため、MariaDB yum リポジトリの追加。

 ※CentOS7用のリポジトリ(MariaDB stable 10.1)を追加。

# vim /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

4.  MariaDBインストール。

 ※--enablerepo=mariadb オプション付きで MariaDBをインストール。

 # root at localhost.localdomain in ~ [12:21:28]

yum -y install --enablerepo=mariadb MariaDB-common MariaDB-devel MariaDB-shared MariaDB-compat MariaDB-server MariaDB-client
読み込んだプラグイン:fastestmirror, langpacks
mariadb | 2.9 kB 00:00:00
mariadb/primary_db FAILED % [============================================================== ] 0.1 B/s | 17 kB 05:14:34 ETA
http://yum.mariadb.org/10.1/centos7-amd64/repodata/279f31f6ee542a2530c273a4c1ce9bab9abe7f50b9f63502d61b46548a3fe008-primary.sqlite.bz2: [Errno 12] Timeout on http://yum.mariadb.org/10.1/centos7-amd64/repodata/279f31f6ee542a2530c273a4c1ce9bab9abe7f50b9f63502d61b46548a3fe008-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
他のミラーを試します。
mariadb/primary_db FAILED % [=================================================================-] 0.3 B/s | 18 kB 00:01:00 ETA
http://yum.mariadb.org/10.1/centos7-amd64/repodata/279f31f6ee542a2530c273a4c1ce9bab9abe7f50b9f63502d61b46548a3fe008-primary.sqlite.bz2: [Errno 12] Timeout on http://yum.mariadb.org/10.1/centos7-amd64/repodata/279f31f6ee542a2530c273a4c1ce9bab9abe7f50b9f63502d61b46548a3fe008-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
他のミラーを試します。
mariadb/primary_db | 18 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: ftp.riken.jp
* remi-safe: mirror.bebout.net
* updates: ftp.riken.jp
google-chrome 3/3
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ MariaDB-client.x86_64 0:10.1.20-1.el7.centos を インストール
---> パッケージ MariaDB-common.x86_64 0:10.1.20-1.el7.centos を インストール
---> パッケージ MariaDB-compat.x86_64 0:10.1.20-1.el7.centos を インストール
---> パッケージ MariaDB-devel.x86_64 0:10.1.20-1.el7.centos を インストール
---> パッケージ MariaDB-server.x86_64 0:10.1.20-1.el7.centos を インストール
--> 依存性の処理をしています: galera のパッケージ: MariaDB-server-10.1.20-1.el7.centos.x86_64
--> 依存性の処理をしています: libjemalloc.so.1()(64bit) のパッケージ: MariaDB-server-10.1.20-1.el7.centos.x86_64
---> パッケージ MariaDB-shared.x86_64 0:10.1.20-1.el7.centos を インストール
--> トランザクションの確認を実行しています。
---> パッケージ galera.x86_64 0:25.3.19-1.rhel7.el7.centos を インストール
--> 依存性の処理をしています: libboost_program_options.so.1.53.0()(64bit) のパッケージ: galera-25.3.19-1.rhel7.el7.centos.x86_64
---> パッケージ jemalloc.x86_64 0:3.6.0-1.el7 を インストール
--> トランザクションの確認を実行しています。
---> パッケージ boost-program-options.x86_64 0:1.53.0-26.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

======================================================================================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
======================================================================================================================================================================================
インストール中:
MariaDB-client x86_64 10.1.20-1.el7.centos mariadb 39 M
MariaDB-common x86_64 10.1.20-1.el7.centos mariadb 43 k
MariaDB-compat x86_64 10.1.20-1.el7.centos mariadb 1.4 M
MariaDB-devel x86_64 10.1.20-1.el7.centos mariadb 6.6 M
MariaDB-server x86_64 10.1.20-1.el7.centos mariadb 100 M
MariaDB-shared x86_64 10.1.20-1.el7.centos mariadb 1.3 M
依存性関連でのインストールをします:
boost-program-options x86_64 1.53.0-26.el7 base 156 k
galera x86_64 25.3.19-1.rhel7.el7.centos mariadb 8.0 M
jemalloc x86_64 3.6.0-1.el7 mariadb 104 k

トランザクションの要約
======================================================================================================================================================================================
インストール 6 パッケージ (+3 個の依存関係のパッケージ)

総ダウンロード容量: 157 M
インストール容量: 688 M
Downloading packages:
警告: /var/cache/yum/x86_64/7/mariadb/packages/MariaDB-10.1.20-centos7-x86_64-common.rpm: ヘッダー V4 DSA/SHA1 Signature、鍵 ID 1bb943db: NOKEY ] 0.0 B/s | 0 B --:--:-- ETA
MariaDB-10.1.20-centos7-x86_64-common.rpm の公開鍵がインストールされていません
(1/9): MariaDB-10.1.20-centos7-x86_64-common.rpm | 43 kB 00:00:00
(2/9): MariaDB-10.1.20-centos7-x86_64-compat.rpm | 1.4 MB 00:00:01
(3/9): MariaDB-10.1.20-centos7-x86_64-devel.rpm | 6.6 MB 00:00:03
(4/9): MariaDB-10.1.20-centos7-x86_64-client.rpm | 39 MB 00:00:45
(5/9): boost-program-options-1.53.0-26.el7.x86_64.rpm | 156 kB 00:00:00
(6/9): MariaDB-10.1.20-centos7-x86_64-shared.rpm | 1.3 MB 00:00:03
(7/9): galera-25.3.19-1.rhel7.el7.centos.x86_64.rpm | 8.0 MB 00:00:06
(8/9): jemalloc-3.6.0-1.el7.x86_64.rpm | 104 kB 00:00:01
(9/9): MariaDB-10.1.20-centos7-x86_64-server.rpm | 100 MB 00:01:31
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計 1.6 MB/s | 157 MB 00:01:38
https://yum.mariadb.org/RPM-GPG-KEY-MariaDB から鍵を取得中です。
Importing GPG key 0x1BB943DB:
Userid : "MariaDB Package Signing Key <package-signing-key@mariadb.org>"
Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : MariaDB-common-10.1.20-1.el7.centos.x86_64 1/9
インストール中 : MariaDB-client-10.1.20-1.el7.centos.x86_64 2/9
インストール中 : boost-program-options-1.53.0-26.el7.x86_64 3/9
インストール中 : galera-25.3.19-1.rhel7.el7.centos.x86_64 4/9
インストール中 : jemalloc-3.6.0-1.el7.x86_64 5/9
インストール中 : MariaDB-server-10.1.20-1.el7.centos.x86_64 6/9
インストール中 : MariaDB-shared-10.1.20-1.el7.centos.x86_64 7/9
インストール中 : MariaDB-devel-10.1.20-1.el7.centos.x86_64 8/9
インストール中 : MariaDB-compat-10.1.20-1.el7.centos.x86_64 9/9
検証中 : MariaDB-shared-10.1.20-1.el7.centos.x86_64 1/9
検証中 : MariaDB-server-10.1.20-1.el7.centos.x86_64 2/9
検証中 : jemalloc-3.6.0-1.el7.x86_64 3/9
検証中 : MariaDB-common-10.1.20-1.el7.centos.x86_64 4/9
検証中 : galera-25.3.19-1.rhel7.el7.centos.x86_64 5/9
検証中 : boost-program-options-1.53.0-26.el7.x86_64 6/9
検証中 : MariaDB-devel-10.1.20-1.el7.centos.x86_64 7/9
検証中 : MariaDB-compat-10.1.20-1.el7.centos.x86_64 8/9
検証中 : MariaDB-client-10.1.20-1.el7.centos.x86_64 9/9

インストール:
MariaDB-client.x86_64 0:10.1.20-1.el7.centos MariaDB-common.x86_64 0:10.1.20-1.el7.centos MariaDB-compat.x86_64 0:10.1.20-1.el7.centos MariaDB-devel.x86_64 0:10.1.20-1.el7.centos
MariaDB-server.x86_64 0:10.1.20-1.el7.centos MariaDB-shared.x86_64 0:10.1.20-1.el7.centos

依存性関連をインストールしました:
boost-program-options.x86_64 0:1.53.0-26.el7 galera.x86_64 0:25.3.19-1.rhel7.el7.centos jemalloc.x86_64 0:3.6.0-1.el7

完了しました!

 ※上記コマンドでインストールを完了したら、以下コマンドでインストール

 されたバージョンを検索して確認。

# rpm -qa | grep "MariaDB"

# root at localhost.localdomain in ~ [12:29:28]
rpm -qa | grep "MariaDB"
MariaDB-client-10.1.20-1.el7.centos.x86_64
MariaDB-devel-10.1.20-1.el7.centos.x86_64
MariaDB-shared-10.1.20-1.el7.centos.x86_64
MariaDB-server-10.1.20-1.el7.centos.x86_64
MariaDB-common-10.1.20-1.el7.centos.x86_64
MariaDB-compat-10.1.20-1.el7.centos.x86_64

5. MariaDBの初期設定。

 デフォルト設定ファイルは、/etc/my.cnf だが、中身は空っぽで、

 /etc/my.cnf.d/ 配下の設定ファイルをincludeするようになっている。

 ※/etc/my.cnf を確認。

# root at localhost.localdomain in ~ [12:36:27]
→ cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

※/etc/my.cnf.d/ を確認。

# root at localhost.localdomain in ~ [12:32:40]
→ ls -al /etc/my.cnf.d
合計 40
drwxr-xr-x. 2 root root 4096 1月 11 12:29 .
drwxr-xr-x. 142 root root 8192 1月 11 12:32 ..
-rw-r--r-- 1 root root 295 12月 15 04:26 client.cnf
-rw-r--r-- 1 root root 763 12月 15 04:26 enable_encryption.preset
-rw-r--r-- 1 root root 232 12月 15 04:26 mysql-clients.cnf
-rw-r--r-- 1 root root 1080 12月 15 04:26 server.cnf
-rw-r--r-- 1 root root 770 11月 17 10:36 server.cnf.rpmsave
-rw-r--r-- 1 root root 285 12月 15 04:26 tokudb.cnf

※/etc/my.cnf.d/ ディレクトリ内にあるファイルの中身も同じく、ほとんど設定

 されていないので、/usr/share/mysql/ から設定ファイルをコピー。

※ここでは、my-small.cnf を流用して、MariaDBを最小構成で設定。

# root at localhost.localdomain in ~ [12:37:20]
→ ls -al /usr/share/mysql/my-*.cnf
-rw-r--r-- 1 root root 4920 12月 15 08:51 /usr/share/mysql/my-huge.cnf
-rw-r--r-- 1 root root 20438 12月 15 08:51 /usr/share/mysql/my-innodb-heavy-4G.cnf
-rw-r--r-- 1 root root 4907 12月 15 08:51 /usr/share/mysql/my-large.cnf
-rw-r--r-- 1 root root 4920 12月 15 08:51 /usr/share/mysql/my-medium.cnf
-rw-r--r-- 1 root root 2846 12月 15 08:51 /usr/share/mysql/my-small.cnf

# root at localhost.localdomain in ~ [12:41:16]
→ cp -p /usr/share/mysql/my-small.cnf /etc/my.cnf.d/server.cnf

※文字化けしないように少なくとも [client] と [mysqld] に UTF-8 を設定。

# root at localhost.localdomain in ~ [12:47:31]
vim /etc/my.cnf.d/server.cnf

[client]以下に下記を追加
default-character-set = utf8

[mysqld]以下に下記を追加
character-set-server = utf8

[mysqldump]以下に下記を追加
default-character-set=utf8

[mysql]以下に下記を追加
default-character-set=utf8

MariaDB をインストールするとデフォルトで /var/lib/mysql が作成

 されるが、もしディレクトリが存在していなかったら作成。

※存在するので、下記の通り。

# root at localhost.localdomain in ~ [12:50:50]

→ ls -al /var/lib/mysql
合計 28712
drwxr-xr-x 6 mysql mysql 4096 1月 11 12:29 .
drwxr-xr-x. 61 root root 4096 1月 11 10:22 ..
-rw-rw---- 1 mysql mysql 16384 1月 11 09:50 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 1月 11 09:50 aria_log_control
-rw-rw---- 1 mysql mysql 5242880 1月 11 09:50 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 11月 14 17:11 ib_logfile1
-rw-rw---- 1 mysql mysql 18874368 1月 11 09:50 ibdata1
drwx------ 2 mysql mysql 4096 11月 18 19:27 live_spms_cake2
-rw-r----- 1 mysql mysql 0 1月 11 12:29 localhost.localdomain.err
drwx------ 2 mysql mysql 4096 11月 14 17:11 mysql
drwx------ 2 mysql mysql 4096 11月 14 17:11 performance_schema
drwx------ 2 mysql mysql 6 11月 14 18:16 test

6. mysql_secure_installation を用いたセキュリティ設定。

 初期状態だと テスト用のデータベース、 アノニマスユーザ (匿名の

 ログインユーザ) 等、不要なものが入っているため、キレイな状態に

 しておく。

6-1) MariaDB サービス有効化、及びサービス開始。

  [MariaDB サービス登録・起動]

# root at localhost.localdomain in ~ [12:51:20]
→ systemctl enable mariadb.service

# root at localhost.localdomain in ~ [12:54:36]
→ systemctl start mariadb.service

# root at localhost.localdomain in ~ [12:55:01]
→ ps -ef | grep "mysql" | grep -v "grep"
mysql 9423 1 1 12:54 ? 00:00:00 /usr/sbin/mysqld

6-2) MariaDB セキュリティ設定

 前回の設定が残っていたため省略。

7. CakePHP 2.xのテスト環境用のユーザを再作成。

7-1) rootでログインしてユーザcake2の状態を確認。

# user at localhost.localdomain in ~ [15:18:53]

mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> SELECT user,host FROM mysql.user;
+-------+-----------+
| user | host       |
+-------+-----------+
| cake2 | %        | 
| root | 127.0.0.1 |
| root | ::1          |
| root | localhost |
+-------+-----------+
4 rows in set (0.00 sec)

7-2) ユーザcake2がlocalhostを参照してないので削除。

MariaDB [(none)]> DROP USER cake2;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT user,host FROM mysql.user;
+------+-----------+
| user | host   |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1    |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)

7-3) 改めて新規ユーザcake2の追加。

(ex)新規ユーザの追加
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO username@localhost IDENTIFIED BY "PASSWORD" WITH GRANT OPTION;

※上記例を参考に追加。

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO cake2@localhost IDENTIFIED BY "cake2" WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT user,host FROM mysql.user;
+-------+-----------+
| user | host   |
+-------+-----------+
| root | 127.0.0.1 |
| root | ::1    |
| cake2 | localhost |
| root | localhost |
+-------+-----------+
4 rows in set (0.00 sec)

7-4) 作成したユーザでログインし直す。

MariaDB [(none)]> quit
Bye

# user at localhost.localdomain in ~ [15:32:46]
mysql -u cake2 -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;

 [参考サイト]

server.etutsplus.com

okdtsk.hateblo.jp

www.vultr.com

tikuflower.blogspot.jp