Getting Started with MariaDB - Second Edition

4.3 (4 reviews total)
By Daniel Bartholomew
    What do you get with a Packt Subscription?

  • Instant access to this title and 7,500+ eBooks & Videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Free Chapter
    Installing MariaDB
About this book

MariaDB is a database that has become very popular in the few short years that it has been around. It does not require a big server or expensive support contract. It is also powerful enough to be the database of choice for some of the biggest and most popular websites in the world, taking full advantage of the latest computing hardware available.

From installing and configuring through basic usage and maintenance, each chapter in this revised and expanded guide leads on sequentially and logically from the one before it, introducing topics in their natural order so you learn what you need, when you need it. The book is based on the latest release of MariaDB and covers all the latest features and functions. By the end of this beginner-friendly book, not only will you have a running installation of MariaDB, but you will have practical, hands-on experience in the basics of how to install, configure, administer, use, and maintain it.

Publication date:
June 2015
Publisher
Packt
Pages
140
ISBN
9781785284120

 

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 easier.

In addition to the source code, there are several other package types, such as:

  • Windows MSI packages

  • Linux YUM packages

  • Linux APT packages

  • Linux and Windows binaries

The Windows MSI packages are for computers and servers running from Windows XP to Windows 8. The Linux .rpm packages are used with distributions such as Fedora, CentOS, and Red Hat that use the Yellow Dog Updater modified (YUM) package manager. Linux .deb packages are used with 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, the Linux and Windows binaries, only briefly. These packages are mainly useful to experienced users of MariaDB who have non-standard custom setups on their database servers. The Windows binaries come in a ZIP file (.zip) and the Linux binaries in a gzipped tar file (.tar.gz), sometimes called a binary tarball.

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

We will also cover how to install MariaDB on Mac OS X. Packages for this operating system supplied by a third party, not by the MariaDB developers.

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

The rest of this chapter contains 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.

So in short, the topics of the remaining sections in this chapter are as follows:

  • Choosing a MariaDB series

  • Installing MariaDB on Windows

  • Installing MariaDB on Mac OS X

  • Installing MariaDB on Debian, Ubuntu, and Linux Mint

  • Installing MariaDB on Fedora, Red Hat, and CentOS

  • Installing MariaDB on other Linux distributions

  • MariaDB package security

  • After the installation

  • Troubleshooting installation issues

Feel free to jump around and only read the sections that directly pertain to you and your chosen operating system.

 

Choosing a MariaDB series


The development of MariaDB 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 GNU/Linux practice of having stable, testing, and unstable versions.

The development series

The development series of MariaDB is where the major new features and capabilities are introduced. Think of this like minor league baseball where the upcoming future stars are introduced and are improved 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 a lot 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 of Beta releases where the code is refined and polished, followed by one or two Release Candidate releases where the 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.

Tip

If the current development series release of MariaDB is a Release Candidate, 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 the series will be well supported with bug and security fixes for a period of at least 5 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 becomes stable.

The maintenance series

When a series moves from development to stable, the series that was the current stable one is moved to become a maintenance series. This means that it will still receive bug fixes for the rest of its 5-year maintenance period 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, which 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.

Tip

Most Linux distributions include MariaDB in their package repositories, either as the default MySQL-compatible database, or as an alternative choice. The version of MariaDB that they include is up to them, and while it is sometimes the most recent stable version of MariaDB, it is often one of the more recent major versions in the maintenance series.

We'll now go through the installation of MariaDB for each of the major operating systems. First Windows, then Mac OS X, then Debian GNU/Linux and Ubuntu Linux, followed by 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 those who know that they want it.

