How to Install MariaDB 10.4 on Ubuntu 18.04 (Bionic Beaver)

7120
Share:
how-to-install-mariadb-10-4-on-ubuntu-18-04-bionic-beaver

Ubuntu 18.04 Bionic Beaver actually comes with MariaDB, but the default version on upstream repositories are still using version 10.1. How if we want to use the latest version (10.4 at the time of this writing)?

Dump Databases

If you already have some databases on your existing MySQL/MariaDB installation, please back them up first. Here's my post explaining how to backup MySQL databases, but if you're in a hurry, the command to backup all databases is:

$ mysqldump --opt -u [uname] -p[pass] --all-databases > [backupfile.sql]

This process could take some time depends on the size of your existing databases. Please wait until the process completed or you might lose your database(s).

Remove Existing Mysql/MariaDB Installation

To remove existing MySQL/MariaDB installation, type this command:

$ sudo apt remove mariadb-server

if you have MariaDB. If you're using MySQL server, use this command:

$ sudo apt remove mysql-server (if you have MySQL)

After pressing "Enter" and prompted for password, you should see something similar with this:

Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages were automatically installed and are no longer required:
  galera-3 mariadb-server-10.1 mariadb-server-core-10.1 socat
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mariadb-server
0 upgraded, 0 newly installed, 1 to remove and 199 not upgraded.
After this operation, 65,5 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 372371 files and directories currently installed.)
Removing mariadb-server (1:10.1.38-0ubuntu0.18.04.1) ...

Now we're ready to continue with installation.

MariaDB 10.4 Installation

Install software-properties-common

$ sudo apt install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
software-properties-common
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 9996 B of archives.
After this operation, 201 kB of additional disk space will be used.
Get:1 http://asia-southeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/main amd64 software-properties-common all 0.96.24.32.11 [9996 B]
Fetched 9996 B in 0s (661 kB/s)
Selecting previously unselected package software-properties-common.
(Reading database ... 60380 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.96.24.32.11_all.deb ...
Unpacking software-properties-common (0.96.24.32.11) ...
Setting up software-properties-common (0.96.24.32.11) ...
Processing triggers for dbus (1.12.2-1ubuntu1.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

Add MariaDB apt Repository

Next step is to configure yum to install from MariaDB Corporation's MariaDB Package Repository by using the MariaDB Package Repository setup script.

MariaDB Corporation provides a MariaDB Package Repository for several Linux distributions that use apt to manage packages. This repository contains software packages related to MariaDB Server, including the server itself, clients and utilities, client libraries, plugins, and Mariabackup. The MariaDB Package Repository setup script automatically configures your system to install packages from the MariaDB Package Repository. It will:

  • Create new repository definition file on /etc/apt/sources.list.d called mariadb.list.
  • Import GPG public keys used to verify the signature of MariaDB software packages. To avoid this step you can use the --skip-key-import option.
  • Update your system's package information.

To use the script, execute the following command:

$ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

It will responds with something like this:

[info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
[info] Adding trusted package signing keys...
[info] Running apt-get update...
[info] Done adding trusted package signing keys.

However, if you just want to download the script rather than executing it, then you can do so in the following way:

$ curl -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

Install MariaDB 10.4

Next step is the actual installation of MariaDB 10.4. On your terminal, enter this command:

$ sudo apt install mariadb-server

It will respond with something like this:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
galera-4 libaio1 libcgi-fast-perl libcgi-pm-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl
libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmariadb3
libmysqlclient20 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.4 mariadb-client-core-10.4 mariadb-common
mariadb-server-10.4 mariadb-server-core-10.4 mysql-common socat
Suggested packages:
libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx
mariadb-test tinyca
The following NEW packages will be installed:
galera-4 libaio1 libcgi-fast-perl libcgi-pm-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl
libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmariadb3
libmysqlclient20 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.4 mariadb-client-core-10.4 mariadb-common
mariadb-server mariadb-server-10.4 mariadb-server-core-10.4 mysql-common socat
0 upgraded, 28 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.1 MB of archives.
After this operation, 199 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Type "Y" followed by "Enter". Installation will be processed and it will take a few seconds to complete, depends on your internet connection.

Verify Installation

Once the installation process finished, we should verify that we've correctly installed MariaDB 10.4. At your shell, type:

$ mysql --version

You should see something like this:

mysql  Ver 15.1 Distrib 10.4.8-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

MariaDB configuration

Usually the first thing you would've done after MariaDB installation is setting up a password for unprotected superuser account. This is not the case now. But if you want to do it anyway, to set root password just type this command:

$ sudo mysql

Your terminal will change to MariaDB monitor. It's like a terminal where you can enter your SQL commands there. To set root password, enter this command:

MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("verysecret");

Change "verysecret" with your preferred password.

If you've forgotten your root password, no problem — you can still connect using sudo and change the password.

Add User

To add another user, supply these commands to your MariaDB monitor:

MariaDB [(none)]> CREATE USER 'adjie'@'localhost' IDENTIFIED BY 'verysecret';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'adjie'@'localhost' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;

As usual, change "verysecret" with your preferred password.

Restore Databases

Although in most cases you should still able to see your existing database after upgrade to MariaDB 10.4, it's still possible that your databases wiped out. No worries, if you followed this guide exactly as it is, you should already have database backup. To restore your database using this command:

$ mysql -u [uname] -p[pass] < [backupfile.sql]

Final Words

I hope that you now know how to install MariaDB 10.4 on Ubuntu 18.04 Bionic Beaver. If you run into any issues or have any feedback feel free to drop a comment below.

Update

I've updated the article with newer Ubuntu version (20.04 - Focal Fossa) in the new article How to Install MariaDB 10.4 on Ubuntu 20.04 Focal Fossa.

Tags
Share:

1 comment

Leave a reply

Your email address will not be published. Required fields are marked *