Getting Started with MariaDB

By Daniel Bartholomew
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies

About this book

In the modern age, storing data is of paramount importance, and this is where databases enter the picture. MariaDB is a relatively new database that has become very popular in a short amount of time. It is a community-developed fork of MySQL and it is designed to be an enhanced and backward compatible database solution.

Getting Started with MariaDB is a practical, hands-on, beginner-friendly guide to installing and using MariaDB. This book will start with the installation of MariaDB before moving on to the basics. You will then learn how to configure and maintain your database with the help of real-world examples.

Getting Started with MariaDB literally starts at square one by walking you through the basics of what you need to know about MariaDB. This book will teach you how to install MariaDB as well as how to configure it. Following that, you will then be shown how to secure MariaDB. This book will also teach you common commands and will help you learn how to maintain a MariaDB server.

Publication date:
October 2013


Chapter 1. Installing MariaDB

Before we can start using MariaDB, we have to install it. The MariaDB source code can be compiled to run on a wide variety of different platforms and system architectures, but there are pre-compiled packages available for Windows and Linux which make the process much easier.

There are several packages types, including the source code:

  • Windows MSI packages

  • Linux YUM packages

  • Linux APT packages

  • Linux and Windows binaries

  • Source code

Windows MSI packages are for computers and servers running Windows 8, Windows XP, and everything in between. Linux .rpm packages are used on distributions, such as Fedora, CentOS, and Red Hat, which use the Yellow Dog Updater, Modified (YUM) package manager. Linux .deb packages are used on distributions, such as Debian and Ubuntu, which use the Advanced Packaging Tool (APT) package manager. We will cover how to install all these types in this chapter.

We will cover the fourth type, Linux and Windows Binaries, briefly. These packages are mainly useful to experienced users of MariaDB who have nonstandard setups. The Windows binaries come in a ZIP file (.zip) and the Linux binaries in a gzipped tar file (.tar.gz).

Even though MariaDB binaries are recommended for more experienced users, installing them is not especially difficult. Check the following links for the official instructions for installing the Linux and Windows binary packages, respectively:

We will also go over how to install MariaDB on Mac OS X. Packages for it are not supplied by the MariaDB developers, but by a third party.

The choice of which type of package to install is an easy one, just use whichever is appropriate for your system. If you are on Windows, use the MSI package. If you are on Ubuntu or Debian, use the APT packages. And if you are on Red Hat, Fedora, or CentOS, uses the YUM packages.

The next few sections contain instructions for each type, but before we get to that we need to talk about series. And no, it has nothing to do with baseball, but it does lend itself to a baseball analogy.


Choosing a MariaDB series

MariaDB development proceeds along multiple development tracks called series . There is a stable series and several maintenance series. Often, there is also a development series. This is similar to the Debian practice of having both a stable and unstable version.

The development series

The development series of MariaDB is where major new features and capabilities are introduced. Think of this like minor league baseball where the up and coming future stars are introduced and are polished and honed to perfection. At any given time, the quality of the current development release could range from Alpha (which has no guarantees that it will even work reliably) to Beta (which is feature complete but generally needs lots of bug fixing and testing) to Release Candidate (which is ready for general use except for some additional testing and minor bug fixing).

During the development cycle, there will generally be several alpha releases, where new features are introduced, followed by a couple beta releases where the code is refined and polished, followed by one or two RC releases where final fixes and polishing take place. The final step for any development series is when it is declared stable and moves into the major league stable series.


If the current development series release is an RC release, we may want to choose that over the current stable release. Otherwise, it is generally best to stick with whatever the current stable release is.

The stable series

For most users just starting out, whatever series is marked stable is the one to use. This is the major league series. The best and most complete version currently available. After a development series has reached a sufficient level of quality to be considered stable, it is promoted to this series and becomes the recommended version of MariaDB.

After being marked as stable, the MariaDB Foundation has a policy that major MariaDB version will be well supported with bug and security fixes and maintenance releases for a period of at least five years. This is regardless of whether it is the current stable series, or if it is one of the maintenance series. It all depends on when it first became stable.

The maintenance series

When a series moves from development to stable, whatever series was stable is moved to the maintenance series. This means that it will still receive bug fixes but it is no longer the recommended or preferred release of MariaDB. Think of it as the hall of fame—full of great previous releases of MariaDB that, while still excellent, have been replaced by a new generation. At any given time there may be three, four, or more MariaDB major versions in the maintenance series.

We'll now go through installing MariaDB for each of the major operating systems. First Windows, then Mac OS X, then Debian and Ubuntu Linux, then Fedora, Red Hat, and CentOS Linux, and lastly other Linux distributions.


