SSブログ

「MariaDB10.0」の設定、動作確認。 [MariaDB]

「MariaDB10.0」の設定、動作確認。

■「MariaDB」の初期設定。

       
[bibo-roku@centos ~]$ sudo mysql_secure_installation ←初期の設定開始。
[sudo] password for bibo-roku: 

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 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") ←エラー発生。

[bibo-roku@centos ~]$ sudo reboot ←エラー対処に再起動実施。

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] ←「空ENTERキー」※「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]  ←「空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]  ←「空ENTERキー」
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]  ←「空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] ←「空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!
       
      


 初期設定開始のコマンドを入力し設定を開始します。
「root」ユーザのパスワードを問われますが、「空のENTERキー」を押します。


「mysql.sock」に繋げられないというエラーのようです。
「/var/lib/mysql/」に見覚えがあるぞと思ったら、インストール時にそのディレクトリが無いぞと怒られていましたね。ですが、ディレクトリは作成されていました。
 しかし「mysql.sock」は見つかりませんでした。
 インターネット検索をしてみると、「ソケットファイルが削除されている場合があります。この場合、MySQLサーバーを一旦シャットダウンして再起動をかけるとソケットファイルが復元されます。」とのこと。
「CentOS」を再起動させたところ、「mysql.sock」が現れました。

 再度、初期設定を始めます。パスワード入力以外は全て「空ENTERキー」=「Yes」で進めます。

「Set root password?」→パスワードを作成しますか?
「New password:」→入力。
「Re-enter new password:」→再入力。
「Remove anonymous users?」→匿名のユーザーを削除しますか?
「Disallow root login remotely?」→リモートユーザのログインを禁止しますか?
「Remove test database and access to it? 」→テストデータベースを削除しますか?
「Reload privilege tables now?」


■設定ファイルの編集。

       
[bibo-roku@centos ~]$ sudo vi /etc/my.cnf.d/server.cnf
---省略---
# this is only for the mysqld standalone daemon
[mysqld]
character-set-server = utf8 ←一文追記。
---省略---

[bibo-roku@centos ~]$ sudo /etc/init.d/mysql restart ←反映させる。
Shutting down MySQL.. SUCCESS! 
Starting MySQL..... SUCCESS!
       
      


 漢字を扱えるようにするために「utf-8」を追記するとのこと。
 ※それ以前に作成されたデータには反映されないみたいなので漢字を扱うなら初めに設定しておく。
 また反映させるためには「MariaDB」を再起動させます。


■「MariaDB」の動作確認。

       
[bibo-roku@centos ~]$ sudo /etc/init.d/mysql start ←起動。
Starting MySQL SUCCESS!

[bibo-roku@centos ~]$ mysql -u root -p ←「root」ユーザーでログイン。
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.0.17-MariaDB MariaDB Server

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

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

MariaDB [(none)]> grant all privileges on test.* to 'bibo-roku'@localhost identified by 'bibo-rokupass'; ←新規ユーザー作成。
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user from mysql.user where user='bibo-roku';
+-----------+
| user      |
+-----------+
| bibo-roku | ←bibo-rokuの登録確認。
+-----------+
1 row in set (0.00 sec)

MariaDB [(none)]> exit ←ログアウト。
Bye

[bibo-roku@centos ~]$ mysql -u 'bibo-roku' -pbibo-rokupass ←「bibo-roku」でログイン。
---省略---

MariaDB [(none)]> create database test; ←testデータベース作成。
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               | ←確認。
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> use test;
Database changed
MariaDB [test]> ←[test]に。

MariaDB [test]> create table test(num int, name varchar(50));
Query OK, 0 rows affected (0.09 sec)

MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test           | ←確認。
+----------------+
1 row in set (0.00 sec)

MariaDB [test]> insert into test values(1,'山田太郎');
Query OK, 1 row affected (0.00 sec)

MariaDB [test]> select * from test;
+------+--------------+
| num  | name         |
+------+--------------+
|    1 | 山田太郎     | ←確認。
+------+--------------+
1 row in set (0.00 sec)

MariaDB [test]> update test set name='山田次郎';
Query OK, 1 row affected (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [test]> select * from test;
+------+--------------+
| num  | name         |
+------+--------------+
|    1 | 山田次郎     | ←変更確認。
+------+--------------+
1 row in set (0.00 sec)

MariaDB [test]> delete from test where num=1;
Query OK, 1 row affected (0.13 sec)

MariaDB [test]> select * from test;
Empty set (0.00 sec) ←「Empty」確認。

MariaDB [test]> drop table test;
Query OK, 0 rows affected (0.03 sec)

MariaDB [test]> show tables;
Empty set (0.00 sec) ←「Empty」確認。

MariaDB [test]> drop database test;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | ←確認。
+--------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> exit 
Bye

[bibo-roku@centos ~]$ mysql -u root -p
Enter password: 
---省略---
MariaDB [(none)]> revoke all privileges on *.* from 'bibo-roku'@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> delete from mysql.user where user='bibo-roku' and host='localhost';
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> select user from mysql.user where user='bibo-roku';
Empty set (0.00 sec) ←「Empty」確認。

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

       
      


 上記の「MariaDB」の動作確認は。下記サイト様の内容をそのまま実施させていただきました。ありがとうございました。
 http://centossrv.com/mariadb.shtml

 流れとしては「testデータベースへの全てのアクセス権限を持った、新規ユーザbibo-rokuを登録」※「-」ハイフンが入るユーザー名を使うときは「'」シングルクォーテーションで囲む必要があります。
「testデータベース作成」→「testデータベースに接続」→「testデータベースにテーブル作成」→「testテーブルに山田太郎登録」→「山田太郎を山田次郎に変更」→「testテーブル内データ削除」→「testテーブル削除」→「testデータベース削除」→「bibo-rokuユーザから全てのデータベースへのアクセス権限を剥奪」→「bibo-rokuの削除」→「MariaDBサーバへ反映」
 テキストで扱うのは難しそうですね……。
 調べてみると、「phpMyAdmin」というモノがあるそうです。




この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。