CentOS7

データベースサーバー構築(MariaDB)

データベースサーバーは、サーバー上のデータベースをクライアントから操作できるようにするためのサーバー。

ここでは、リレーショナル型データベースのデータベースサーバーであるMariaDBを使用する。

MariaDBインストール

[root@localhost ~]# yum -y install mariadb-server ← mariadb-serverインストール

MariaDB設定

[root@localhost ~]# vi /etc/my.cnf.d/server.cnf ← MariaDB設定ファイル編集
[mysqld]
character-set-server = utf8 ← 追加(MariaDBサーバーの文字コードをUTF-8にする)

MariaDB起動

[root@localhost ~]# systemctl start mariadb ← MariaDB起動
[root@localhost ~]# systemctl enable mariadb ← MariaDB自動起動設定

MariaDB初期設定

[root@localhost ~]# mysql_secure_installation ← MariaDB初期設定
/usr/bin/mysql_secure_installation: 行 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
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(rootパスワード設定)
New password: ← 任意の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]
c← 空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(リモートからのrootログイン禁止)
... 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] ← 空ENTER(testデータベース削除)
- 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!

MariaDB確認

[root@localhost ~]# mysql -u root -p ← MariaDBrootでログイン
Enter password: ← MariaDBrootパスワード応答
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
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)]> grant all privileges on test.* to hogehoge@localhost identified by 'hogehogepass'; ← testデータベースへの全てのアクセス権限を持った、新規ユーザーhogehogeを登録
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user from mysql.user where user='hogehoge'; ← hogehogeユーザー登録確認
+--------+
user
+--------+
hogehoge
+--------+
1 row in set (0.00 sec)
MariaDB [(none)]> exit ← ログアウト
Bye
[root@localhost ~]# mysql -u hogehoge -phogehogepass ← MariaDBへhogehogeユーザーでログイン
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
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)]> 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; ← testデータベースへ接続
Database changed
MariaDB [test]> create table test(num int, name varchar(50)); ← testテーブル作成
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,'山田太郎'); ← testテーブルへデータ登録
Query OK, 1 row affected, 1 warning (0.01 sec)
MariaDB [test]> select * from test; ← データ登録確認
+------+--------------+
numname
+------+--------------+
1山田太郎
+------+--------------+
1 row in set (0.00 sec)
MariaDB [test]> update test set name='山田次郎'; ← testテーブル内データ更新
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [test]> select * from test; ← データ更新確認
+------+--------------+
numname
+------+--------------+
1山田次郎
+------+--------------+
1 row in set (0.00 sec)
MariaDB [test]> delete from test where num=1; ← testテーブル内データ削除
Query OK, 1 row affected (0.03 sec)
MariaDB [test]> select * from test; ← データ削除確認
Empty set (0.00 sec)
MariaDB [test]> drop table test; ← testテーブル削除
Query OK, 0 rows affected (0.02 sec)
MariaDB [test]> show tables; ← テーブル削除確認
Empty set (0.00 sec)
MariaDB [test]> drop database test; ← データベースtest削除
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases; ← データベース削除確認
+--------------------+
Database
+--------------------+
information_schema
+--------------------+
1 row in set (0.01 sec)
MariaDB [(none)]> exit ← ログアウト
Bye
[root@localhost ~]# mysql -u root -p ← MariaDBrootでログイン
Enter password: ← MariaDBrootパスワード応答
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
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)]> revoke all privileges on *.* from hogehoge@localhost; ← hogehogeユーザーから全てのデータベースへのアクセス権限を剥奪
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> delete from mysql.user where user='hogehoge' and host='localhost'; ← hogehogeユーザー削除
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> select user from mysql.user where user='hogehoge'; ← hogehogeユーザー削除確認
Empty set (0.00 sec)
MariaDB [(none)]> flush privileges; ← hogehogeユーザーの削除をMariaDBサーバーへ反映
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit ← ログアウト
Bye

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS