WordPress blogging platform is a PHP based web application and uses a MySQL database as a backend database. In this article we will explain in easy to follow step by step format how to manually create a MySQL database for your WordPress blog or website. Two options are explained below, either by connecting to MySQL using a web based graphical user interface such as phpMyAdmin, or by using the MySQL command line.

Once you have created the new WordPress MySQL database and have a user and password to access it, make sure you read the last section of this article “Recommended WordPress Database user privileges“ to make sure the most secure privileges are assigned to such user.

Creating a MySQL database using phpMyAdmin

There are several ways which you can use to connect to a MySQL database server to create a database, one of them is by using a web based graphical user interface such as phpMyAdmin.

  1. Once logged in to the phpMyAdmin interface, click on the Database Tab, specify a database name in the Create new database input file and click on Create button.

Create new MySQL database using PHPMyAdmin

WP White Security.com Security Tip: Avoid using predictable database names, such as blogdatabase or blogdb. In case a malicious user is trying to guess such a name, it makes it a little bit more difficult to guess.

  1. Create a new username and password to be used by WordPress PHP scripts to access the newly created MySQL database. To do so navigate to the Privileges tab and click on Add a new user.

PHPMyAdmin Add a new user web interface

  1. In the Add new user page shown above, enter a username, host and password, and ignore all other entries. If WordPress is going to be installed on the same server where MySQL is (typical scenario) the host should be set to Localhost. This means that this user is always going to connect from the same computer and requests using such credentials from a remote server will be denied.

WP White Security.com Security Tip: Avoid using predictable usernames, such as bloguser or blogusr. Also, a strong password should consist of at least 8 characters and should include alphabetical letters, numeric characters and as well special characters. Ideally the password should not be a dictionary word. An example of a good password is: !Pi4aX_7z?

  1. Once the new user is created, from the same Privileges tab click on Edit Privileges for the newly created user.
  2. In the Edit Privileges page, scroll down to the Database-specific privileges section so you can assign the user privileges only to the new WordPress MySQL database. Select the database from the drop down menu as shown in the screen shot below.

MySQL Database specific privileges in PHPMyAdmin

  1. Once the database is selected, you are redirected to a page from where you can specify the database specific privileges, as shown below.

MySQL Database privileges for WordPress database

  1. As shown in the above screenshot, for installing WordPress it is safe to assign all privileges apart from the Administration privileges to a user.

Creating MySQL database for WordPress via Command Line

  1. Connect to the MySQL engine using the command mysql –u root –p. Once you specify the password you will be connected to the MySQL database and prompted with mysql> prompt.
  2. To create a database use the CREATE DATABASE command. E.g. if you would like to create the database T3stdb123 enter the following:
CREATE DATABASE T3stdb123;
  1. Once the database is created, use the command GRANT ALL PRIVILEGES to create a new user with ALL privileges. If the database name is t3stdb123, the new user is newdbuser  and the user’s passwords is !Pi4aX_7z? then the command should be;
GRANT ALL PRIVILEGES ON t3stdb123.* TO "newdbuser"@"localhost" IDENTIFIED BY "!Pi4aX_7z?";


  1. Once the new user has been created and privileges has been assigned to it, run the command FLUSH PRIVILEGES; to flush the old privileges and start using the new assigned ones.

Recommended WordPress Database Permissions

For typical WordPress operation, the MySQL database user only needs SELECT, INSERT and UPDATE data privileges. It is recommended to use the minimum possible privileges when running WordPress. Any other privileges, such as ALTER, CREATE and DROP are sometimes needed during an upgrade or when installing some plugins which need access to change the database structure.  In such case you will be advised to do such changes by the plugin developer.Whenever you assign structure related privileges do it ONLY for temporary period. You can read more about WordPress database privileges from the article Why minimum MySQL user WordPress database privileges help.

Comments

  1. i read ur blog “Creating a MySQL Database for WordPress”,it is very useful for those who want to create mysql database for wordpress.

    can u post anymore post related to this

  2. Marina Sebanszi says:

    As beginner it was a very useful article. Looking forward to more such article from you.

  3. Supriya Gusain says:

    Thanks for the Article….it has helped me alot…..:)

  4. Kayod Igbasanmi says:

    Good day, thanks for your step by step guide, really help but i wish to know how i can create login and student portal using phpadmin and mqsql on wordpress website. really appreaciate anyone assistance on this. thanks all.

    • Hi Kayod,

      Thank you for your comment. What you are asking though is a different subject and requires several steps etc. If you would like to know more about it, and need assistance or WordPress consultancy, drop me an email on robert@wpwhitesecurity.com and we will gladly assist you.

      Have a great day!

      • Kayod Igbasanmi says:

        Okay, i will send you an email right now, kindly check your email Mr Robert please. glad to hear from you in earnest. Kayode

Speak Your Mind

*

Get Notified Instantly of Changes on Your WordPress

The WSAL Notifications Extension plugin enables WordPress administrators to setup monitoring rules so they are notified instantly via email when important changes happen on their WordPress.

Learn More