MariaDB インストール
OS 標準パッケージ
サーバー側 mariadb-server
クライアント側 mariadb-client
クライアント側はサーバー側を入れると同時に入るはず。
バージョンは OS 側で固定されているので注意。
$ sudo apt install mariadb-server
$ sudo apt install mariadb-client
インストールした時点でサービスが既に動作している。
code:console
$ systemctl status mariadb
● mariadb.service - MariaDB 10.6.11 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-12-15 02:17:25 UTC; 21min ago
Docs: man:mariadbd(8)
Process: 60183 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 60184 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 60186 ExecStartPre=/bin/sh -c ! -e /usr/bin/galera_recovery && VAR= || VAR=cd /usr/bin/..; /usr/bin/galera_recovery; $? -eq 0 && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, st> Process: 60229 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 60231 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 60216 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 7 (limit: 2324)
Memory: 61.0M
CPU: 719ms
CGroup: /system.slice/mariadb.service
└─60216 /usr/sbin/mariadbd
Dec 15 02:17:25 i-13100000450284 mariadbd60216: 2022-12-15 2:17:25 0 Note /usr/sbin/mariadbd: ready for connections. Dec 15 02:17:25 i-13100000450284 mariadbd60216: Version: '10.6.11-MariaDB-0ubuntu0.22.04.1' socket: '/run/mysqld/mysqld.sock' port: 3306 Ubuntu 22.04 Dec 15 02:17:25 i-13100000450284 systemd1: Started MariaDB 10.6.11 database server. Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60236: Looking for 'mariadb' as: /usr/bin/mariadb Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60236: Looking for 'mariadb-check' as: /usr/bin/mariadb-check Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60236: This installation of MariaDB is already upgraded to 10.6.11-MariaDB. Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60236: There is no need to run mysql_upgrade again for 10.6.11-MariaDB. Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60236: You can use --force if you still want to run mysql_upgrade Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60245: Checking for insecure root accounts. Dec 15 02:17:25 i-13100000450284 /etc/mysql/debian-start60249: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables code:console
$ sudo mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Bye
\q で終了する。
mysql_secure_installation でよりセキュアにする。(変化部分を確認したが、変化していないので不要っぽい。)
code:console
$ sudo /usr/bin/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
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication Y/n y Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? Y/n n ... skipping.
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.
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.
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!
待ち受けしているポート番号を確認する。Unix ドメインソケットを使う場合は何もないのが正しい。
3306 か mysql が見えているならポートが開いてしまっている。
$ ss -tl
存在するデータベースの確認
code:console
MariaDB (none)> SHOW DATABASES; +--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.001 sec)
データベース定義の確認
code:console
MariaDB (none)> SHOW CREATE DATABASE mysql; +----------+----------------------------------------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------------------------------------+
| mysql | CREATE DATABASE mysql /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ |
+----------+----------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
utf8md4 が正しい文字コード、utf8mb4_general_ci が正しいロケール。それ以外を使うとろくなことにならない。
ユーザーの確認
専用の命令はなく、mysql.user テーブルを見るしかない。
code:console
MariaDB (none)> SELECT User, Host FROM mysql.user; +-------------+-----------+
| User | Host |
+-------------+-----------+
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
3 rows in set (0.001 sec)