OshiHa.com

ConoHaでAlpine Linux 3.8

MariaDB のインストール・設定

2018/09/04  2018/09/05

◆◇◆ 【衝撃価格】VPS512MBプラン!月額630円/1時間1円【ConoHa】 ◆◇◆

1. インストール

alpine:~$ sudo apk add mariadb mariadb-client

2. MariaDB のバージョン確認

alpine:~$ mysql --version
mysql  Ver 15.1 Distrib 10.3.9-MariaDB, for Linux (x86_64) using readline 5.1

3. MariaDB の設定

設定1

/etc/mysql のディレクトリ内に my.cnf が存在しないので、新規作成する。
(バージョン10.3.2 から)

alpine:~$ sudo vi /etc/mysql/my.cnf
[client]
port		= 3306
socket		= /run/mysqld/mysqld.sock
default-character-set=utf8mb4

[mysqld]
port		= 3306
socket		= /run/mysqld/mysqld.sock
character-set-server	= utf8mb4
collation-server	= utf8mb4_general_ci
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

tmpdir		= /tmp/
log_error = /var/log/mysql/mariadb.log
skip-networking
log-bin=mysql-bin
binlog_format=mixed
server-id	= 1

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

設定2

ソケットファイルを保存するディレクトリを作成し、所有者を変更する。

alpine:~$ sudo mkdir /run/mysqld
alpine:~$ sudo chown mysql:mysql /run/mysqld

設定3

ログを保存するディレクトリを作成し、所有者を変更する。

alpine:~$ sudo mkdir /var/log/mysql
alpine:~$ sudo chown mysql:mysql /var/log/mysql

設定4

alpine:~$ sudo /etc/init.d/mariadb setup
 * Creating a new MySQL database ...

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h alpine password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

MariaDB の起動とサービス登録

alpine:~$ sudo rc-service mariadb start
alpine:~$ sudo rc-update add mariadb

ここで、起動すると以下のエラーがでるが、そのまま進む。

180905 14:47:11 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
180905 14:47:11 mysqld_safe Logging to '/var/log/mysql/mysqld.err'.
180905 14:47:11 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

設定3

alpine:~$ sudo 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): 	← 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
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: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:テストデータベースは削除
 - 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!

4. 各種コマンド

MariaDB に root でログイン

alpine:~$ sudo mysql -u root -p

ステータスの確認

MariaDB [(none)]> status;
--------------
mysql  Ver 15.1 Distrib 10.3.9-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:          16
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.3.9-MariaDB MariaDB Server
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /run/mysqld/mysqld.sock
Uptime:                 1 min 11 sec

Threads: 7  Questions: 19  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 12  Queries per second avg: 0.267
--------------

ユーザー情報一覧

MariaDB [(none)]> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *2208D3DFB880883225174930F1B573BDF8AF22C0 |
| root | 127.0.0.1 | *2208D3DFB880883225174930F1B573BDF8AF22C0 |
| root | ::1       | *2208D3DFB880883225174930F1B573BDF8AF22C0 |
+------+-----------+-------------------------------------------+
3 rows in set (0.001 sec)
データベース一覧
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

文字コードの確認

MariaDB [(none)]> SHOW VARIABLES LIKE "chara%";
+--------------------------+------------------------------+
| Variable_name            | Value                        |
+--------------------------+------------------------------+
| character_set_client     | utf8mb4                      |
| character_set_connection | utf8mb4                      |
| character_set_database   | utf8mb4                      |
| character_set_filesystem | binary                       |
| character_set_results    | utf8mb4                      |
| character_set_server     | utf8mb4                      |
| character_set_system     | utf8                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.002 sec)

終了

MariaDB [(none)]> exit

◆◇◆ 【衝撃価格】VPS512MBプラン!月額630円/1時間1円【ConoHa】 ◆◇◆

ConoHa VPSの攻略
Alpine Linux 3.8

TOP