4
3

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.

Install MariaDB on Raspberry Pi OS

Last updated at Posted at 2020-09-25

MariaDB

MariaDBの開発は、MySQLのオリジナルコードの作者でMySQL ABの創設者でもあるミカエル・ウィデニウスにより、現在オラクルによって所有されているMySQLをフォークして立ち上げられたプロジェクトにより行われている。配布ライセンスは、GNU General Public Licenseのバージョン2。MariaDBの名は、Wideniusの2番目の娘の名前から採られている。
ウィキペディア(Wikipedia)

MySQL on Raspberry Pi OS ?

ありません。

pi@raspberrypi:~ $ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package mysql-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  mariadb-server-10.0

E: Package 'mysql-server' has no installation candidate

Install MariaDB

pi@raspberrypi:~ $ sudo apt install mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
<snip>
Processing triggers for systemd (241-7~deb10u4+rpi1) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10+rpi1) ...
pi@raspberrypi:~ $ mariadb -V
mariadb  Ver 15.1 Distrib 10.3.23-MariaDB, for debian-linux-gnueabihf (armv7l) using readline 5.2

root パスワード設定


pi@raspberrypi:~ $ sudo mysql_secure_installation
<snip>
Enter current password for root (enter for none):
OK, successfully used password, moving on...
<snip>
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
<snip>
Remove anonymous users? [Y/n] y
<snip>
Disallow root login remotely? [Y/n] n
<snip>
Remove test database and access to it? [Y/n] y
<snip>
Reload privilege tables now? [Y/n] y
<snip>

unix_sokect プラグインの無効化

root ユーザは unix_sokect プラグインを利用して認証されます。Linux ユーザと SQL ユーザが同じでないとログインできません。言い方を変えると、root については DB 側にパスワードを持たず、OS 側が root かどうかで DB にアクセス可能かどうかの判断をしています。

pi@raspberrypi:~ $ sudo mysql -u root
<snip>
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> SELECT User, Host, plugin FROM user;
+------+-----------+-------------+
| User | Host      | plugin      |
+------+-----------+-------------+
| root | localhost | unix_socket | <<<< これ
+------+-----------+-------------+
1 row in set (0.001 sec)

以下、無効化設定。

MariaDB [mysql]> USE mysql;
Database changed
MariaDB [mysql]> UPDATE user SET plugin='' WHERE User='root';
Query OK, 1 row affected (0.001 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> exit
Bye
pi@raspberrypi:~ $ sudo systemctl restart mysql
pi@raspberrypi:~ $  mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.3.23-MariaDB-0+deb10u1 Raspbian 10

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

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

MariaDB [(none)]>

環境

pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 10 (buster)
Release:	10
Codename:	buster
pi@raspberrypi:~ $ cat /proc/device-tree/model
Raspberry Pi 4 Model B Rev 1.2
4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?