How to switch from MySQL to MariaDB database on Ubuntu Linux

|

,

|

This post teaches how to switch from MySQL to MariaDB database server on Ubuntu 16.04 LTS, due to MariaDB’s increasing popularity. It involves removing MySQL and installing MariaDB, with the process detailed through step-by-step commands. MariaDB functions as a direct drop-in replacement for MySQL, meaning applications dependent on MySQL will not experience interruptions post-installation.

This article explains switching from MySQL to MariaDB database server on Ubuntu Linux.

One might choose to switch from MySQL to MariaDB for several reasons. One of the main reasons is that MariaDB is a community-driven open-source project, whereas Oracle Corporation owns MySQL. This means that MariaDB tends to have more frequent and significant updates and a more active community of developers contributing to its development.

MariaDB generally performs better than MySQL, particularly when handling complex queries. MariaDB also includes some features that MySQL does not have, such as the ability to use multiple storage engines for different tables within the same database.

Overall, it’s worth considering switching from MySQL to MariaDB, especially if you value open-source software and want to stay up-to-date with the latest developments in database technology.

MariaDB is a drop-in replacement for MySQL. This means it operates and functions like MySQL. If you uninstall MySQL and install MariaDB, applications that depend on MySQL won’t know the difference after installing MariaDB.

Removing MySQL Database Server

To get rid of MySQL from Ubuntu, run the commands below.

sudo systemctl stop mysql.service
sudo apt-get remove mysql-server mysql-common libmysqlclient18

After running the above commands, continue below to install the MariaDB database server.

Installing MariaDB Database Server

Once MySQL is removed from Ubuntu, run the commands below to install MariaDB.

sudo apt-get install mariadb-server mariadb-client libmariadbclient18

The commands above should install the stable version of the MariaDB database server from Ubuntu repositories.

During the installation, you may get the message below that the old data directory location will be saved at the new location. Accept and continue.

┌────────────────────┤ Configuring mariadb-server-10.1 ├──────
│ The old data directory will be saved at new location
│ A file named /var/lib/mysql/debian-*.flag exists on this system. The
│ number indicates a database binary format version that cannot
│ automatically be upgraded (or downgraded).
│ Therefore the previous data directory will be renamed to
│ /var/lib/mysql-* and a new data directory will be initialized at
│ /var/lib/mysql.
│ Please manually export/import your data (e.g. with mysqldump) if needed.
│                                  <Ok>
│
└────────────────────────────────────────────────────────

However, if you need to install the latest versions of MariaDB, run the commands below to add the MariaDB repository key to Ubuntu.

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Then, run the commands below to add the MariaDB version 10.2 branch or repository to Ubuntu.

sudo sh -c "echo 'deb [arch=amd64,i386] https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB-10.1.list"

Finally, run the commands below to install MariaDB from the 10.2 branches.

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

Add the repository below to install the latest unreleased 10.3 version.

sudo sh -c "echo 'deb [arch=amd64,i386] https://mirrors.evowise.com/mariadb/repo/10.3/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB-10.2.list"

Then, run the commands below to update to the latest 10.2 version.

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

After installation, the commands below can stop, start, and enable the MariaDB service to start up when the server boots.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure the MariaDB server.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

That’s it!

Now you can log in to MySQL by typing the commands below:

sudo mysql -u root -p

Summary:

Again, this post shows you how to convert from MySQL to a MariaDB database server. Since almost all Linux distributions are now switching from MySQL to MariaDB, it’s probably the best thing to switch for better system support.

You may also like the post below:


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



3 responses to “How to switch from MySQL to MariaDB database on Ubuntu Linux”

  1. Jon Avatar
    Jon

    This will not migrate your existing databases. Use with caution.

  2. vinci Avatar
    vinci

    This article is so misleading, I can’t believe it. As previously mentioned, this will NOT migrate your existing database. This is completely useless. It simply removes mysql and installs mariadb, completely ignoring what’s going to happen to the database itself.

  3. Zach Screwtheauthor Gilmore Avatar
    Zach Screwtheauthor Gilmore

    Does not address the very concern everyone came here for: how to switch from MySQL to MariaDB (which would include migration of course, but this article does not). Good tutorial on how to uninstall mysql and subsequently install mariadb, but not on how to switch… Thanks I deleted my database on accident..

Leave a Reply to JonCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading