How to Install and Configure MySQL/MariaDB for WordPress

Leave your reply

Introduction

Learn how to install and configure MySQL/MariaDB for WordPress. WordPress is one of the world's most popular CMS and blogging software packages, and its famous "five minute install" makes it one of the easiest to use.

Most WordPress users will find that it works on their server without having to make any updates or changes to MySQL/MariaDB. However, in some cases MySQL/MariaDB may need to be updated or configured in order to run WordPress.

Requirements

  • A server running Ubuntu 14.04, CentOS 6, or CentOS 7
  • Root or sudo permissions

Note: For any Cloud Server with Plesk, applications like WordPress should always be installed and managed through the Plesk interface. See our article Use WordPress on a Cloud Server With Plesk for step-by-step instructions.

Checking Your Version of MySQL/MariaDB

To check your version of MySQL/MariaDB, log into the client with the command:

sudo mysql -u root -p

The version number will be displayed in the welcome message.

WordPress

The current version of WordPress recommends either:

  • MySQL version 5.6 or greater
  • MariaDB version 10.0 or greater

Updating MySQL on Ubuntu 14.04

Note: We strongly recommend you to back up your database(s) before you proceed to update MySQL. There are several significant differences between MySQL 5.5 and 5.6. Before upgrading MySQL, be sure to consult the list of changes to see what may be affected on your system.

On newer Ubuntu and Debian systems including Ubuntu 14.04, first remove the existing version of MySQL with the commands:

sudo apt-get purge mysql-server-core-5.5 mysql-server-5.5 mysql-server mysql-client-core-5.5 mysql-client-5.5 mysql-client  
sudo apt-get autoremove

Then install MySQL 5.6 with the commands:

sudo apt-get update
sudo -E apt-get install mysql-server-5.6 mysql-client-5.6

Updating MariaDB on CentOS 6

Note: We strongly recommend you to back up your database(s) before you proceed to update MariaDB.

On older CentOS and Red Hat systems including CentOS 6, upgrading to MariaDB 10 is a three-step process:

  1. Remove MySQL 5.1
  2. Install and upgrade MariaDB 5.5
  3. Upgrade MariaDB 5.5 to MariaDB 10.0

Attempting to upgrade directly to MariaDB 10.0 will fail.

Step 1: Configure the MariaDB Repository and Remove MySQL 5.1

Create a file with the command:

sudo nano /etc/yum.repos.d/MariaDB55.repo

Put the following into the file:

# MariaDB 5.5 repository for CentOS 6
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Save and exit the file, then update the repository cache with the command:

sudo yum clean all

Finally, remove MySQL with the command:

sudo yum remove mysql-server

Step 2: Install and Upgrade MariaDB 5.5

Install MariaDB 5.5 with the command:

sudo yum install MariaDB-server MariaDB-client

Once the installation has completed, start MariaDB with the command:

sudo service mysql start

Upgrade the installation of MariaDB 5.5 with the command:

sudo mysql_upgrade -u root -p

Enter the original root MySQL password and wait for the upgrade to finish.

Step 3: Remove MariaDB 5.5 and upgrade to MariaDB 10.0

Remove MariaDB 5.5 with the command:

sudo yum remove MariaDB-server MariaDB-client

Disable the MariaDB 5.5 repository with the command:

sudo mv /etc/yum.repos.d/MariaDB55.repo /etc/yum.repos.d/MariaDB55.repo.disabled

Create a MariaDB 10.0 repository with the command:

sudo nano /etc/yum.repos.d/MariaDB10.repo

Put the following into the file:

# MariaDB 10.0 repository for CentOS 6
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Save and exit the file, then update the repository cache with the command:

sudo yum clean all

Install MariaDB 10.0 with the command:

sudo yum install MariaDB-server MariaDB-client

After the installation is complete, start MariaDB with the command:

sudo service mysql start

Upgrade the installation with the command:

sudo mysql_upgrade -u root -p

Enter the root MariaDB password and wait for the upgrade to finish. Then start MariaDB with the command:

sudo service mysql start

Updating MariaDB on CentOS 7

Note: We strongly recommend you back up your database(s) before you proceed to update MariaDB.

On newer CentOS and Red Hat systems including CentOS 7, first update yum with the command:

sudo yum update

Next, add the MariaDB repository. Create a file with the command:

sudo nano /etc/yum.repos.d/MariaDB10.repo

Put the following into the file:

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

Save and exit the file.

Stop the running instance of MariaDB and delete it with the following three commands:

sudo systemctl stop mariadb
sudo yum remove mariadb-server mariadb mariadb-libs
sudo yum clean all

Install the new version with the command:

sudo yum install MariaDB-server MariaDB-client

Once this has completed, start MariaDB with the command:

sudo systemctl start mysql

Finally, enable MariaDB to start on boot with the command:

sudo /sbin/chkconfig mysql on