Hamsa K
Editor
9 min read | 3 years ago

How to Install Mariadb on Centos 8

Install mariadb on centos 8/RHEL 8

MariaDB Server is one of the most popular open source relationaldb.MariaDB is robust, fast and Scalable with rich storage engines. Recent new functionality includes advanced clustering with Galera Cluster 4, compatibility features with Oracle Database and Temporal Data Tables, allowing one to query the data as it stood at any point in the past.

Step 1: Install mariadb using Appstream repo

you can install mariadb using yum and will get little bit old version.

[root@centos ~]# yum install mariadb-server

Also Read -> How to Install Gradle on Centos 8

Step 2: Install latest version using offcial repo

Now you need to add the Mariadb yum repository to system.

[root@centos ~]# vi /etc/yum.repos.d/mariadb.repo

Add below content to above file and save it.

We hope you are following "How to Install Mariadb on Centos 8" step by step carefully. The remaining steps will help you to finish the upgrade process..

 For Centos 8

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

 For RHEL 8

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/rhel8-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

you can install mariadb server with following commands.

centos 8

[root@centos ~]# yum install boost-program-options
[root@centos ~]# yum install --disablerepo=AppStream MariaDB-server MariaDB-client

RHEL 8

yum install boost-program-options
yum --disablerepo=rhel-8-for-x86_64-appstream-rpms install MariaDB-server MariaDB-client

once mariadb was installed, check service status and enable it on startup with the following commands.

[root@centos ~]# systemctl start mariadb
[root@centos ~]# systemctl enable mariadb
[root@centos ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.4.12 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Wed 2020-02-19 13:16:16 IST; 2s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 4226 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 4184 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSR>
  Process: 4182 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 4195 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 11527)
   Memory: 71.4M
   CGroup: /system.slice/mariadb.service
           └─4195 /usr/sbin/mysqld
Feb 19 13:16:15 centos mysqld[4195]: 2020-02-19 13:16:15 0 [Note] InnoDB: 10.4.12 started; log sequence number 61276; transaction id 21
Feb 19 13:16:15 centos mysqld[4195]: 2020-02-19 13:16:15 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Feb 19 13:16:15 centos mysqld[4195]: 2020-02-19 13:16:15 0 [Note] InnoDB: Buffer pool(s) load completed at 200219 13:16:15
Feb 19 13:16:15 centos mysqld[4195]: 2020-02-19 13:16:15 0 [Note] Plugin 'FEEDBACK' is disabled.
Feb 19 13:16:15 centos mysqld[4195]: 2020-02-19 13:16:15 0 [Note] Server socket created on IP: '::'.
Feb 19 13:16:16 centos mysqld[4195]: 2020-02-19 13:16:16 0 [Note] Reading of all Master_info entries succeeded
Feb 19 13:16:16 centos mysqld[4195]: 2020-02-19 13:16:16 0 [Note] Added new Master_info '' to hash table
Feb 19 13:16:16 centos mysqld[4195]: 2020-02-19 13:16:16 0 [Note] /usr/sbin/mysqld: ready for connections.
Feb 19 13:16:16 centos mysqld[4195]: Version: '10.4.12-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
Feb 19 13:16:16 centos systemd[1]: Started MariaDB 10.4.12 database server.


Also Read -> How to Install Ansible on Centos 8 

Step 3: secure mariadb

secure mariadb by running mysql_secure_installation.

[root@centos ~]# mysql_secure_installation
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] 
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]
 ... 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]
 ... 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]
 - 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]
 ... 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!

Step 4: Access Mariadb

To connect to the MariaDB server through the terminal as the root account then type below command.

[root@centos ~]# mysql -u root -p

it will ask mariadb root password and then it disaplays mariadb shell

Also Read -> How to Install Ruby on Rails on Centos 8

[root@centos ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.4.12-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)]>

step 5: create database

Login with mysql root password as shown above and then create one sample db like below.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]> create database lampdb;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create user 'lampuser'@'localhost' IDENTIFIED BY 'strongpassword';
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> grant all on lampdb.* TO 'lampuser'@'localhost';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit
Bye

Now you have successfully installed mariadb on centos 8/RHEL 8 server.

Also Read -> How to Install Apache CouchDB on Centos 8

 

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy