How to Add an Admin User to the WordPress Database via MySQL (2024)

Have you been locked out of your WordPress website?

Sometimes, hackers will lock you out of your own website by deleting your admin account from the database.

In this article, we will show you how to add an admin user to the WordPress database via MySQL so you can get your access back.

How to Add an Admin User to the WordPress Database via MySQL (1)

Why Add an Admin User to the WordPress Database via MySQL?

We once ran into an issue where a user’s site was hacked, and their admin account was deleted from the database. This locked them out of their WordPress website.

We were able to help them get access to their website by creating a new admin user directly to the WordPress website. We did that using phpMyAdmin, a web-based tool that allows you to manage MySQL databases using your web browser.

If you find yourself locked out of your WordPress admin area due to hackers or simply because you forgot your password, then you can do the same.

However, you should always make a backup of your database before performing any MySQL edits. Then, once you can log back into your website, you may need to follow our beginner’s guide to fixing your hacked WordPress site.

With that being said, let’s take a look at how to add an admin user to the WordPress database via MySQL.

Adding an Admin User to the WordPress Database With phpMyAdmin

phpMyAdmin comes pre-installed with most top WordPress hosting companies. You can find it in the Databases section of your hosting account’s cPanel dashboard.

Here is a screenshot fromtheBluehost control panel:

How to Add an Admin User to the WordPress Database via MySQL (2)

Clicking on the icon will open the phpMyAdmin interface. You need to select your WordPress database from the left column.

After that, phpMyAdmin will display all tables in your WordPress database. You will be making changes to the wp_users and wp_usermeta tables.

How to Add an Admin User to the WordPress Database via MySQL (3)

Adding a User to the wp_users Table

First, you need to find the wp_users table and click it. This will show the users currently listed in the table.

Notice in the screenshot below that there are two user IDs in our demo website’s table, 1and2. When we create a new user for our demo site, this ID needs to be unique, so we’ll type the number 3.

You need to click the ‘Insert’ tab at the top of the screen so you can insert the information for a new admin user.

How to Add an Admin User to the WordPress Database via MySQL (4)

Add the following information to the fields on the Insert form:

  • ID: pick a unique number (in our example, we’ll use 3)
  • user_login: the username that will be used when logging in
  • user_pass: add a password, and make sure to select MD5 in the function menu (see the screenshot below)
  • user_nicename: the user’s full name or nickname
  • user_email: the user’s email address
  • user_url: your website address
  • user_registered: select the date and time the user was registered using the calendar
  • user_activation_key: leave blank
  • user_status: set this to 0
  • display_name: the user’s full name or display name
How to Add an Admin User to the WordPress Database via MySQL (5)

Once you have finished, make sure you click on the ‘Go’ button to store the new user.

Adding a User to the wp_usermeta Table

Now, you need to find the wp_usermeta table and click it. After that, you should click on the ‘Insert’ tab as you did in the previous step.

Next, you need to add the following information to the Insert form:

  • unmeta_id: leave this blank (it will be auto-generated)
  • user_id: the user ID you used in the previous step
  • meta_key: this should be wp_capabilities
  • meta_value: insert this: a:1:{s:13:"administrator";s:1:"1";}
How to Add an Admin User to the WordPress Database via MySQL (6)

After that, when you scroll down, you should find fields for a second row. You need to add the following information:

  • unmeta_id: leave this blank (it will be auto-generated)
  • user_id: the user ID you used in the previous steps
  • meta_key: you need to enter wp_user_level
  • meta_value: 10
How to Add an Admin User to the WordPress Database via MySQL (7)

When you have finished entering the information into the fields, you need to click the ‘Go’ button. Congratulations, you have created a new admin username!

Now, you should be able to log in to your WordPress admin area using the username and password you specified for this user.

As soon as you log in, you need to navigate to Users » All Users, then click on the username you just created.

How to Add an Admin User to the WordPress Database via MySQL (8)

Now, without changing anything, scroll to the bottom of the page and click the ‘Save’ button.

This will allow WordPress to clean up the user you just created and add some extra information that is needed.

Adding an Admin User to the WordPress Database Using a SQL Query

If you are a developer, then you can speed up the process using code.

Simply drop this SQL query into your database:

INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('3', 'demo', MD5('demo'), 'Your Name', 'test@example.com', 'http://www.example.com/', '2022-09-01 00:00:00', '', '0', 'Your Name'); INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '3', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'); INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '3', 'wp_user_level', '10');

Hosted with ❤️ by WPCode

Make sure you change ‘databasename’ to the database you are working with.

Also, don’t forget to change the other values to those you want for the new user, as we explained in the first method.

How to Add an Admin User to the WordPress Database via MySQL (9)

Expert Guides on What to Do When Locked Out of WordPress Admin

Now that you know how to add an admin user via MySQL, you may like to see some articles on how to fix your website when locked out of the WordPress admin area.

  • What to Do When You Are Locked Out of WordPress Admin (wp-admin)
  • How to Use WordPress Recovery Mode
  • How to Reset a WordPress Password from phpMyAdmin
  • How to Unblock Limit Login Attempts in WordPress
  • How to Deactivate All Plugins When Not Able to Access WP-Admin
  • How to Fix the WordPress White Screen of Death (Step by Step)
  • How to Fix The Critical Error in WordPress (Step by Step)
  • How to Fix WordPress Login Page Refreshing and Redirecting Issue
  • How to Fix the Error Establishing a Database Connection in WordPress
  • How to Easily Fix This Site Can’t Be Reached Error in WordPress

We hope this tutorial helped you learn how to add an admin user to the WordPress database via MySQL. You may also want to see our ultimate WordPress security guide or our list of common WordPress errors and how to fix them.

If you liked this article, then please subscribe to ourYouTube Channelfor WordPress video tutorials. You can also find us onTwitterand Facebook.

How to Add an Admin User to the WordPress Database via MySQL (2024)
Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6227

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.