Ubuntu Linux System MariaDB10.3 Source Compilation Installation Notes

Posted by matthiasone on Sun, 19 May 2019 07:52:21 +0200

MySQL and Maria Widenius are real relatives and sisters, named after Michael Widenius, the father of MySQL, who was born to his first wife, My Widenius, and Maria Widenius, the daughter of his current wife.After Oracle acquired Sun, MySQL, previously sold to Sun by Monty, was inherited by Oracle.Oracle is the world's largest commercial database manufacturer and, driven by the Save MySQL campaign, Monty led the development and promotion of MariaDB due to concerns about Oracle's dictatorship of MySQL and the uncertainty of future closed sources.MariaDB is the largest branch of the original MySQL, and the source code compilation and installation process basically inherits from MySQL.The RDBMS used in previous work were MySQL, and now the new project requires MariaDB, try installing it locally first.My system environment is Ubuntu 18.04(LTS).Since MySQL 5.7 has been compiled and installed from source code, additional modifications are required to install MariaDB.Record the installation here.

1. Installation Dependency

Source compilation and installation requires several Linux environment dependencies, Ubuntu system reference https://mariadb.com/kb/en/library/building-mariadb-on-ubuntu/ .Copy the commands inside to the terminal and run them separately.

apt install software-properties-common devscripts equivs
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository --update --yes --enable-source 'deb [arch=amd64] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu '$(lsb_release -sc)' main'
apt-get build-dep mariadb-10.3

Download Source

Current 10.3 is Stable, 10.4 or RC, download 10.3 https://downloads.mariadb.org/mariadb/.

https://downloads.mariadb.org/
wget http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb//mariadb-10.3.14/source/mariadb-10.3.14.tar.gz
tar -xz -f mariadb-10.3.14.tar.gz
cd mariadb-10.3.14/ ; ls

(3) Creating users

If MySQL is not installed locally, mariadb in the following command can be changed to mysql.

groupadd mariadb
useradd -g mariadb mariadb
mkdir -p /usr/local/mariadb/data
chown -R mariadb /usr/local/mariadb
chgrp -R mariadb /usr/local/mariadb

(4) Compile and Install

The default global configuration file for MySQL is'/etc/my.cnf', which MariaDB still uses.However, since MySQL is already running locally, to avoid conflicts, the configuration file directory is re-specified with the'-DEFAULT_SYSCONFDIR'option.If MySQL is not installed locally, this option is omitted and MariaDB in the command can be changed to mysql.

cmake -DEFAULT_SYSCONFDIR=/opt -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/usr/local/mariadb/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all
make && make install

Initial service

Start by writing a simple configuration file manually, since port 3306 of the original MySQL is already occupied, a new port is reassigned.

vim /opt/my.cnf


[client]
port = 6033
socket = /tmp/mariadb.sock

[mysqld]
socket = /tmp/mariadb.sock
basedir = /usr/local/mariadb
datadir = /usr/local/mariadb/data
pid_file = /usr/local/mariadb/data/linux.pid

Then initialize the MariaDB installation, for more information https://mariadb.com/kb/en/library/mysql_install_db/ .Configuration files are specified during initialization with the'--defaults-file'option.

/usr/local/mariadb/scripts/mysql_install_db --defaults-file=/opt/my.cnf --user=mariadb --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data

Once initialization is complete, MariaDB can be started.Refer to the installation documentation locally because MySQL has been written to the service https://mariadb.com/kb/en/library/generic-build-instructions/ , manually started.

/usr/local/mariadb/bin/mysqld_safe --defaults-file=/opt/my.cnf --port=6033 --user=mariadb &

If there is no MySQL locally, you can write MariaDB to the startup service, for example:

cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
update-rc.d mysqld defaults
service mysqld start

Once the service is started, you can see the daemon daemon of MySQL / MariaDB in the process list.Next, run a database security installation processing script that comes with MariaDB.Detailed reference https://mariadb.com/kb/en/library/mysql_secure_installation/ .The script is prepared for database installation for production environments and does the following four main things:

  • Set password for root account
  • Settings to prevent root accounts from logging on outside of localhost
  • Remove anonymous accounts
  • Remove test libraries (test libraries are accessed by default by anonymous account connections and are used for Debug s)
/usr/local/mariadb/bin/mysql_secure_installation --defaults-file=/opt/my.cnf

The program receives several manual inputs as follows.

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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): ( ˇˍˇ )Enter here(Not yet set up root Password?)( ˇˍˇ )
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y ( ˇˍˇ )Enter here y Start Setting root Password( ˇˍˇ )
New password: 
Re-enter new password: ( ˇˍˇ )Enter password twice in a row(Remember your 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 ( ˇˍˇ )Remove anonymous accounts here( ˇˍˇ )
 ... 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] n ( ˇˍˇ )Is Prohibited root Account Remote Access(Of course not for local use / Choice of production environment y)( ˇˍˇ )
 ... skipping.

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 ( ˇˍˇ )Remove Test Library( ˇˍˇ )
 - 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 ( ˇˍˇ )Reload Permission Table( ˇˍˇ )
 ... 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!

Connection Configuration

Here you can connect using MariaDB, start with a soft connection.

ln -s /usr/local/mariadb/bin/mysql /usr/bin/mariadb

Terminal command line connection.

mariadb --defaults-file=/opt/my.cnf --user=root --password=1024

This is the first time you have logged in to the MariaDB client window.

root@linux:~/mariadb-10.3.14# mariadb --defaults-file=/opt/my.cnf --user=root --password=1024
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.3.14-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

For local testing, account and password information can be written under the configuration file [client] group so that future connections do not have to be entered.

vim /opt/my.cnf


[client]
user = root
password = 1024
port = 6033
socket = /tmp/mariadb.sock

The configuration file needs to be restarted to take effect.

/usr/local/mariadb/bin/mysqladmin --defaults-file=/opt/my.cnf --user=root --password=1024 shutdown
/usr/local/mariadb/bin/mysqld_safe --defaults-file=/opt/my.cnf --port=6033 --user=mariadb &

Finally, connect MariaDB to modify the `user` permission table to allow the root account to connect remotely.

root@linux:~/mariadb-10.3.14# mariadb --defaults-file=/opt/my.cnf
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.14-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT `Host` FROM `mysql`.`user` WHERE `User` = 'root'\G
*************************** 1. row ***************************
Host: 127.0.0.1
*************************** 2. row ***************************
Host: ::1
*************************** 3. row ***************************
Host: linux
*************************** 4. row ***************************
Host: localhost
4 rows in set (0.001 sec)

MariaDB [(none)]> UPDATE `mysql`.`user` SET `Host` = '%' WHERE `User` = 'root' AND `Host` = 'linux';
Query OK, 1 row affected (0.002 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> 

At this point, the MariaDB can be accessed remotely from the root account using other database client tools.

Topics: MariaDB MySQL Database Oracle