How to Create An Admin User in WordPress Using MySQL

Create an admin user in WordPress using MySQL – In my other WordPress how-to article, I’ve shown you how to create an admin user via FTP with a simple functions file code snippet. This method is particularly useful when you forgot WordPress password and cannot recover it in traditional methods.

Besides from using FTP, you can also create an admin user in WordPress using MySQL pretty easily. Just like the FTP method, this approach is helpful when you are facing WordPress login problems. In case you are wondering, here is how to do it.

Things You Need to Know Beforehand

You need to have access to your hosting control panel and your MySQL database. Typically most hosting providers use cPanel as the hosting control panel and phpMyAdmin to manage WordPress database. So, I’m using the same to create an admin user in WordPress via MySQL.

Even if your control panel is different or using some other software to manage MySQL, the process should be pretty similar.

Note: Before proceeding any further, make sure that you backup WordPress database. This helps you to restore the database if anything happens in the process.

Create An Admin User in WordPress Using MySQL

1. To create an admin user in WordPress using MySQL, login to your hosting control panel, find and click on the phpMyAdmin option to open phpMyAdmin. Typically, you can find the phpMyAdmin link in the Databases section in the cPanel.

Using phpMyAdmin we are going to edit wp_users and wp_usermeta tables to create an admin user in WordPress using MySQL.

Create an Admin User in WordPress using MySQL - Select phpMyAdmin
Create an Admin User in WordPress using MySQL – Select phpMyAdmin

2. In the phpMyAdmin window, select your database appearing on the sidebar.

Create an Admin User in WordPress using MySQL - Select Your Database
Select Your Database

3. The above action will open the database. click on the link wp_users appearing on the sidebar.

Create an Admin User in WordPress using MySQL - Select wp_users Table
Select wp_users Table

4. Once the table has been opened, click on the option “Insert” appearing on the upper navigation bar.

Create an Admin User in WordPress using MySQL - Click Insert in wp_users Table
Create an Admin User in WordPress using MySQL – Click Insert in wp_users Table

5. Now, enter the fields as described below:

  • ID — In this field, enter a number of your choice. In my case, I’ve entered “5”. Remember this number, we are going to enter it a couple more times in other areas.
  • user_login — Enter a username of your choice. I’ve chosen “user5” as my username.
  • user_pass — Select “MD5” from the drop-down menu and then enter a strong password in the next field.
  • user_nicename — Enter your nickname in this field.
  • user_email — Enter the email address you’d like to associate this account with.
  • user_url — You can enter a web address of your choice in this field.
  • user_registered — Enter the date and time when the user is registered.
  • user_activation_key — Leave this field blank for now.
  • user_status — In this field, enter “0”.
  • display_name — Enter your name in this field. This will be displayed on your WordPress site.

6. Once you are done filling up the details as described, click on the button “Go“.

Create an Admin User in WordPress using MySQL - Fill wp_users fields
Create an Admin User in WordPress using MySQL – Fill wp_users fields

After editing the wp_users table, we can proceed to edit wp_usermeta table. Just like before, all we have to do is add a few values to complete the process of creating an admin user using MySQL.

7. To do that, click on the link “wp_usermeta” link appearing on the sidebar.

Create an Admin User in WordPress using MySQL - Select wp_usermeta Table
Select wp_usermeta Table

8. After opening the wp_usermeta table, click on the option “Insert” appearing on the upper navigation bar.

Create an Admin User in WordPress using MySQL - Select wp_usermeta Table Insert Option
Select wp_usermeta Table’s Insert Option

9. Now fill in the fields as described below:

  • unmeta_id — Leave this field empty.
  • user_id — Enter the ID you’ve entered earlier. In my case, I’ve entered “5” earlier.
  • meta_key — Enter meta key as wp_capabilities.
  • meta_value — Insert a:1:{s:13:"administrator";s:1:"1";} as the meta value.

On the other row, fill the blanks like below:

  • unmeta_id — Again, leave this field empty.
  • user_id — Enter earlier user ID. In my case, that will be “5”.
  • meta_key —  Insert wp_user_level in this field.
  • meta_value — Enter “10” in the field.

Once you are done filling up the details, this is how it looks like. Click on the button “Go” to save the changes.

Create an Admin User in WordPress using MySQL - Fill wp_usermeta Fields
Create an Admin User in WordPress using MySQL – Fill wp_usermeta Fields

10. That’s all there is to do. You’ve successfully created an admin user in WordPress using MySQL. In fact, you can log in with this username and password you used in this procedure.

Once logged in, you can reset the password of the other account, modify, or remove the user account by navigating to “User > All Users” in the WordPress dashboard.

Create an Admin User in WordPress using MySQL - Admin User Account Created using MySQL
Admin User Account Created using MySQL

If you like this simple guide, you might also like how to change database prefix and how to change WordPress database name. Do check them out for improved WordPress security.

Hope that helps and do comment below sharing your thoughts and experiences about using the above method to create an admin user using MySQL.

Leave a Reply

Your email address will not be published. Required fields are marked *

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