Have you ever been locked out of your house because you forgot your key? Getting locked out of your WordPress website can feel just as frustrating, especially if a hacker has deleted your admin account. But don’t worry, there’s a way to regain access.
Think of your website as a house with a hidden back door. This back door is your website’s database, which is typically accessed using MySQL commands. While it may sound complex, it’s essentially a set of instructions that allows you to make changes to your website behind the scenes.
In this article, we will guide you on how to use MySQL to create a new admin account for your website, similar to getting a new key for your house. This way, you can secure your site from hackers and regain control.
Why You Should Add an Admin User to Your WordPress Database Using MySQL
We encountered a situation where a user’s site was compromised, resulting in their admin account being deleted from the database. This left them unable to access their WordPress website.
We assisted them in regaining access to their website by creating a new admin user directly in the WordPress database. This was accomplished using phpMyAdmin, a web-based tool that enables you to manage MySQL databases through your web browser.
If you’ve been locked out of your WordPress admin area due to hacking or if you’ve forgotten your password, you can regain access through this method.
Always remember to back up your database before making any changes in MySQL. Once you’re able to log back into your website, you may want to refer to our beginner’s guide on how to fix a hacked WordPress site.
Now, let’s explore the steps to add an admin user to the WordPress database using MySQL.
How to Add an Admin User to the WordPress Database Using phpMyAdmin
Most leading WordPress hosting providers include phpMyAdmin by default. You can locate it in the Databases section of your hosting account’s cPanel dashboard.
Here’s a screenshot from the Bluehost control panel:
Clicking the icon will launch the phpMyAdmin interface. You will need to select your WordPress database from the left-hand column.
Once selected, phpMyAdmin will display all the tables in your WordPress database. You will be editing the wp_users and wp_usermeta tables.
How to Add a User to the wp_users Table
First, locate the wp_users table and click on it. This will display the users currently registered in the table.
In the screenshot below, you will see two user IDs in our demo website’s table: 1 and 2. When creating a new user for our demo site, it is essential that this ID is unique, so we will use the number 3.
To insert the information for a new admin user, click on the ‘Insert’ tab located at the top of the screen.
Please fill in the following details in the fields on the Insert form:
ID: choose a unique number (for our example, we will use 3)user_login: the username that will be used for logging inuser_pass: create a password and ensure to select MD5 from the function menu (refer to the screenshot below)user_nicename: the user’s full name or preferred nicknameuser_email: the user’s email addressuser_url: your website URLuser_registered: select the date and time when the user was registered using the calendaruser_activation_key: leave this field blankuser_status: set this value to 0display_name: the user’s full name or display name
After completing the form, remember to click the ‘Go’ button to save the new user.
Adding a User to the wp_usermeta Table
First, locate the wp_usermeta table and select it. Then, click on the ‘Insert’ tab as you did previously.
Next, fill in the following details in the Insert form:
unmeta_id: leave this field empty (it will be generated automatically)user_id: enter the user ID from the previous stepmeta_key: this should bewp_capabilitiesmeta_value: insert the following:a:1:{s:13:"administrator";s:1:"1";}
After that, scroll down to find fields for a second entry. You need to provide the following information:
unmeta_id: leave this field empty (it will be generated automatically)user_id: enter the user ID from the previous stepsmeta_key: you should enterwp_user_levelmeta_value: 10
Once you have completed filling in the fields, click the ‘Go’ button. Congratulations, you have successfully created a new admin user!
You should now be able to log in to your WordPress admin area using the username and password you set for this user.
After logging in, navigate to Users » All Users, then select the username you just created.
Now, without making any changes, scroll to the bottom of the page and click the ‘Save’ button.
This action will allow WordPress to finalize the user you just created and add any necessary additional information.
How to Add an Admin User to the WordPress Database Using a SQL Query
If you’re a developer, you can expedite the process with a code snippet.
Simply execute this SQL query in 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');
Be sure to replace ‘databasename’ with the name of the database you are using.
Remember to update the other fields for the new user as detailed in the first method.
Comprehensive Guides for Regaining Access to WordPress Admin
Now that you’ve learned how to add an admin user using MySQL, you might find our articles on resolving issues when locked out of the WordPress admin area helpful.
- Steps to Take When Locked Out of WordPress Admin (wp-admin)
- Guide to Utilizing WordPress Recovery Mode
- Instructions for Resetting a WordPress Password via phpMyAdmin
- How to Disable Limit Login Attempts in WordPress
- Steps to Deactivate All Plugins When Unable to Access WP-Admin
- How to Resolve the WordPress White Screen of Death (Step-by-Step)
- How to Address the Critical Error in WordPress (Step-by-Step)
- How to Fix the WordPress Login Page Refreshing and Redirecting Issue
- How to Resolve the Error Establishing a Database Connection in WordPress
- Simple Solutions for the ‘This Site Can’t Be Reached’ Error in WordPress
We hope this guide has helped you learn how to add an admin user to the WordPress database using MySQL. You may also want to explore our comprehensive WordPress security guide or our compilation of common WordPress errors and their solutions.
If you enjoyed this article, consider subscribing to our YouTube Channel for WordPress video tutorials. You can also connect with us on Twitter and Facebook.



