このエントリーをはてなブックマークに追加


Raspbian busterにMariaDBをインストール

本記事では、ラズベリーパイのRaspbian busterにMariaDBをインストールし、
ユーザ追加、データベース作成、SQLを実行までの記事になります。


スポンサーリンク

関連記事

使用した環境

MariaDBパッケージをインストールする

LXTerminal t.png を使ってaptコマンドでMariaDBをインストール手順になります。

  1. MariaDBパッケージインストール前に以下のコマンドを実行しアップデートを実施します。
    sudo apt update
    sudo apt -y upgrade
  2. 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.
  3. インストール中のメッセージは以下の通りです。
    $ 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の変更

/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
01.png
 

/etc/mysql/mariadb.conf.d/50-server.cnf の変更が終わったら保存し、以下のようにMariaDBを再起動します。

sudo systemctl restart mariadb

MariaDB初期設定

  1. MariaDBの初期設定を以下のコマンドで実施します。
    sudo mysql_secure_installation
  2. rootパスワードを設定します。
    基本はすべてEnterキーで構いませんが、以下のメッセージが表示されたら、
    MariaDBのrootパスワードを設定してください。(大文字英字がデフォルトになります。)
    Set root password? [Y/n] 
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
  3. 以下のメッセージが表示されプロンプトが表示されたらMariaDBの初期設定は完了です。
    Thanks for using MariaDB!

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をインストールし簡単な動作確認を実施するまでの資料でした。


スポンサーリンク

添付ファイル: file01.png 431件 [詳細] filet.png 384件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019-08-04 (日) 02:10:02