Installing MariaDB on Windows

There are two types of MariaDB downloads for Windows: ZIP files and MSI packages. As mentioned previously, the ZIP files are similar to the Linux binary .tar.gz files and they are only recommended for experts who know they want it. If we are starting out with MariaDB on Windows, it is recommended to use the MSI packages. Here are the steps to do just that:

  1. Download the MSI package from First click on the series we want (stable, most likely), then locate the Windows 64-bit or Windows 32-bit MSI package. For most computers, the 64-bit MSI package is probably the one that we want, especially if we have more than 4 Gigabytes of RAM. If you're unsure, the 32-bit package will work on both 32-bit and 64-bit computers.

  2. Once the download has finished, launch the MSI installer by double-clicking on it. Depending on our settings we may be prompted to launch it automatically. The installer will walk us through installing MariaDB.

  3. If we are installing MariaDB for the first time, we must be sure to set the root user password when prompted.

  4. Unless we need to, don't enable access from remote machines for the root user or create an anonymous account. We'll cover creating regular user accounts in Chapter 4, MariaDB User Account Management.

  5. The Install as service box is checked by default, and it's recommended to keep it that way so that MariaDB starts up when the computer is booted. The Service Name textbox has the default value MySQL for compatibility reasons, but we can rename it if we like.

  6. Check the Enable networking option, if you need to access the databases from a different computer. If we don't it's best to uncheck this box. As with the service name, there is a default TCP port number (3306) which you can change if you want to, but it is usually best to stick with the default unless there is a specific reason not to.

  7. The Optimize for transactions checkbox is checked by default. This setting can be left as is.

  8. There are other settings that we can make through the installer. All of them can be changed later by editing the my.ini file (more on that in Chapter 2, Configuring MariaDB), so we don't have to worry about setting them right away.

  9. If our version of Windows has User Account Control enabled, there will be a pop-up during the installation asking if we want to allow the installer to install MariaDB. For obvious reasons, click on Yes.

  10. After the installation completes, there will be a MariaDB folder added to the start menu. Under this will be various links, including one to the MySQL Client, which we will find out more about in Chapter 5, Using MariaDB).


    If we already have an older version of MariaDB or MySQL running on our machine, we will be prompted to upgrade the data files for the version we are installing, it is highly recommended that we do so.

  11. Eventually we will be presented with a dialog box with an installation complete message and a Finish button. If you got this far, congratulations! MariaDB is now installed and running on your Windows-based computer. Click on Finish to quit the installer.

To learn about installing MariaDB on Mac OS X or Linux, read on. Otherwise, feel free to skip to the After the installation section at the end of this chapter.


Installing MariaDB on Mac OS X

One of the easiest ways to install MariaDB on Mac OS X is to use Homebrew, which is an Open Source package manager for that platform. Before you can install it, however, you need to prepare your system. The first thing you need to do is install Xcode; Apple's integrated development environment. It's available for free in the Mac App Store.

Once Xcode is installed you can install brew. Full instructions are available on the Brew Project website at but the basic procedure is to open a terminal and run the following command:

ruby -e "$(curl -fsSL"

This command downloads the installer and runs it. Once the initial installation is completed, we run the following command to make sure everything is set up properly:

brew doctor

The output of the doctor command will tell us of any potential issues along with suggestions for how to fix them. Once brew is working properly, you can install MariaDB with the following commands:

brew update
brew install mariadb

Unlike on Linux and Windows, brew does not automatically set up or offer to set up MariaDB to start automatically when your system boots or start MariaDB after installation. To do so, we perform the following command:

ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

To stop MariaDB, we use the unload command as follows:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

To learn about installing MariaDB on Linux, read on. Otherwise, skip to the After the installation section at the end of this chapter.


Installing MariaDB on Debian, Ubuntu, and Linux Mint

The procedure for installing MariaDB on Debian, Ubuntu, and Linux Mint is easy, and starts with a visit to the Repository Configuration Tool at:

This tool is used for APT-based Linux distributions such as Debian, Ubuntu, and Mint, YUM-based Linux distributions such as Fedora, CentOS, and Red Hat, and other distributions that have support for MariaDB built-in such as Mageia, Arch Linux, and openSUSE.

Before using the tool you need to know which version of Ubuntu, Debian, or Mint to use. If you do not know, an easy way to find out is with the following command:

cat /etc/lsb-release

Type the command into the terminal and you will get an output similar to the following:


