Home Blog WordPress Management Creating a MySQL Database for WordPress

Creating a MySQL Database for WordPress

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 and potentially break the security of your WordPress.

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

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.

11 thoughts on “Creating a MySQL Database for WordPress

  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. As beginner it was a very useful article. Looking forward to more such article from you.

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

    1. 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@melapress.com and we will gladly assist you.

      Have a great day!

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

  4. Hello!
    Please help!

    I tried to reanimate site form old hosting (it already ended). Site is written on wordpress
    I created new DB and new user. But there’s prefix different from initial. I changed it in wp-config and all files seem to be copied correctly.
    Nut there works only the first page. And when I try to open the other i see: [an error occurred while processing this directive]

    It seems to be some error with using new DB
    But I can’t understand where to look for it
    Thanks for any help

  5. Hello.
    I’ve just read the article about setting up a mysql database in WordPress.
    I’m creating a multi-seller marketplace with WordPress, and i would like to have any detail furthermore or an assistance to set up a mysql database in it.

    1. Hello Josue, it really depends on what plugin you are using for the marketplace. However, in most cases the plugin you are using automatically creates the tables in the WordPress database, so you do not have to worry about manually creating them.

Comments are closed.

Stay in the loop

Subscribe to the Melapress newsletter and receive curated WordPress management and security tips and content.

Newsletter icon
Please enable JavaScript in your browser to complete this form.

It’s free and you can unsubscribe whenever you want. Check our blog for a taste.

Envelope icon