Install MariaDB on CentOS 7
In this post, we’ll show you how to install MariaDB on a CentOS 7 instance hosted on DigitalOcean or Alibaba Cloud or any other cloud server.
MariaDB is basically MySQL under the hood. It’s a fork of MySQL, the database structure and indexes of MariaDB are the same as MySQL. This allows you to switch from MySQL to MariaDB without having to alter your applications since the data and data structures won’t change. In this guide, you will see commands with MySQL words. Don’t get confused.
Get the latest stable version of MariaDB and install it.
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo. [info] Adding trusted package signing keys... [info] Successfully added trusted package signing keys.
sudo yum install MariaDB-server MariaDB-devel -y
. . . Installed: MariaDB-devel.x86_64 0:10.4.11-1.el7.centos MariaDB-server.x86_64 0:10.4.11-1.el7.centos Dependency Installed: MariaDB-client.x86_64 0:10.4.11-1.el7.centos MariaDB-common.x86_64 0:10.4.11-1.el7.centos MariaDB-compat.x86_64 0:10.4.11-1.el7.centos boost-program-options.x86_64 0:1.53.0-27.el7 galera-4.x86_64 0:26.4.3-1.rhel7.el7.centos lsof.x86_64 0:4.87-6.el7 Complete!
Start MariaDB service
sudo systemctl start mariadb.service
Enable it to start automatically when you reboot the server
sudo systemctl enable mariadb.service
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
Secure the installation
Enter root password and other details
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 haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] Y New password: Re-enter new 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 ... 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] Y ... Success! 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 - 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 ... 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!
Installation is done.
The following steps lets you know how to login to MariaDB console and create database and assign privileges;
Login to MariaDB console as root
mysql -u root -p
Enter password when prompted.
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.4.11-MariaDB MariaDB Server 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)]>
Create a database
MariaDB [(none)]> CREATE DATABASE bugzilla; Query OK, 1 row affected (0.001 sec)
Create a user
MariaDB [(none)]> CREATE USER 'ubugzilla'@'localhost' IDENTIFIED BY 'Password'; Query OK, 0 rows affected (0.003 sec)
Assign the newly created user to your database
MariaDB [(none)]> GRANT ALL PRIVILEGES ON bugzilla.* TO 'ubugzilla'@'localhost'; Query OK, 0 rows affected (0.020 sec)
MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.001 sec)
Exit MariaDB console
There’s one more thing to do. We need to change the MariaDB configuration file to allow packets upto 16M and allow smaller words as indexes.
sudo vi /etc/my.cnf.d/server.cnf
Add these following lines.
#Bugzilla Settings #Allow packets up to 16M max_allowed_packet=16M #Allow small words in full-text indexes ft_min_word_len=2
Restart MariaDB server
sudo systemctl restart mariadb.service