The output shows that this machine is running Ubuntu 10.04 LTS "Lucid". So using the Repository Configuration Tool, click on Ubuntu, then 10.04 LTS 'lucid', then on the version or series of MariaDB you want to install. Lastly, click on the mirror you want to use. The tool will then output three pieces of text. The first are the commands to add the MariaDB repository to your system. The second contains the commands to install MariaDB, and the third contains the text and alternate instructions in case adding the repository using the first set of instructions did not work.

For example, the generated commands for adding a repository for MariaDB 10.0 on the 64-bit version of Ubuntu 12.04 LTS "Lucid" and using the osuosl mirror are as follows:

sudo apt-get install python-software-properties
sudo apt-key adv --recv-keys \
--keyserver 0xcbcb082a1bb943db 
sudo add-apt-repository \
'deb precise main'

The first command installs the python-software-properties package, which contains the helper command we will use. The second command installs the GPG key that is used to sign MariaDB packages. See the MariaDB package security section later in this chapter for more information on this. The third command adds the repository using the add-apt-repository command.

The displayed installation commands are as follows:

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

The mariadb-server package depends on the other MariaDB packages, so these two commands are all we need to install MariaDB. Once the second apt-get command finishes, MariaDB will be installed and running. Congratulations!

Jump ahead to the MariaDB package security section if you're interested in the MariaDB signing keys or skip to the After the installation section if you want to start using MariaDB right away.


Installing MariaDB on Fedora, Red Hat, and CentOS

The procedure for installing MariaDB on Fedora, Red Hat, and CentOS makes use of the Yellowdog Updater, Modified (YUM) package manager. There are two steps: first, create a repo file for MariaDB and second, install MariaDB.

To generate the required text for the repo file, we visit the MariaDB Repository Configuration Tool at:

This tool is used for both APT-based Linux distributions such as Debian and Ubuntu, and YUM-based Linux distributions such as Fedora, CentOS, and Red Hat.

Click on the distribution we are using, the release available, and the version of MariaDB we want to install. After doing so, contents of the appropriate repo file will be displayed.

For example, the generated text for MariaDB 10.0 on the 64-bit version of CentOS 6 is:

# MariaDB 10.0 CentOS repository list - created 2013-03-09 20:58 UTC 
name = MariaDB 
baseurl = 

The gpgkey line tells YUM where the MariaDB signing key is located. The gpgcheck line directs Yum to always use the signing key to verify the MariaDB packages. The first time we install MariaDB our system will not have the key so Yum will download it and install it. If Yum has never used the key before it will ask for confirmation whether it is OK to import the key. See the MariaDB package security section for more information on the MariaDB signing key.

Copy and paste the generated text from the repository configuration tool into a file using our favorite text editor. Naming the file something descriptive, such as MariaDB.repo, is recommended. Move the file to the /etc/yum.repos.d/ folder using a command similar to the following:

sudo mv -vi MariaDB.repo /etc/yum.repos.d/

Once the file is in place, we are ready to install MariaDB. Installing MariaDB from the command line is as simple as:

sudo yum install MariaDB-server MariaDB-client 

The capitalization of the package names is important. If we type mariadb-server instead of MariaDB-server, we'll get a package cannot be found error.

YUM will gather in all of the dependencies for MariaDB and present us with a list of things we need to install. If we are installing MariaDB on a new system, the list of packages YUM installs because of dependencies could be quite large. The following screenshot shows that there are more than 41 dependent packages that will be installed when we install MariaDB.

After answering y, the installation will get going and we will be prompted to accept the GPG signing key. We verify the fingerprint with y. Yum will then continue downloading and installing MariaDB and will end with a Complete! message.

As a final step of the installation, we start MariaDB with the following command:

sudo /etc/init.d/mysql start

If everything has gone well, we will see output similar to the following:

[[email protected] ~]$ sudo /etc/init.d/mysql start 
Starting MySQL..... SUCCESS!

MariaDB is now installed and running. Congratulations! Jump ahead to the After the installation section or continue on to read about the MariaDB Package Security.

Jump ahead to the MariaDB package security section if you're interested in the MariaDB signing keys or skip to the After the installation section if you want to start using MariaDB right away.


Installing MariaDB on other Linux distributions

MariaDB is also available on several other Linux distributions and even if no formal packages are provided the MariaDB developers provide generic Linux binaries that work with many versions of Linux. Instructions on how to install and use the generic binaries are available at

