Build MariaDB from source code on Ubuntu 18

Build MariaDB from source code on Ubuntu 18

 

Purpose: Build MariaDB from source to help you proactively build the correct version, select the appropriate options when building. For this example, I built MariaDB version 10.3.17 and saved it at location: / opt / mysql

The default data stored in / var / lib / mysql will be converted to / opt / mysql / data
Details of the steps are as follows:

Step 1: Copy the entire contents of the .sh file below into a build-mariadb-10.3.17-from-source file:

 

#!/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

After running, it takes about 1-2 hours and no errors are successful.

Step​​ 2: secure install mysql

cd /opt/mysql

bin/mysql_secure_installation

Then you optionally set the root user password, remove the remote login to mysql, delete the test DB ...

Step​​ 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 all​​ process MariaDB​​ 

sudo pkill mysqld

Start and check​​ status MariaDB

sudo systemctl start mariadb

sudo systemctl status mariadb

Step 4: Start​​ MariaDB​​ when start server

sudo systemctl enable mariadb

Step 5:​​ Access to mariadb management

cd /opt/mysql

bin/mysql -u root -p

good luck!

 

Reference:

https://mariadb.com/kb/en/compiling-mariadb-from-source/

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

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

 

 

 

 

BÀI VIẾT CÙNG CHUYÊN MỤC

Hướng Dẫn Sửa Lỗi Không Extend Được Ổ C Trên Windows Server 2025 Do Vướng Phân Vùng Recovery
Hướng Dẫn Sửa Lỗi Không Extend Được Ổ C Trên Windows ...

Hướng Dẫn Sửa Lỗi Không Extend Được Ổ C Trên Windows Server 2025 Do Vướng Phân ...

Cảnh Báo Đỏ: Chiến Dịch FortiBleed Rò Rỉ Hàng Chục Nghìn Thông Tin Quản Trị Tường Lửa Fortinet
Cảnh Báo Đỏ: Chiến Dịch FortiBleed Rò Rỉ Hàng Chục ...

Cảnh Báo Đỏ: Chiến Dịch FortiBleed Rò Rỉ Hàng Chục Nghìn Thông Tin Quản Trị ...

Không copy được giữa máy Windows và máy ảo qua mRemoteNG/RDP: Nguyên nhân và cách sửa
Không copy được giữa máy Windows và máy ảo qua ...

mRemoteNG Remote Desktop RDP Clipboard Redirection rdpclip.exe VPS Windows ...

Hướng dẫn bật Nested Virtualization trên ESXi để chạy Android Studio Emulator trong máy ảo Windows
Hướng dẫn bật Nested Virtualization trên ESXi để chạy ...

Nested Virtualization ESXi VMware Android Studio Android Emulator WHPX Hyper-V ...

PITR (Point In Time Recovery) là gì? Khôi phục Database về đúng thời điểm cần thiết
PITR (Point In Time Recovery) là gì? Khôi phục ...

PITR, Point In Time Recovery, PITR là gì, Database Recovery, PostgreSQL PITR, ...