Mairadb source compilation and installation

Keywords: Linux MySQL MariaDB Database cmake

Source compilation and installation of Mairadb

1. Install the dependent components required by the environment first

[root@node6 ~]# yum -y install bison bison-devel zlib-devel libcurl-devel \
libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutlsevel \
libxml2-devel openssl-devel libevent-devel libaio-devel 

2. Create required users

[root@node6 ~]#useradd -r -s /sbin/nologin -d /data/mysql mysql

3. Create the data storage directory and modify the primary group as mysql user

[root@node6 ~]#mkdir /data/mysql
[root@node6 ~]#chown -R mysql.mysql /data/mysql/

4. Upload the downloaded source package to the server. The version number used here is mariadb-10.2.23. Unzip the source package after uploading.

[root@node6 ~]#tar xf mariadb-10.2.23.tar.gz
[root@node6 ~]#du -sh mariadb-10.2.23.tar.gz  mariadb-10.2.23
69M mariadb-10.2.23.tar.gz
507M    mariadb-10.2.23

5. Enter the mariadb decompression directory and start compiling and installing mariadb

[root@node6 ~]#cd mariadb-10.2.23
[root@node6 ~/mariadb-10.2.23]#cmake . \
> -DCMAKE_INSTALL_PREFIX=/app/mysql \
> -DMYSQL_DATADIR=/data/mysql/ \
> -DSYSCONFDIR=/etc \
> -DMYSQL_USER=mysql \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
> -DWITH_DEBUG=0 \
> -DWITH_READLINE=1 \
> -DWITH_SSL=system \
> -DWITH_ZLIB=system \
> -DWITH_LIBWRAP=0 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci

# Make-j 4 uses CPU multithreading, but it depends on the actual number of cores of CPU
[root@node6 ~/mariadb-10.2.23]#make -j 4 && make install 

6. Initialize database

[root@node6 /app/mysql]#scripts/mysql_install_db --user=mysql --datadir=/data/mysql

7. Check whether the data storage directory has generated files and directories

[root@node6 /app/mysql]#ls /data/mysql/ -l
total 110620
-rw-rw---- 1 mysql mysql    16384 May  2 11:34 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 May  2 11:34 aria_log_control
-rw-rw---- 1 mysql mysql      938 May  2 11:34 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 May  2 11:34 ibdata1
-rw-rw---- 1 mysql mysql 50331648 May  2 11:34 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 May  2 11:34 ib_logfile1
drwx------ 2 mysql root      4096 May  2 11:34 mysql
drwx------ 2 mysql mysql       20 May  2 11:34 performance_schema
drwx------ 2 mysql root         6 May  2 11:34 test

8. Configure the environment variables of mariadb

[root@node6 /app/mysql]#vim /etc/profile.d/mysql.sh
export PATH=/app/mysql/bin:$PATH
[root@node6 /app/mysql]#. /etc/profile.d/mysql.sh

9. Copy the system template configuration file to / etc and change its name to my.cnf. Overwrite the system's own configuration file

[root@node6 /app/mysql]#cp support-files/my-huge.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y

10. Copy the mariadb startup script to / etc/init.d/ and name it mysqld, add it to the startup item, and then start the service

[root@node6 /app/mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[root@node6 /app/mysql]#chkconfig --add mysqld
[root@node6 /app/mysqlservice mysqld start
Starting mysqld (via systemctl):                           [  OK  ]

11. Enter the maridb database operation interface

[root@node6 ~]#mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.2.23-MariaDB-log 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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> 

Now that the database is installed, you can log in to the database for a series of operations

Posted by Martin18 on Mon, 18 Nov 2019 08:09:33 -0800