Before installing the binary packages, however, it is worth our while to look in our distribution's package manager to see if MariaDB is already there. For example, Mageia, Arch Linux, openSUSE, and others all include MariaDB in their distributions' repositories. For those Linux distributions (including these three) that the MariaDB developers are familiar with, installation instructions are provided using the MariaDB repository configuration tool (


MariaDB package security

The packages provided by the MariaDB developers are signed with a security key so that they can be verified by package managers such as Yum and Apt. The key signing and verification infrastructure on Linux is called Gnu Privacy Guard (GPG). It is a compatible Open Source version of Pretty Good Privacy (PGP) which is an industry standard data encryption, decryption, and verification system.

The identification number (GPG ID) of the MariaDB signing key is 0xcbcb082a1bb943db. For long-time users of GPG, this ID may seem a little long. That's because until recently, it was common to share a short form of the GPG ID. This is discouraged now because of a GPG's vulnerability; however many utilities will still display the short form by default. The long form of the ID is more secure, so this is what the MariaDB developers share when talking about the key. But, in case we want it, the short form of the ID is 1BB943DB (it's just the last eight characters of the long form ID). For the extra cautious, the full key fingerprint is:

1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB

The key IDs and fingerprint are also posted in the MariaDB Knowledgebase, which is the official location of the MariaDB documentation and is available at

By checking the signature of the packages, Linux package managers, and more importantly, we, can verify whether the package that comes from the MariaDB developers and hasn't been tampered with since they created it.

When configuring the MariaDB repository on Debian and Ubuntu, and during the initial MariaDB install on Fedora, Red Hat, and CentOS, an important task is to import the signing key. It's a good idea to verify the key by comparing it to the IDs and the fingerprint when doing so. Thankfully, this is a one-time operation. Once the key is imported the process is fully automatic. We'll only be notified if the signature check fails.


After the installation

After installing MariaDB, we can quickly test that MariaDB is up and running by opening a terminal or command-line window and running the following command (on Windows we can also open the mysql client .exe in the MariaDB folder):

mysql -u root -p

This command connects to MariaDB as the root user (-u root) and prompts for the password of that user (-p). When prompted, type in the password configured during the install. If no password was set during the install, remove -p. Until a password is set we can connect without a password.


Not having a password for the root user can be dangerous! If you did not set one during the installation, be sure to set one immediately after the install following the instructions in Chapter 3, MariaDB Security.

If MariaDB has been successfully installed and started, we should see something similar to the following screenshot when connecting using the previous command to launch the mysql command-line client:

If you get the MariaDB command-line prompt as illustrated in the preceding screenshot, congratulations! You've just installed MariaDB and can successfully connect to the server using the command-line client. You can quit the command-line client for now. Don't worry; we'll come back to it soon.


Troubleshooting installation issues

The MariaDB installers work very well. And they are tested and retested constantly. Occasionally issues with either installing MariaDB or running it for the first time are discovered, but they are almost always fixed promptly so that users are not affected.

If we do happen to run into an issue when trying to start MariaDB, what should we do?

The first thing we should do is look in the error log. The MariaDB error log is either stored with the system logfiles (for example, under /var/log/ on Linux) or in the MariaDB data directory. Common locations for the MariaDB data directory include /var/lib/mysql/ on Linux, C:\Program Files\MariaDB <version>\data\ on Windows (<version> is the version number of MariaDB we are using), and /usr/local/var/mysql/ on Mac OS X. The error logfile itself will either be called mysql.err or hostname.err where hostname is the name we've given our computer. It is also worth noting that the name and location of the logfile can be customized by the my.cnf or my.ini file. The next chapter on configuring MariaDB will go into this file and its location.

Each entry inside the error logfile consists of a timestamp and a description of what went wrong at that timestamp. Sometimes the information given is enough for us to figure it out ourselves, but sometimes we may need to ask for help. We shouldn't feel bad if we can't figure an error out, even experts are sometimes stumped! If we do need to ask for help, the resources listed on the following page, especially the Maria Discuss mailing list and the official IRC channel can help greatly:



In this chapter we installed MariaDB. Our next task is to configure it, which just so happens to be the subject, and title, of the next chapter.

About the Author

  • Daniel Bartholomew

    Daniel Bartholomew has been using Linux since 1997 and databases since 1998. In addition to this book, he has also written MariaDB Cookbook, Packt Publishing, and dozens of articles for various magazines, including The Linux Journal, Linux Pro, Ubuntu User, and Tux. He became involved with the MariaDB project shortly after it began in early 2009 and continues to be involved to this day. He currently works for MariaDB, Inc. and splits his time between managing MariaDB releases, documentation, and maintaining various bits and pieces that keep the MariaDB project running smoothly.

    Browse publications by this author
Book Title
Unlock this book and the full library for FREE
Start free trial