0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MariaDBインストールと使い方メモ

Last updated at Posted at 2021-01-29

MariaDBをインストールして、ログインするまで

忘れないように自分用の備忘録

MariaDBのインストール

yumでインストール

yumでMariaDBサーバをインストールする。

# yum install mariadb-server mariadb-devel

MariaDBの起動

サービスとして起動可能とする

# systemctl enable mariadb
# systemctl start mariadb
# systemctl status mariadb

セキュリテイ

最初にセキュリティ設定をやっておく。

# mysql_secure_installation

MariaDBの初期設定

DBの文字コードをlatenからUTF8に変更

DB作成時に毎回UTF指定する方法でも良いが、全体で設定しておくと楽。

/etc/my.cnf.d/mariadb-server.cnf.org

[ ~]# diff -u /etc/my.cnf.d/mariadb-server.cnf.org /etc/my.cnf.d/mariadb-server.cnf
--- /etc/my.cnf.d/mariadb-server.cnf.org        2020-12-23 01:46:21.000000000 +0900
+++ /etc/my.cnf.d/mariadb-server.cnf    2021-01-29 22:38:15.832472193 +0900
@@ -8,6 +8,8 @@
 # this is read by the standalone daemon and embedded servers
 [server]
+character-set-server=utf8
+
 # this is only for the mysqld standalone daemon

変更したら再起動

[ ~]# systemctl restart mariadb.service

文字コード確認


[ ~]# mysql -u root

MariaDB [(none)]> show variables like "character%";
+--------------------------+------------------------------+
| Variable_name            | Value                        |
+--------------------------+------------------------------+
| character_set_client     | utf8                         |
| character_set_connection | utf8                         |
| character_set_database   | utf8   *UTFに変わってる       |
| character_set_filesystem | binary                       |
| character_set_results    | utf8                         |
| character_set_server     | utf8                         |
| character_set_system     | utf8                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.001 sec)

色々とDBを見るコマンドたち

DBの一覧

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| my_db              |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)

DBアクセスしてテーブルの一覧確認

MariaDB [(none)]> use mysql
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
| event                     |
| func                      |
(省略)

テーブル定義の確認

MariaDB [mysql]> desc user;
+------------------------+-----------------------------------+------+-----+----------+-------+
| Field                  | Type                              | Null | Key | Default  | Extra |
+------------------------+-----------------------------------+------+-----+----------+-------+
| Host                   | char(60)                          | NO   | PRI |          |       |
| User                   | char(80)                          | NO   | PRI |          |       |
| Password               | char(41)                          | NO   |     |          |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N        |       |
〜(省略)

ユーザとホスト確認


MariaDB [(none)]> select user, host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | localhost |
+------+-----------+
3 rows in set (0.000 sec)
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?