If we are starting out with MariaDB for Windows, it is recommended to use the MSI packages. The following are the steps to do just that:

  1. Download the MSI package from https://downloads.mariadb.org/ location. First click on the series that we want (whatever is the current stable version, most likely), then locate the Windows 64-bit or Windows 32-bit MSI package. For most Windows PCs, the 64-bit MSI package is probably the one that we want, especially if we have more than 4 GB of RAM. If you're unsure, the 32-bit package will work on both 32-bit and 64-bit Windows computers.

  2. Once the download has finished, launch the MSI installer by double-clicking on it. Depending on the local Windows settings, you may be promoted to launch the installer 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 MariaDB root user password when prompted. This is done by checking the Modify password for database user 'root' checkbox and then filling in our chosen password two times in the provided textboxes.

  4. Unless you need to, don't check the Enable access from remote machines for 'root' user or the Create An Anonymous Account checkboxes. We'll cover creating regular user accounts in Chapter 4, Administering MariaDB.

  5. The Use UTF8 as the default server's character set checkbox is unchecked by default, but it's a good idea to check it, as shown in the following screenshot:

  6. The Install as service box is checked by default, and it is recommended to keep it that way so that MariaDB starts up when the computer is booted.

  7. The Service Name textbox has the default value MySQL for compatibility reasons, but we can rename it if we like. This name is what Windows uses to identify the running service, and it does not affect MariaDB so, it is okay to rename or keep it as the default name.

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

  9. The Optimize for transactions checkbox is also checked by default. This is the recommended setting, as shown here:

  10. One easy way to help the MariaDB developers is to check the Enable the Feedback plugin checkbox, as shown in the following screenshot. When enabled, the feedback plugin submits anonymous usage information to the MariaDB Foundation. This information includes things such as what plugins are enabled, how much memory MariaDB uses, and the operating system that we are using. MariaDB developers use this information to guide MariaDB development.

  11. There are other settings that we can make through the installer. All of them can be changed later by editing the my.ini file. We will be covering this in Chapter 2, Configuring MariaDB, so we don't need to worry about them right away.

  12. If our version of Windows has user account control enabled, a pop-up window will appear during the installation asking if we want to allow the installer to install MariaDB. For obvious reasons, we will need to click on Yes.

  13. Once the installation is complete, there will be a MariaDB folder added to the start or the programs menu. There will be various links under this, including one to the mysql command-line client application. We will be using this application in Chapters 5-7.

    Tip

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

  14. Eventually, we will be presented with a dialog box containing an installation complete message and a Finish button. At this point, MariaDB is installed and running on our Windows-based computer. Congratulations! Click on Finish to quit the installer.

To install MariaDB on Mac OS X or Linux, read on; otherwise, feel free to skip those sections.

 

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 from the Mac App Store.

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

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

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

brew doctor

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

brew update
brew install mariadb

Tip

There is no option to choose a specific MariaDB series; whatever is the current version in brew is the one that will be installed. Also, brew will not prompt you to set a database user password during installation, this is dangerous, so be sure to set one immediately afterwards, following the instructions in Chapter 3, Securing MariaDB.

MariaDB will not automatically be started after installation. To do so, we run the following commands:

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 to install MariaDB on Debian GNU/Linux, Ubuntu, and Linux Mint is easy and starts with a visit to the repository configuration tool from:

https://downloads.mariadb.org/mariadb/repositories

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, Suse, openSUSE, and others.

Tip

Many Linux distributions offer MariaDB in their repositories either as the default MySQL-compatible database or as an alternative choice. The instructions here will install MariaDB directly from the MariaDB repositories instead of from your Linux distribution's repositories.

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

cat /etc/lsb-release

The output will be similar to the following:

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=14.04

DISTRIB_CODENAME=trusty

DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

This example output shows that the computer is running Ubuntu 14.04.1 LTS "Trusty". So, using the repository configuration tool, we will click on Ubuntu, then 14.04 LTS "trusty", and then on the MariaDB series we want to install. Lastly, we will click on the mirror we want to use. The tool will then output three pieces of text. The first contains the commands to add the MariaDB repository to our system. The second contains the commands to actually install MariaDB. The third block of text contains alternative instructions in case adding the repository using the first set did not work.

For example, the generated commands for adding a repository for MariaDB 10.1 for Ubuntu 14.04 LTS "trusty" and using the osuosl mirror are as follows:

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys \
--keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository \
'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main'

The first command installs the software-properties-common package if it is not already installed. This package contains the add-apt-repository command we use to install the repository. The second command imports the GPG encryption key that is used to sign MariaDB packages. For more information about this key, see the MariaDB package security section later in this chapter. The third command adds the repository.

