Build MariaDB từ source code trên Ubuntu

Build MariaDB from source code - Compile​​ MariaDB từ​​ Source code

Mục đích: Build MariaDB from source giúp bạn có thể​​ chủ​​ động build đúng được version, chọn lựa các option phù hợp khi​​ build. Ví dụ​​ này mình build MariaDB version 10.3.17 và lưu​​ ​​ location: /opt/mysql

data thường default lưu trữ​​ ​​ /var/lib/mysql sẽ​​ được chuyển sang đường dẫn /opt/mysql/data

Các bước tiến hành như sau:

Bước 1: Copy toàn bộ​​ nội dung file .sh bên dưới vào 1 file build-mariadb-10.3.17-from-source:

 

#!/bin/bash

#Build mariadb verrsion 10.3.17 from source code

#/opt/setup/build-mariadb-10.3.17-from-source.sh

# © Copyright Sakurai​​ 

 

#turn off ipv6

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1

sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

# setup ENV

#export LC_CTYPE=en_US.UTF-8

#export LC_ALL=en_US.UTF-8

 

# Create Folder

DIR_DATA="/opt/mysql/"​​ 

mkdir -p $DIR_DATA

mkdir -p /opt/setup

mkdir -p /opt/mysql/mariadb

mkdir -p $DIR_DATA/data

 

## Install​​ dependencies package

echo "####################################################################"

echo "#  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ Install dependencies package  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ #"

echo "####################################################################"

apt-get​​ -y update

apt-get -y upgrade

sudo apt-get -y install cmake

sudo apt-get -y install libncurses5-dev

sudo apt-get -y install jemalloc*

apt-get install -y libaio-dev

sudo apt-get build-dep mariadb-server

apt-get install -y libmysqlclient-dev cmake libncurses5-dev libaio1 libaio-dev

sudo apt-get install -y libncurses5-dev

#https://dba.stackexchange.com/questions/9654/could-not-find-curses-error-when-installing-mysql-from-source

#apt-get install zlib-devel

sudo apt-get install -y zlib1g zlib1g-dev

#https://stackoverflow.com/questions/40576661/error-cannot-find-lz-building-mariadb-on-a-debian-based-container

#https://www.systutorials.com/how-to-install-the-zlib-library-in-ubuntu/

 

#Delete all user mysql

userdel -r mysql

userdel -g mysql

 

cd /opt/setup

echo​​ "####################################################################"

echo "#  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ Download Package  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ #"

echo "####################################################################"

wget -O mariadb-10.3.17.tar.gz ​​ https://downloads.mariadb.org/interstitial/mariadb-10.3.17/source/mariadb-10.3.17.tar.gz/from/http%3A//ftp.hosteurope.de/mirror/archive.mariadb.org/

#Extract the tarball

tar xvf mariadb-10.3.17.tar.gz

 

cd mariadb-10.3.17

chown -R root.root .

echo "####################################################################"

echo "#  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ Build MariaDB from source  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ #"

echo "####################################################################"

 

 

cmake . -DCMAKE_INSTALL_PREFIX:PATH=$DIR_DATA

make

make install

 

#cd /opt/mysql/mariadb

#ln -s lib lib64

 

############# Before Starting MariaDB

#create user mysql

sudo useradd -r mysql

sudo groupadd mysql​​ 

sudo useradd -r -g mysql mysql

chown -R mysql.mysql $DIR_DATA

cd $DIR_DATA

#create DB current location: /opt/mysql

scripts/mysql_install_db --user=mysql

 

#chown -R root.root .​​ 

#chown -R mysql /opt/mysql/data

PATH=$PATH:$DIR_DATA/bin

 

#Add /usr/local/mysql/bin to user pi’s PATH.

su​​ 

#Also root user’s PATH.

PATH=$PATH:$DIR_DATA/bin

 

#Start the​​ MariaDB daemon

sudo bin/mysqld_safe --datadir='/opt/mysql/data'

 

#sudo mysql_secure_installation

Sau khi chạy xong mất khoảng thời gian 1-2h và không có lỗi là thành công.

Bước 2: secure install mysql

cd /opt/mysql

bin/mysql_secure_installation

sau đó bạn​​ tùy chọn đặt password user root, bỏ​​ login từ​​ xa đến mysql, xóa DB test…

Bước 3: Create services

sudo nano /etc/systemd/system/mariadb.service

#Paste

[Unit]

Description=MariaDB database server

After=network.target

After=syslog.target

 

[Service]

Type=simple

PrivateNetwork=false

User=mysql

Group=mysql

CapabilityBoundingSet=CAP_IPC_LOCK

PermissionsStartOnly=true

ExecStart=/opt/mysql/bin/mysqld_safe --basedir=/opt/mysql --datadir=/opt/mysql/data

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

 

Restart=on-abort

RestartSec=5s

UMask=007

PrivateTmp=false

LimitNOFILE=16364

 

[Install]

WantedBy=multi-user.target

Alias=mysql.service

Alias=mysqld.service

 

Kill hết process MariaDB hiện có

sudo pkill mysqld

Start và kiểm tra status MariaDB

sudo systemctl start mariadb

sudo systemctl status mariadb

Bước 4: Khởi động MariaDB khi bật server

sudo systemctl enable mariadb

Bước 5: Để​​ truy cập vào quản lý mariadb

cd /opt/mysql

bin/mysql -u root -p

 

chúc các bạn thành công!

 

 

Tham khảo:

https://www.linuxbabe.com/raspberry-pi/compile-mariadb-source-raspbian-jessie

https://notes.sagredo.eu/other-contents-186/installing-mariadb-from-source-153.html

 

 

 

 

SaKuRai

Xin chào, Mình là Sakurai. Blog này là nơi để note lại và chia sẻ những kiến thức, kinh nghiệm mà mình và anh em trong Team. Cảm ơn các bạn đã quan tâm theo dõi!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *