MariaDB is a drop-in replacement for MySQL database server. Drop-in replacement means MariaDB works exactly like MySQL. When you remove MySQL server and install MariaDB, your applications using the database server won’t notice that change.
That’s because MariaDB is using the same core packages and services MySQL uses. The two big differences between the two software are licensing agreements and their owners.
You can read more about the two by researching online. When you’re ready to installing MariaDB, continue below.
Step 1: Update Ubuntu Servers
Before installing packages on Ubuntu systems, you must first update the server by fetching latest packages in Ubuntu repositories. Sometimes, if you don’t update, you may run into issues installing software.
To update Ubuntu systems, run the commands below.
sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove
The commands above update Ubuntu and remove obsoletes software if there are some available. You may have to restart your systems after getting rid of obsoletes kernels and headers.
Step 2: Install MariaDB Server
After updating your system, run the commands below to install MariaDB from Ubuntu default software repositories.
sudo apt-get install mariadb-server mariadb-client
After running the commands above, you’ll see a list of packages, include MariaDB package that are going to be installed. Type Y for yes to continue installing these packages. These are required for MariaDB to function.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient20
libreadline5 libterm-readkey-perl mariadb-client-10.0
mariadb-client-core-10.0 mariadb-common mariadb-server-10.0
mariadb-server-core-10.0 mysql-common
Suggested packages:
libmldbm-perl libnet-daemon-perl libsql-statement-perl
libipc-sharedcache-perl mailx mariadb-test tinyca
The following NEW packages will be installed:
libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient20
libreadline5 libterm-readkey-perl mariadb-client mariadb-client-10.0
mariadb-client-core-10.0 mariadb-common mariadb-server mariadb-server-10.0
mariadb-server-core-10.0 mysql-common
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.7 MB of archives.
After this operation, 150 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
After installing MariaDB, continue below to secure the database server. You’ll create a new password, change some less secure default settings and disable remote login for the root user.
Step 3: Configuring MariaDB
To configure MariaDB, run the commands script below.
sudo mysql_secure_installation
When you run the script above, you’ll be prompted to answer series of security questions. Follow the steps below to complete the task.
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 authorisation. Set 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... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - 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!
At this point, MariaDB should be installed and ready to use. To check the version of MariaDB installed, run the commands below.
mysql -V
Other commands to remember
Other commands to remember:
Stop MariaDB — >sudo systemctl stop mysql.service
Start MariaDB –>sudo systemctl start mysql.service
Enable MariaDB –>sudo systemctl enable mysql.service
PS: If you need to install the latest version of MariaDB directly from developer’s repository, follow the steps below:
Step 4: Installing MariaDB Latest Version
First add the repository key by running the commands below.
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
Then add the repository of the latest version. You need to edit the version number accordingly.
sudo sh -c 'echo "deb http://ftp.osuosl.org/pub/mariadb/repo/10.1/ubuntu `lsb_release -cs` main" >> /etc/apt/sources.list.d/MariaDB.list'
At the time of this post, the latest version was 10.1
Update your system and the latest version of MariaDB will be installed.
sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove
Enjoy!