- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2019-08-04T02:03:09+09:00","","")
#navi(../)
* Raspbian busterにMariaDBをインストール [#b3d497cb]
本記事では、ラズベリーパイのRaspbian busterにMariaDBをインストールし、~
ユーザ追加、データベース作成、SQLを実行までの記事になります。
#htmlinsert(minipc-top.html)
#contents
* 関連記事 [#l2b67a88]
-[[Raspbian busterにSQLite3をインストール>Pi/Server/Raspbian busterにSQLite3をインストール]]
* 使用した環境 [#g657fe68]
-Raspberry Pi 3B+~
[[Raspberry Pi(Amazonへのリンク)>https://amzn.to/2IIrAhM]]
- Raspbian OS
$ lsb_release -dr
Description: Raspbian GNU/Linux 10 (buster)
* MariaDBパッケージをインストールする [#t61a0715]
LXTerminal &ref(t.png); を使ってaptコマンドでMariaDBをインストール手順になります。
+ MariaDBパッケージインストール前に以下のコマンドを実行しアップデートを実施します。
sudo apt update
sudo apt -y upgrade
+ MariaDBパッケージを以下のコマンドを実行しインストールします。
sudo apt install mariadb-server -y
ちなみにインストールするmariadb-serverパッケージの情報は以下の通りです。~
apt showコマンドで確認することができます。~
$ apt show mariadb-server
Package: mariadb-server
Version: 1:10.3.15-1
Priority: optional
Section: database
Source: mariadb-10.3
Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Installed-Size: 66.6 kB
Depends: mariadb-server-10.3 (>= 1:10.3.15-1)
Homepage: https://mariadb.org/
Tag: devel::lang:c++, devel::lang:sql, devel::library, implemented-in::c++,
interface::commandline, interface::daemon, network::server,
protocol::db:mysql, role::devel-lib, role::metapackage, role::program,
works-with::db
Download-Size: 30.2 kB
APT-Sources: http://ftp.jaist.ac.jp/raspbian buster/main armhf Packages
Description: MariaDB database server (metapackage depending on the latest version)
This is an empty package that depends on the current "best" version of
mariadb-server (currently mariadb-server-10.3), as determined by the MariaDB
maintainers. Install this package if in doubt about which MariaDB
version you need. That will install the version recommended by the
package maintainers.
.
MariaDB is a fast, stable and true multi-user, multi-threaded SQL database
server. SQL (Structured Query Language) is the most popular database query
language in the world. The main goals of MariaDB are speed, robustness and
ease of use.
+インストール中のメッセージは以下の通りです。~
$ sudo apt install mariadb-server -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
galera-3 gawk libaio1 libcgi-fast-perl libcgi-pm-perl
libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl
<省略>
プロンプト($)が戻ってくればMariaDBのインストールは完了です。
* collation-serverの変更 [#x5206858]
/etc/mysql/mariadb.conf.d/50-server.cnf にサーバの文字コードおよびcollation(文字列比較のルール)が設定されてます。~
デフォルト(インストール時点)では以下の通りです。
#
# * Character sets
#
# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf
#
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
必要に応じて変更してください。~
本記事では、collation-serverの設定値を(''utf8mb4_bin'')に変更しました。
#collation-server = utf8mb4_general_ci
collation-server = utf8mb4_bin
/etc/mysql/mariadb.conf.d/50-server.cnf の変更が終わったら保存し、以下のようにMariaDBを再起動します。
sudo systemctl restart mariadb
* MariaDB初期設定 [#s6d572c8]
+MariaDBの初期設定を以下のコマンドで実施します。
sudo mysql_secure_installation
+rootパスワードを設定します。~
基本はすべてEnterキーで構いませんが、以下のメッセージが表示されたら、~
MariaDBのrootパスワードを設定してください。(大文字英字がデフォルトになります。)
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
+以下のメッセージが表示されプロンプトが表示されたらMariaDBの初期設定は完了です。
Thanks for using MariaDB!
* MariaDBの動作確認 [#geefb216]
MariaDBへの接続、SQLの発行を試してみます。
$ sudo mariadb -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 46
Server version: 10.3.15-MariaDB-1 Raspbian testing-staging
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)]>
SQLを実行してみる
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.002 sec)
MariaDB [(none)]> select now();
+---------------------+
| now() |
+---------------------+
| 2019-08-04 01:56:41 |
+---------------------+
1 row in set (0.001 sec)
MariaDB [(none)]> exit
Bye
ちなみに上記では、mysqlではなく、mariadbコマンドで実行しています。~
もちろん、mysqlコマンドでも同様に動作します。~
mariadbコマンドはmysqlコマンドのシンボリックリンクです。
$ file $(which mariadb)
/usr/bin/mariadb: symbolic link to mysql
$ ls -l $(which mariadb)
lrwxrwxrwx 1 root root 5 5月 21 16:45 /usr/bin/mariadb -> mysql
以上、ラズパイ(Raspbian buster)にMariaDBをインストールし簡単な動作確認を実施するまでの資料でした。
#htmlinsert(minipc-btm.html)