Forked from MySQL, created with love by original MySQL developers, MariaDB is one of the most popular open source database platforms to this date. MariaDB is guaranteed to stay open source. In this guide, we are going to see how to install MariaDB 10.x on CentOS 7.
Step 1: Add Repository
Add MariaDB repository using any text editor.
$ nano /etc/yum.repos.d/MariaDB.repo
Step 2: Add Repository
Add the following content into the repo file:
[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/10.3/centos7-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Step 3: Install MariaDB
The following command will install the MariaDB server and the client.
$ yum -y install MariaDB-server MariaDB-client MariaDB-common
Step 4: Enable and Start MariaDB service
We are going to enable MariaDB Server to auto start during boot then start the service.
$ systemctl enable mariadb
$ systemctl start mariadb
Step 5: Securing MariaDB
MariaDB comes with a built-in script to help secure a MariaDB server. The requires several user inputs. The following command will start the securing script:
$ mysql_secure_installation
Step 5a: Set root Password
Type in y when asked to set root password and type in the new password twice.
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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Step 5b: Remove Anonymous User
Type in y to remove the built-in anonymous user.
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!
Step 5c: Prevent root Access outside localhost
Type in y to disallow root access into the database outside the server itself.
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!
Step 5d: Remove Built-in Database
Type in y to remove the built-in database named test.
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!
Step 5e: Apply Privileges
Type in y to apply all the changes thus far.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Step 6: Test Database Access
At this point, the MariaDB server is fully configured and ready to serve. Connect to the database to ensure root credential is working.
$ mysql -u root -p
MariaDB [(none)]>
Congratulations! Your MariaDB Server 10.x is now fully configured and secured on CentOS 7.
User Management
To see the list of all existing MariaDB users:
MariaDB [(none}]> select host,user,password from mysql.users;
To remove all privileges for a user and delete the user:
MariaDB [(none)]> revoke all privileges, grant option from 'user'@'%';
MariaDB [(none)]> drop user 'user'@'%';
To grant all privileges to a user for a database:
MariaDB [(none)]> grant all privileges on database.* to 'user'@'%' identified by 'password';
MariaDB [(none)]> flush privileges;