LoginSignup
7
10

More than 5 years have passed since last update.

CentOS7にMariaDBいれたよ

Last updated at Posted at 2018-05-05

Ruby on Rails5いれたいから先にDBのインストール。
MySQLか迷ったけど、centOS7だしということでMariaDBにした。
忘れないようにキロク。

環境

OS:centOS7

インストールから起動までの手順

1.mariadbインストール

コマンド
# インストール
$ yum install mariadb mariadb-server

# インストール済みパッケージ一覧からmariadb確認
$ rpm -qa | grep -i mariadb

---- 入ったもの ----
mariadb-libs-5.5.56-2.el7.x86_64
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64

2.my.cnfで文字コード指定

コマンド
$ vi /etc/my.cnf 

# [mysqld]の中に記述
[mysqld]
character-set-server=utf8 

3.MariaDB起動

serviceコマンドってわかりやすかったなーって思いながら、systemctlでスタート。

コマンド
$ systemctl start mariadb 

怒られた

エラー
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

エラーおきて起動できないって言われた。
指示通り[journalctl -xe]叩いてみる。
で、[ERROR]のとこ見てみる。

エラー
[ERROR] /usr/libexec/mysqld: unknown variable 'aracter-set-server=utf8'

あ、さっき追記した[character・・・]のcが抜けてる・・・。
もう1度編集して、再度スタート。
なにも言われなかったので、status確認。

コマンド
$ systemctl status mariadb 

--- 結果 ---
Active: active (running) ...

今度は無事に起動できた。
それにしても、いつまでたってもこういう所は治らない。
でも、エラー起きてもちゃんと原因究明できるようになったというか、文章をちゃんと読む気になったというか・・・うん、多分成長はしてるはず。

起動できたので、自動起動設定も有効にする。

コマンド
$ systemctl enable mariadb

4.mariaDB初期設定

コマンド
$ 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):
OK, successfully used password, moving on...

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

# rootパスワード設定するか
Set root password? [Y/n] y
New password: パスワード入力
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
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

# rootのリモートログインは無効にするか
Disallow root login remotely? [Y/n] y
 ... 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.

# デフォルトの[test]データベースは削除するか
Remove test database and access to it? [Y/n] 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? [Y/n] y
 ... 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!

5.mariaDBにログインしてみる

コマンド
$ mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server

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

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

MariaDB [(none)]>

無事にログインできました
おしまい。

2018/05/05 追記

5.5って全然最新じゃなかったので、入れた直後にアップデートしました
centOS7にいれたMariaDB5.5をv10.2にアップデートしたよ

7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10