To install the latest version of MariaDB on AlmaLinux, you need to add MariaDB repositories. To install version 10.7 of MariaDB, execute the following to add the MariaDB repo to your system:
curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.7
Next is to install MariaDB using the following:
sudo dnf install mariadb-server mariadb
After installing MariaDB server, you can configure it by editing /etc/my.cnf and/or files from /etc/my.cnf.d.
Next is to enable MariaDB service via:
sudo systemctl enable --now mariadb
To check the status of MariaDB, use:
systemctl status mariadb
To restart the MariaDB service, use:
sudo systemctl restart mariadb
If you want to change the location of the default datadir (directory where data are saved by MariaDB) which is /var/lib/mysql, you need to follow these steps:
- Create a directory where you want to save your data. In my case, I usually put it inside the Home* directory /home/mysql
mkdir /home/mysql
chown -R mysql:mysql /home/mysql
- Next is to stop MariaDB service, using:
systemctl stop mariadb
systemctl status mariadb - Assuming that the current datadir is /var/lib/mysql, copy the files from that location using:
cp -R -p /var/lib/mysql/* /home/mysql
- Then, edit MariaDB configuration to use the new data directory of MariaDB
- Run add the SELinux security context to /home/mysql before restarting MariaDB using:
semanage fcontext -a -t mysqld_db_t "/mnt/mysql-data(/.*)?"
restorecon -R /mnt/mysql-data - If you chose directory from /home folder, restarting MariaDB will fail or will generate an error as you need to turn off the ProtectHome by setting it to false in the mariadb.service file found at /usr/lib/systemd/system then run the following to start mariadb again with the new location of the data:
systemctl daemon-reload
systemctl start mariadb