データベース · 6 min read · Jan 07, 2026
CentOS 6 に MariaDB 10.0 をインストールする
MariaDB は MySQL のコミュニティ開発フォークであり、MySQL の強化されたドロップイン置き換えを目指しています。これは GNU GPL ライセンスであり、Monty Widenius のような MySQL の元開発者によって主導されています。MariaDB は現在も活発ですが、MySQL よりも市場シェアはかなり少ないです。MySQL が持つ大きな勢いのため、周囲にはまだ多くのコミュニティがありますが、オープンソースの世界での新しい活動のほとんどは MariaDB に関連しており、ほとんどの Linux ディストリビューションは現在 MySQL 互換のデータベースとして MariaDB を出荷しています。以下のチュートリアルでは、CentOS 6 に MariaDB 10.0 をインストールする手順を案内します。CentOS 6 は古すぎますか?はい、その通りですが、CentOS 6 は 2020 年までセキュリティ更新がサポートされており、まだ多くのサーバーがそれを使用している可能性がありますが、最新の CMS システムをホストするために新しい MySQL 互換のデータベースが必要な場合があります。
前提条件
- これらの手順は、MySQL がすでにインストールされていない単一の CentOS 6 ノードに MariaDB 10.0 をインストールすることを目的としています。
- デフォルトの MariaDB インストールは、データベースを保存するために /var/lib/mysql ディレクトリを使用するため、/var に関連付けられたパーティションまたは論理ボリュームには十分なスペースが必要です。
- 設定ファイルのバックアップ(置き換えのみ): 現在のインストールを置き換える場合は、現在の MySQL/MariaDB 設定ファイルのコピーを作成することをお勧めします。このファイルは、Debian/Ubuntu システムでは /etc/mysql/my.cnf に、CentOS システムでは
/etc/my.cnfにあります。CentOS では、MariaDB パッケージがアンインストール時に設定ファイルを削除するため、このステップは特に重要です。 - このチュートリアルの残りの部分では、root ユーザーアカウントまたは sudo 権限を持つユーザーアカウントでサーバーに接続していると仮定します。他のアカウントから root シェルに入るには、次のコマンドを実行します:
sudo suステップ 1. ** MariaDB リポジトリの設定
利用可能なパッケージが最新であることを確認する必要があります。そのためには、ターミナルで次のコマンドを実行します:
yum -y updateLoaded plugins: fastestmirror
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/4): base/7/x86_64/group_gz | 155 kB 00:00
(2/4): extras/7/x86_64/primary_db | 101 kB 00:00
(3/4): updates/7/x86_64/primary_db | 3.1 MB 00:00
(4/4): base/7/x86_64/primary_db | 5.3 MB 00:04
Determining fastest mirrors
* base: mirror.net.cen.ct.gov
* extras: mirror.es.its.nyu.edu
* updates: mirror.atlanticmetro.net
Resolving Dependencies
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-51.el7_2.2 will be updated
---> Package openssl.x86_64 1:1.0.1e-51.el7_2.4 will be an update
---> Package openssl-libs.x86_64 1:1.0.1e-51.el7_2.2 will be updated
---> Package openssl-libs.x86_64 1:1.0.1e-51.el7_2.4 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
openssl x86_64 1:1.0.1e-51.el7_2.4 updates 711 k
openssl-libs x86_64 1:1.0.1e-51.el7_2.4 updates 951 k
Transaction Summary
================================================================================
Upgrade 2 Packages
Total download size: 1.6 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): openssl-1.0.1e-51.el7_2.4.x86_64.rpm | 711 kB 00:00
(2/2): openssl-libs-1.0.1e-51.el7_2.4.x86_64.rpm | 951 kB 00:00
--------------------------------------------------------------------------------
Total 2.3 MB/s | 1.6 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:openssl-libs-1.0.1e-51.el7_2.4.x86_64 1/4
Updating : 1:openssl-1.0.1e-51.el7_2.4.x86_64 2/4
Cleanup : 1:openssl-1.0.1e-51.el7_2.2.x86_64 3/4
Cleanup : 1:openssl-libs-1.0.1e-51.el7_2.2.x86_64 4/4
Verifying : 1:openssl-libs-1.0.1e-51.el7_2.4.x86_64 1/4
Verifying : 1:openssl-1.0.1e-51.el7_2.4.x86_64 2/4
Verifying : 1:openssl-1.0.1e-51.el7_2.2.x86_64 3/4
Verifying : 1:openssl-libs-1.0.1e-51.el7_2.2.x86_64 4/4
Updated:
openssl.x86_64 1:1.0.1e-51.el7_2.4 openssl-libs.x86_64 1:1.0.1e-51.el7_2.4
Complete!次に、MariaDB CentOS リポジトリを追加します。
新しい MariaDB リポジトリファイル /etc/yum.repos.d/mariadb.repo を nano で作成します:
nano /etc/yum.repos.d/MariaDB.repoそして、CentOS-6 32 ビット用の次のテキストを貼り付けます:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1または、CentOS-6 64 ビット用のこのテキストを貼り付けます:
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1その後、Ctrl+X を押してファイルを終了し、保存します。
上記の例に示すように、MariaDB がリポジトリに署名するために使用する GPG キーを自動的に取得するための gpgkey 行が含まれています。このキーは、パッケージのダウンロードの整合性を確認するために必要です。
注意: MariaDB リポジトリジェネレーターを使用する際にどのリポジトリを使用すべきかを見つけるため。
ステップ 2 – Yum で MariaDB 10 をインストール
MySQL の削除(インストールされている場合のみ)
システムにインストールされている可能性のある古い MySQL サーバーのバージョンを完全に削除し、MariaDB にアップグレードすることをお勧めします。
MySQL がすでにインストールされているかどうかを確認するには、次のコマンドを実行します:
rpm -qa 'mysql*'必要に応じて、MariaDB をインストールする前に見つかった MySQL パッケージを削除できます。次のコマンドを使用します:
yum list installed | grep mysqlyum remove mysql-client mysql-server mysql-common mysql-develそして、MySQL データベースを削除します:
rm -Rf /var/lib/mysqlMariaDB 10 のインストール
標準のサーバーインストールでは、少なくとも client、shared、および server RPM ファイルをダウンロードしてインストールする必要があります。
yum install MariaDB-server MariaDB-client -y次のような出力が表示されるはずです:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.net.cen.ct.gov
* extras: mirror.es.its.nyu.edu
* updates: mirror.atlanticmetro.net
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.44-2.el7.centos will be installed
--> Processing Dependency: perl(Sys::Hostname) for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(IPC::Open3) for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(File::Temp) for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(Fcntl) for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(Exporter) for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: /usr/bin/perl for package: 1:mariadb-5.5.44-2.el7.centos.x86_64
---> Package mariadb-server.x86_64 1:5.5.44-2.el7.centos will be installed
--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(File::Path) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
[...]
Installed:
mariadb.x86_64 1:5.5.44-2.el7.centos mariadb-server.x86_64 1:5.5.44-2.el7.centos
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 perl.x86_64 4:5.16.3-286.el7
perl-Carp.noarch 0:1.26-244.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-5.el7
perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7
perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7
perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7
perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-2.el7
perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PathTools.x86_64 0:3.40-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7 perl-Pod-Escapes.noarch 1:1.04-286.el7
perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7
perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7
perl-Socket.x86_64 0:2.010-3.el7 perl-Storable.x86_64 0:2.45-3.el7
perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7
perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7
perl-libs.x86_64 4:5.16.3-286.el7 perl-macros.x86_64 4:5.16.3-286.el7
perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7
perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7
Complete!インストールプロセスが完了したら、MariaDB を起動できます。MariaDB サービスは「mysql」と呼ばれるため、以下のコマンドは誤りではありません。
service mysql startStarting MySQL. SUCCESS!次のコマンドを実行して、毎回の起動時に MariaDB を開始します。
chkconfig mysql on次のコマンドを使用して、MariaDB インストールのバージョンを確認できます:
mysql -Vmysql Ver 15.1 Distrib 10.0.24-MariaDB, for Linux (x86_64) using readline 5.1今のところ順調です!
ステップ 3 – MariaDB のセキュリティ強化
デフォルトでは、MariaDB は強化されていません。mysql_secure_installation スクリプトを使用して MariaDB をセキュアにできます。以下の手順を注意深く読んでください。これにより、root パスワードが設定され、匿名ユーザーが削除され、リモート root ログインが禁止され、テストデータベースが削除され、MariaDB のセキュリティが強化されます。すべての管理者がこのスクリプトを実行して、MySQL インストールが安全であることを確認することをお勧めします。残念ながら、このスクリプトは対話式であり、root パスワードを要求するため、ビルドプロセスに簡単に含めることはできません。これらのオプションには「はい」と答えることをお勧めします。スクリプトの詳細については、MariaDB ナレッジベースを参照してください。
引数なしで mysql_secure_installation を呼び出します:
mysql_secure_installationこれにより、質問応答方式で動作する手順が開始され、MariaDB インストールにいくつかのカスタマイズを適用できます。以下は、何が起こるかの例と、使用すべき推奨オプションのいくつかです。
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!MariaDB にログインしてセキュリティを強化するには、root ユーザーの現在のパスワードが必要です。MariaDB をインストールしたばかりで、まだ root パスワードを設定していない場合、デフォルトのパスワードは空白になりますので、ここではただ Enter を押してください。
Enter current password for root (enter for none):
OK, successfully used password, moving on...root パスワードを設定することで、適切な認証なしに誰も MariaDB の root ユーザーにログインできないようにします。
Set root password? [Y/n] y
New password: ENTER YOUR PASSWORD
Re-enter new password: REPEAT YOUR PASSWORD
Password updated successfully!
Reloading privilege tables..
... Success!デフォルトでは、MariaDB インストールには匿名ユーザーが存在し、誰でもユーザーアカウントを作成せずに MariaDB にログインできるようになっています。これはテスト用にのみ意図されており、インストールを少しスムーズにするためのものです。生産環境に移行する前に、匿名ログインを削除する必要があります。
Remove anonymous users? [Y/n] y
... Success!通常、root は「localhost」からのみ接続を許可されるべきです。これにより、誰かがネットワーク越しに root パスワードを推測できないようにします。
Disallow root login remotely? [Y/n] y
... Success!デフォルトでは、MariaDB には「test」という名前のデータベースがあり、誰でもアクセスできます。これもテスト用にのみ意図されており、生産環境に移行する前に削除する必要があります。
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!特権テーブルを再読み込みすることで、これまでに行ったすべての変更が即座に適用されることを確認します。
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 を再起動する必要があります。
service mysql restartShutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!それで終わりです。MariaDB サーバーにログインして、古いデータベースやテーブルを確認してください(MySQL からアップグレードした場合)。
MariaDB に接続するには、以下のコマンドを実行します。
mysql -u root -pこの場合、-u フラグでユーザー root を指定し、次に -p フラグを使用して MySQL にパスワードを要求させます。
求められたら、mysql_secure_installation スクリプトで指定したパスワードを入力します。
その後、ウェルカムヘッダーと MariaDB プロンプトが表示されます。
MariaDB コマンドのリストを表示するには、プロンプトで help または \ h と入力します:
General information about MariaDB can be found at
http://mariadb.org
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type 'help contents'
作成した現在のデータベースのリストを表示するには、次のコマンドを使用します:
SHOW DATABASES;+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)「information_schema」、「performance_schema」、および「mysql」データベースはデフォルトで設定されており、MariaDB サーバーのシステムデータを含んでいます。これらのテーブルは、何をしているかを理解していない限り、触れないでおくべきです。
データベースサーバーの状態を確認します:
status;mysql Ver 15.1 Distrib 5.5.44-MariaDB, for Linux (x86_64) using readline 5.1
Connection id: 14
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 5.5.44-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 47 min 9 sec
Threads: 1 Questions: 32 Slow queries: 0 Opens: 4 Flush tables: 2 Open tables: 30 Queries per second avg: 0.011
--------------
MariaDB [(none)]>データベースを作成しても、それを使用するために選択する必要があります。howtoforge を現在のデータベースにするには、次のステートメントを使用します:
USE howtoforgeデータベースは一度だけ作成する必要がありますが、MySQL セッションを開始するたびにそれを使用するために選択する必要があります。これは、例に示すように USE ステートメントを発行することで行えます。あるいは、MySQL を呼び出すときにコマンドラインでデータベースを選択することもできます。接続パラメータを提供する必要がある場合は、その後にデータベース名を指定します。たとえば:
mysql -h host -u user -p howtoforge注意: すべてのデータベース名、テーブル名、テーブルフィールド名は大文字と小文字を区別します。したがって、SQL コマンドを与える際には適切な名前を使用する必要があります。
デフォルトでは、コマンドライン経由で実行されるすべての MySQL 操作は、現在選択されているデータベースで実行されます。現在どのデータベースが選択されていますか?それを見つけるには、次のコマンドを発行します:
SELECT database();結果は次のようになります:
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
MariaDB [(none)]>結果は null であり、現在データベースが選択されていないことを意味します。
さらなる情報
このトピックに関する追加情報を得るために、以下のリソースを参照することをお勧めします。これらは有用であることを期待して提供されていますが、外部ホストされた資料の正確性やタイムリーさについては保証できません。
- MariaDB ドキュメント
- MySQL リファレンスマニュアル
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。