本記事では、ラズベリーパイのRaspbian busterにMariaDBをインストールし、
ユーザ追加、データベース作成、SQLを実行までの記事になります。
$ lsb_release -dr Description: Raspbian GNU/Linux 10 (buster)
LXTerminal を使ってaptコマンドでMariaDBをインストール手順になります。
sudo apt update sudo apt -y upgrade
sudo apt install mariadb-server -yちなみにインストールするmariadb-serverパッケージの情報は以下の通りです。
$ 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のインストールは完了です。
/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
sudo mysql_secure_installation
Set root password? [Y/n] New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
Thanks for using MariaDB!
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をインストールし簡単な動作確認を実施するまでの資料でした。