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:

  1. 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

  2. Next is to stop MariaDB service, using:

    systemctl stop mariadb
    systemctl status mariadb

  3. Assuming that the current datadir is /var/lib/mysql, copy the files from that location using:

    cp -R -p /var/lib/mysql/* /home/mysql

  4. Then, edit MariaDB configuration to use the new data directory of MariaDB
  5. 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

  6. 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

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments