Creating New MySQL User and Database for WordPress

pc 1776995 640

Every WordPress installation has a database in the backend. That’s one of WordPress’ requirements.

Now, there are many different database servers you can use with WordPress. From MySQL to MariaDB to Percona and MongoDB, all of these different database servers should work just fine with WordPress.

Because you can’t use all of them at the same time, you must select one to use with WordPress. For this post, we’re going to be using MySQL databases to connect WordPress.

This brief tutorial is going to show you how to create WordPress MySQL database and user, and how to grant the user rights to manage the WordPress database.

To get started with managing WordPress’ MySQL databases, follow the steps below:

Step 1: Install MySQL

If you haven’t installed MySQL yet, the commands below show you how to install it on Ubuntu.

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

During the installation, you’ll be prompted to create and confirm a new root password for MySQL. Please type and confirm a password to continue.

This is the same password you’ll use to sign onto MySQL server.

Step 2: Sign on and Create a WordPress Database and User

After the database server has been installed, run the commands below to sign onto the database.

sudo mysql- u root -p

You’ll be prompted for a password. type the password you created earlier during the installation.

After signing on to MySQL database server, run the commands below to create a new WordPress database called wpdb.


This will create a new WordPress database called wpdb.

After creating the WordPress database, you’ll also need to create a database user. This account will be used by WordPress to interact with the database. To create the database user named wpuser, run the commands below.

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'type_user_password_here';

The above commands create a new database user called wpuser.

Now you should have both the database and user created. The user does have not any rights to the database. In order for the database user to interact on behalf of WordPress, including making changes to the data in the database, the user will need the rights to do these things.

To give the user full rights to mange the database, run the commands below

GRANT ALL ON wpdb.* TO 'wpuser'@'localhost';

The commands above grant wpuser all rights to manage all the tables in the wpdb database.

To grant the user right to a single table, run the commands below

GRANT <permission> ON wpdb.<table> TO 'wpuser'@'localhost';

Replace <permission> with one of these permission levels.

  • SELECT – gives the user permission to use the select command to fetch data from tables
  • INSERT – gives the user permission to add new rows into tables
  • UPDATE – gives the user permission to modify the existing rows in tables
  • DELETE – gives the user permission to delete existing rows from tables
  • CREATE – gives the user permission to create new tables or databases
  • DROP – gives the user permission to remove existing tables or databases
  • ALL PRIVILEGES – gives the user permission to have unrestricted access on a database or the whole system(by using an asterisk in the database position)

This is how WordPress databases and users are created on MySQL.


This post shows students and new users how to create databases, users and grant users access to databases. After creating the database and the user, you can then configure WordPress to use it.

You may also like the post below:


  1. Missing Single Quote on granting permissions. The line should be as follows.
    Grant all on kingwoodpsychology_wp.* To ‘fpckadmin’@’localhost’;

  2. Thanks a lot for such an informative post!

    I am following these instructions and this video at the same time. Both make a database, but the steps to follow are a little different. Why is this happening? Am I doing something wrong?

    Thanks for the help!

  3. Hi,
    I am new to the LAMP enviroment.
    I hope people can still answer my question regarding this article. How does wordpress know it has to use wp_user to connect to the database?
    Is that a requited user for every installation. If so, what about the password, where does wordpress know about the password for wp_user?
    This is confusing. I read and re-read the steps, I can’t see the connection and therefore I am still getting “database not found error”
    Thanks much in advance.

  4. The database connection information is saved in the wp-config.php file inside the root directory of the WordPress site. It’s exposed there as plain text if you open it in a text editor.

    I’m having related issues (which is why a search brought me here) but I’m running MySQL 8.0.19 on my server locally with PHP 7.3, Apache 2.4 and and WordPress. Despite following these steps to the letter, I’m getting a fatal error in setting up the database connection.

  5. Just discovered my error. Note: My error.

    I had to change the listening port on MySQL when I set it up due to a different app with an older version. In the config of WordPress I had to use localhost:port to idenfity it and it took off running afterwards

  6. I know this is old but it would be nice if you edited it and added a comment that this will not work in most systems with the newer mysql / wordpress and either edit the content to work in the newer systems or provide a link to a site that does.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.