“This is my 27th day of participating in the First Challenge 2022. For more details: First Challenge 2022.”

MariaDB

I don’t know how many people use MariaDB, but MariaDB is like the open source version of MySQL.

On January 16, 2008, MySQL AB announced that it had agreed to be acquired by Sun Microsystems Group for approximately $1 billion. The acquisition was completed on February 26, 2008. This also means that MySQL may go fully commercial in the future; MariaDB was conceived to remain open source under the GNU GPL.

MariaDB VS MySQL

MariaDB differs from MySQL, especially mysql5.x and MariaDB.

License agreement: MariaDB uses the GPL, while MySQL uses the GPL and Commercial License. MariaDB is more open source than MySQL.

In addition to the standard MyISAM, BLACKHOLE, CSV, MEMORY, ARCHIVE, and MERGE engines, MariaDB also provides the following storage engines in the MariaDB source code and binary package: Aria, XtraDB (peer replacement with InnoDB), FederatedX (peer replacement with Federated), Cassandra and other SQL storage engines.

I won’t discuss the differences in how to compile and install MariaDB on Debian.

Environment to prepare

According to the official documentation of MariaDB: mariadb.com/kb/en/compi… We need to rely on:

  • Cmake compiler
  • GCC compiler
  • OpenSSL
  • Bison depend on the package
  • Libcures depend on the package

Cmake compiler

The MariaDB cmake version is not as high as it should be.

apt install cmake -y
Copy the code

Installation successful:Note that you can also use a higher version of cmake, but you will need to compile it yourself.cmake.org/download/

GCC compiler

The Debian GCC compiler can be installed by:

apt install -y build-essential
Copy the code

OpenSSL

Not to mention OpenSSL, a lot of encryption is done by calling OpenSSL library functions directly:

apt install -y openssl libssl-dev
Copy the code

Bison and libcures

Hey, I don’t know what these two libraries are for, but just as a dependency ~ ~

Debian installation method:

apt install -y bison libncurses-dev
Copy the code

Download the source code

Next, we enter the official website to download the source code: mariadb.org/download

Before compilation, there is no Ali mirror source, today to see… There it is!

# Download source codeWget HTTP: / / https://mirrors.aliyun.com/mariadb//mariadb-10.6.5/source/ mariadb - 10.6.5. Tar. Gz# decompressionThe tar - xf mariadb - 10.6.5. Tar. Gz# enter directory
cdMariadb - 10.6.5Copy the code

Configuration and Compilation

MariaDB uses cmake for configuration and compilation.

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/mydata/data \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mariadb.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci
Copy the code

Here are the compile parameters:

  • DCMAKE_INSTALL_PREFIX: MariaDB installation address
  • DMYSQL_DATADIR: address for storing database files
  • DMYSQL_UNIX_ADDR: sock file storage address after compilation
  • DDEFAULT_CHARSET: Database encoding

Note that I use UTF8MB4 encoding here, mainly to accommodate special characters such as Emoji.

The above parameters need to be synchronized with my.cnf below (if you need to modify mine)

After that, we compile:

make
Copy the code

In addition, if your Linux device is multi-core, you can add the -j parameter to speed up compilation.

Compile ok, we install:

make install
Copy the code

Once installed, go to /usr/local and see our MariaDB:

Initialize the MariaDB

Now we initialize MariaDB, first creating a user:

groupadd -g 306 -r mysql
useradd -u 306 -g mysql -r -s /sbin/nologin mysql
Copy the code

Create SQL directory (above) :

mkdir /mydata/data -p
# attribute to mysql user
chown mysql:mysql /mydata/data
Copy the code

MariaDB installation address, modify file ownership to mysql user:

cd /usr/local/mariadb
chgrp mysql ./*
Copy the code

Initialize with an initialization script:

scripts/mariadb-install-db --user=mysql --datadir=/mydata/data
Copy the code

Configure my CNF

CNF: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf: /etc/mysql.cnf

vim /etc/my.cnf
Copy the code

My configuration (for more parameters, please see the official documentation) :

# Begin /etc/mysql/my.cnf
# The following options will be passed to all MySQL clients
[client]
port            = 3306
socket          = /tmp/mariadb.sock

# The MySQL serve
[mysqld]
port            = 3306
socket          = /tmp/mAriadb. Sock # MariaDB install address basedir =/usr/local/mariadb
datadir         = /mydata/data
#skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
skip-name-resolve = 0MariaDB does not listen on any IP and TCP ports # skip-networking # required unique ID between1 and 2^32 - 1
server-id       = 1
innodb_data_file_path = ibdata1:12M:autoextend

# You can innodb_buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 32M
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_write_io_threads = 4
innodb_read_io_threads = 4

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar withSQL #safe-updates [isamchk] key_buffer = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout # End  /etc/my.cnfCopy the code

Register service and environment variables

After that, we need to register as a system service to start MariaDB. Here we use systemctl as a service, not a service:

Register as a service:

vim /usr/lib/systemd/system/mariadb.service
Copy the code

Add content:

[Unit]
Description=MariaDB

[Service]
LimitNOFILE=10000
Type=simple
User=mysql
Group=mysql
PIDFile=/mydata/data/microServer.pid
ExecStart=/usr/local/mariadb/bin/mysqld_safe --datadir=/mydata/data
ExecStop=/bin/kill -9 $MAINPID

[Install]
WantedBy=multi-user.target
Copy the code

When this is done, use systemctl to configure the reload and start:

systemctl daemon-reload
systemctl start mariadb
Copy the code

Also add the bin directory in the MariaDB installation directory to the environment variable, for example:

PATH=/usr/local/mariadb/bin:$PATH
Copy the code

Setting the root user

To set up root and allow remote login, use the MariaDB help script:

Go to the bin folder in the MariaDB installation directory
cd /usr/local/mariadb/bin
Run the help script
./mariadb-secure-installation
Copy the code

After running the script, the password of user root will be set. If you need to log in remotely as user root, the most direct method is to enter MariaDB interactive mode and enter the password

Use mysql grant all PRIVILEGES on *.* to 'root'@'%' identified by 'with grant option; flush privileges;Copy the code

END

The MariaDB installation is complete.

Is the package manager faster to install? Have a chance to share with you the software package manager or Docker build.