MariaDBデータベースサーバのインストール
動作確認済みシステム Debian 11
データベースサーバとして、MariaDBをインストールします。MariaDBは、MySQLをフォークして開発されています。
Debian 11のデフォルトリポジトリにあるMariaDBの情報を見てみます。
apt show mariadb-server
Package: mariadb-server
Version: 1:10.5.11-1
Priority: optional
Section: database
Source: mariadb-10.5
Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Installed-Size: 72.7 kB
Depends: mariadb-server-10.5 (>= 1:10.5.11-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: 34.8 kB
APT-Sources: http://deb.debian.org/debian bullseye/main amd64 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.5), 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.
バージョンが10.5となっています。しかし、最新バージョン10.6がリリースされています。
この10.6をリリースする方法を説明します。
以下のコマンドで、MariaDBのリポジトリを追加します。
apt install software-properties-common dirmngr
curl -LsSO https://mariadb.org/mariadb_release_signing_key.asc
chmod -c 644 mariadb_release_signing_key.asc
mv -vi mariadb_release_signing_key.asc /etc/apt/trusted.gpg.d/
add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.6/debian bullseye main'
MariaDBをインストールします。
apt update
apt install mariadb-server
設定ファイルを編集します。
vi /etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]
binlog_expire_logs_seconds = 864000
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
innodb_strict_mode = 0
innodb_read_only_compressed = 0
binlog_expire_logs_secondsは、バイナリログが肥大化するのを防ぐために設定します。
MariaDB 10.6以降では、InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.というメッセージが出力され、データベースに書き込めないことがあるので、innodb_strict_modeとinnodb_read_only_compressedも設定します。
MariaDBサービスの再起動を行います。
systemctl restart mariadb.service
MariaDBの初期設定を実施します。
mariadb-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): (何も入力せずEnterキーを押す)
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] Y
New password: (rootの新しいパスワードを入力)
Re-enter new password: (再度パスワードを入力)
Password updated successfully!
Reloading privilege tables..
... Success!
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!
以下のコマンドでMariaDBにログインできることが確認できればOKです。
mariadb -u root -p