Installing WordPress Step 2: Setting up MySQL for WordPress using Command Line MySQL Client on Linux (CentOS 6)

This post is part of a step-by-step series on installing WordPress on Linux (CentOS 6)

There are several ways to access your MySQL database, but in this tutorial we will be using command line. Before we begin we assume the following:

Requirements

  1. MySQL has been installed and secured
  2. WordPress Directory has been Installed
    1. Using yum
    2. Without yum

Starting Up the Command Line Interface

You will need the password you made for root (or whichever user you made), when you installed and secured MySQL

[ahmed@amayem ~]$ mysql -u  root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.6.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

If you hit a MySQL ERROR 2002 (HY000) then check here to see how I solved it

Creating the Database

mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.36 sec)

I named the database testdb but you should name it something appropriate to your setup.

Granting Priveleges of the Database

mysql> GRANT ALL PRIVILEGES ON testdb.* TO "wptestuser"@"localhost" 
-> IDENTIFIED BY "testpassword";
Query OK, 0 rows affected (2.35 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.15 sec)

Change testdb, wptestuser and testpassword to something appropriate to your setup. Note that wptestuser is just a name I made at the moment, and isn’t actually a linux user.

Exiting

mysql> EXIT;
Bye

Done.

Next Steps

  1. Updating wp-config.php with Database Settings and Security Keys
  2. Deciding the Site Root Directory and Moving Files there
  3. Running the WordPress php Install Script

References

  1. Official WordPress Documentation on Using the MySQL client

Ahmed Amayem has written 90 articles

A Web Application Developer Entrepreneur.