How to Add an Admin User to the WordPress Database via MySQL

How to Add an Admin User to the WordPress Database via MySQL

Last Updated on September 12, 2022 by Oluwatuyi

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’ll show you how to add an admin user to the WordPress database via MySQL, so you can get your access back.

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 without any other entry.

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 under the Databases section of your hosting account’s cPanel dashboard.

Here is a screenshot from the NameCheap control panel:

The first step is to locate the name of the database associated with your website. Go to cPanel > Files section > File Manager menu:

pl file manager 13

Find the wp-config.php file. Right-click on the file and select View or Edit option:

pl wp 1

You will see the database name in this line:

pl wp 27

Go to phpMyAdmin menu in the Databases section:

wp users 1

Go to the Insert tab:

wp users 2

Fill in the following information:

ID – any number you wish to assign to the user
user_login – username you want to use
user_pass – password for this user to access WordPress admin dashboard. You need to select MD5 from the drop-down menu in the Function column
user_nicename – you can set a nickname here
user_email – contact email of the new user
user_url – your website url
user_registered – date and time for when this user is registered
user_status – set this to 0
display_name – name, that will be displayed on the website

Once all the fields are filled in, click the Go button:

wp users 3

Now, go to the wp_usermeta table:

wp users 4 1

Go to the Insert tab:

wp users 2 1

In the first form, fill in the following information:

unmeta_id – leave this blank (it will be auto-generated)
user_id – ID you used for the user while adding it to wp_users table
meta_key – set it to wp_capabilities
meta_value – put the following:
a:1:{s:13:”administrator”;s:1:”1″;}

Fill the form below with the following details:

unmeta_id – leave this blank (it will be auto-generated)
user_id – ID you used for the user while adding it to wp_users table
meta_key – input following: wp_user_level
meta_value – insert following: 10

Once all the fields are filled in, click the Go button at the bottom:

wp users 5 1
wp users 6

We hope this tutorial helped you learn how to add an admin user to the WordPress database via MySQL. If you have any issue on this, you can use our comment session or join our delegate on Facebook to solve any issues related to WordPress and subscribe to our YouTube Channel for WordPress video tutorials

Share this Post

Leave a Comment

Your email address will not be published.

Scroll to Top