LoginSignup
5
6

MariaDB10.11のインストール(ソースからコンパイル)for RockyLinux8.x & 9.x and Ubuntu 22.04.2

Last updated at Posted at 2016-09-24

はじめに

MySQLからの移行者も徐々に増え始めmariaDB。
MariaDB11.0.2をソースからコンパイルしてインストールする方法をメモしておきます。
2023年6月現在、「11.0.2」が最新版です。

実践環境バージョン情報

ソフトウェア バージョン
CMake 3.26.3
ncruse 6.4
MariDB 11.0.2
OS RockeyLinux 8.x and 9 and Ubuntu 22.04.2

注意事項

OpenSSL1.1には、未対応なのでOpenSSL1.0.xをあらかじめインストールしておきましょう。
※RockyLinux 9の場合は、OpenSSL 3.0.x系を利用
https://jira.mariadb.org/browse/MDEV-10332

準備

稼働用のユーザーを作成する

useradd mysql

Cmakeをインストールする

cd /usr/local/src
wget https://github.com/Kitware/CMake/archive/refs/tags/v3.27.0-rc3.tar.gz
tar xvzf v3.27.0-rc3.tar.gz
cd CMake-3.27.0-rc3


#環境変数を設定する
export OPENSSL_ROOT_DIR=/usr/local/ssl
export PKG_CONFIG_PATH=/usr/local/ssl/lib:$PKG_CONFIG_PATH
./configure
gmake -j 8
make install

もしエラーになった場合

rm CMakeCache.txt

を実行して再度行ってみましょう

ncruseをインストール

bash
cd /usr/local/src
#ミラーサイトを利用する
wget http://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz
tar xvzf ncurses-6.4.tar.gz
cd ncurses-6.4
./configure --with-shared
make
make install

MariaDBをインストールする

bash
cd /usr/local/src
wget https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/mariadb-11.0.2/source/mariadb-11.0.2.tar.gz
tar xvzf mariadb-11.0.2.tar.gz
cd mariadb-11.0.2

#export OPENSSL_ROOT_DIR=/usr/local/ssl
#export OPENSSL_INCLUDE_DIR=/usr/local/ssl/include
#export OPENSSL_LIBRARIES=/usr/local/ssl/lib/
#export OPENSSL_ROOT_DIR=/usr/local/ssl

/usr/local/bin/cmake \
-DPLUGIN_TOKUDB=NO 
#-OPENSSL_ROOT_DIR=/usr/local/ssl \
#-OPENSSL_INCLUDE_DIR=/usr/local/include \
#-OPENSSL_LIBRARIES=/usr/local/lib64 \
#-DDEFAULT_CHARSET=utf8 \
#-DDEFAULT_COLLATION=utf8_general_ci

make install -j 8

#
# もしくは、以下の方法でコンパイル
#
#BUILD/autorun.sh
#./configure --with-plugin-xtradb
#make 
#make install

#オーナーを設定
chown mysql:mysql -R /usr/local/mysql/


#設定ファイルをコピーする
#cp support-files/my-medium.cnf /etc/my.cnf
#cp etc/my.cnf.d/server.cnf /etc/my.cnf
my.cnf
cat > /etc/my.cnf << EOF
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
datadir=/usr/local/mysql/data
lc_messages_dir = /usr/local/mysql/share
socket          = /usr/local/mysql/run/mariadb/mysql.sock
bind-address = 0.0.0.0
innodb_compression_algorithm = none

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/usr/local/mysql/run/mariadb/mysql.pid


#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.4 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.4]

[client]
socket          = /usr/local/mysql/run/mariadb/mysql.sock

EOF

初期DBファイルを作成

su mysql
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
exit

#ログの場所を作成
mkdir /var/log/mariadb
chown -R mysql:mysql /var/log/mariadb/

設定ファイルを用意する

起動スクリプト

mariadb.service
cat > /usr/lib/systemd/system/mariadb.service << EOF
[Unit]
Description=MariaDB 10.8.3 database server
Documentation=man:mysqld(8)
Documentation=https://mariadb.com/kb/en/library/systemd/
After=network.target



[Service]
User=mysql
Group=mysql
Restart=always
Type=simple


ExecStart=/usr/local/mysql/bin/mysqld
ExecStop=/bin/kill \${MAINPID}
PIDFile=/usr/local/mysql/run/mariadb/mysql.pid

[Install]
WantedBy=multi-user.target

EOF

設定ファイルの追加

・Can't find messagefile '/usr/share/errmsg.sys'と言われた時の対応
・/tmpのCentOS7からの動作挙動影響によるPIDファイルのパス変更

プロセス配置用のディレクトリも用意する

mkdir -p /usr/local/mysql/run/mariadb
chown mysql:mysql /usr/local/mysql/run/mariadb

初期パスワード設定

su mysql
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
/usr/local/mysql/bin/mysql -u root
use mysql;
select * from user;
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
create user admin@'%' identified by 'password';
grant create on *.* to admin@'%';
exit

##一度Mariadbを停止する
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
#パスワードを聞かれたら先ほど設定したパスワードを入力し、Enterキーを押す

サービスの設定

サービスの起動と自動起動登録

systemctl enable mariadb
systemctl start mariadb

起動後のユーザー設定

su mysql
./mysql -u mysql
alter user 'root'@'localhost' identified BY 'パスワード';
exit

inclundeファイルについて

PHP7.1.xをmysqliモジュールをコンパイルする際に、「my_list.h」が存在しないとエラーになることがあります。これは、インストール後のいくつかのヘッダーファイルが入っていないからです。
これに対応するため、以下の対策を入れておきます。

bash:includeファイルコピー
mv /usr/local/mysql/include /usr/local/mysql/include.def
mkdir -p /usr/local/mysql/include/mysql
chown -R mysql:mysql /usr/local/mysql/include
cd /usr/local/src/mariadb-10.5.10/include
cp -rf ./* /usr/local/mysql/include/mysql
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6