Now that the repository is configured, we can install MariaDB using the following installation commands:

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.

To learn about installing MariaDB on Fedora, Red Hat, and CentOS, read on. Otherwise, jump ahead to the MariaDB package security section if you're interested in the MariaDB GPG 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 to install 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 will visit the MariaDB repository configuration tool from:

https://downloads.mariadb.org/mariadb/repositories/

Tip

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, Suse, openSUSE, and others.

To generate the text, we simply click on the distribution we are using, the distribution release we are using, and the version of MariaDB we want to install. After doing so, the contents of the appropriate repo file will be displayed.

For example, the text generated for MariaDB 10.1 on the 64-bit version of CentOS 7 is as follows:

# MariaDB 10.1 CentOS repository list
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

The gpgkey line tells YUM where the GPG signing key is located. The gpgcheck=1 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 have to download and install it. Since 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 GPG signing key.

We copy and paste the generated text into a file using our favorite text editor. Naming the file descriptively, such as MariaDB.repo, is recommended. Once the file is created, we then move it to the /etc/yum.repos.d/ folder using a command similar to the following one:

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

Once the file is in place, we are ready to install MariaDB. This is as simple as the following:

sudo yum install MariaDB-server MariaDB-client

The capitalization of the package names is important because if we type mariadb-server instead of MariaDB-server, we will either get a package cannot be found error or, if we are using a distribution that includes MariaDB, we will get the distribution version of MariaDB instead of the version from the MariaDB project.

YUM will gather in all of the dependencies for MariaDB and present us with a list of everything that needs to be installed to install MariaDB. The following screenshot shows this:

After answering y, the installation will get going and we will be prompted to accept the GPG signing key. We will 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:

[dbart@centos70-x86-64 ~]$ sudo /etc/init.d/mysql start

Starting MySQL.. SUCCESS! 

MariaDB is now installed and running.

Jump ahead to the MariaDB package security section if you're interested in the MariaDB GPG signing key, 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 available on more Linux distributions than just the ones listed previously in this chapter, 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 from:

https://mariadb.com/kb/en/mariadb/installing-mariadb-binary-tarballs/

Before installing these generic packages, however, it is worth your while to look in your distribution's package manager to see if MariaDB is already there.

 

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 longtime 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 vulnerability discovered a couple years ago; 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 Knowledge Base, which is the official location of the MariaDB documentation and is available from:

https://mariadb.com/kb/en/mariadb/gpg/

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 will only be notified if the signature check fails.

For MariaDB Windows, binary Linux, and the MariaDB source code files, we can verify them in two ways, first is by comparing the md5sum of the file we downloaded with the md5sum posted on the MariaDB downloads page next to the file. The second way is to use PGP or GPG to verify the cryptographic signature of the file. These signatures are also posted on the MariaDB downloads page.

 

After the installation


After installing MariaDB, we can quickly verify 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.exe client 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, we will type in the password we configured during installation. If no password was set during installation, we simply remove the -p from the command. Until a password is set, we can connect without a password.

Tip

Not having a password for the root user is 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, Securing MariaDB.

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 log files (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 log file itself will either be called mysql.err or hostname.err where "hostname" is the name that we've given our computer. It is also worth noting that the name and location of the log file can be customized by either the my.cnf file or the my.ini file. Chapter 2, Configuring MariaDB, will delve further into this file and its location.

Each entry inside the error log file 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 at other times, we may need to ask for help. We shouldn't feel bad if we can't figure out an error; even experts are sometimes stumped! If we do need to ask for help, the resources listed on the following link, especially the Maria discuss mailing list and the official IRC channel can help greatly:

https://mariadb.com/kb/en/mariadb/where-are-other-users-and-developers-of-mariadb/

 

Summary


In this chapter, we installed MariaDB on various operating systems. Our next task is to configure it, which also happens to be the subject and the 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
Latest Reviews (4 reviews total)
... ...
The book seems to match what I was looking for
A well written, introductory text to a great Open Source product.
Getting Started with MariaDB - Second Edition
Unlock this book and the full library FREE for 7 days
Start now