How To Add An Admin User To The WordPress Database Via MySQL
Last modified: May 20, 2026
More than half of small businesses are targeted by hackers each year. When an attacker gains access to your WordPress site, one of their first moves may be to delete your admin account from the database, leaving you completely locked out with no way to log in.
The good news is that you can bypass the front-end login entirely and add a new admin user directly through MySQL. This same technique works if you’re migrating a site and the admin email no longer exists, if a plugin bug corrupted the user table, or if you simply can’t access the registered email to trigger a password reset. As long as you have access to phpMyAdmin (through your hosting control panel) or a direct MySQL connection, you can restore admin access in a few minutes.
Before you start, make a full backup of your MySQL database. Your hosting panel usually offers a one-click database export; do that first. If something goes wrong during the process, you’ll be able to restore from the backup rather than dealing with a broken database.
Three Ways to Access Your WordPress Database
The steps below use phpMyAdmin, which is available through most hosting control panels (cPanel, Plesk, Kinsta, WP Engine). If phpMyAdmin is not available on your host, you have two alternatives:
- WP-CLI: If you’re on a managed host with SSH access and WP-CLI installed, you can add an admin user in one command:
wp user create newadmin [email protected] --role=administrator --user_pass=YourSecurePassword. Replace the username, email, and password with your own. This is faster than the phpMyAdmin method and skips the database editing entirely. - SSH + MySQL CLI: If you have SSH access but no WP-CLI, connect via SSH and run:
mysql -u DB_USERNAME -p DB_NAME(replace with your values from wp-config.php). Once connected, you can run INSERT queries directly against wp_users and wp_usermeta. This is the same logical process as the phpMyAdmin steps below, just without the GUI.
If none of these apply, continue with the phpMyAdmin method in the steps below.
* This button will show the rest of the post and open up an offer from a vendor
Step 1 – phpMyAdmin
Open your hosting control panel (cPanel, Plesk, or your host’s custom dashboard) and click phpMyAdmin. If you’re on a managed host like Kinsta or WP Engine, you’ll find phpMyAdmin access within their site dashboard.
Once you’re in phpMyAdmin, look at the left sidebar for a list of databases. Click the one associated with your WordPress site. If you’re not sure which database your site uses, open your wp-config.php file (in your site’s root folder) and look for the DB_NAME value; that’s your database.
With the database selected, you’ll see a list of tables. Most WordPress installations use the default wp_ prefix, but some use a custom prefix chosen during installation. If you don’t see wp_users, look for a table ending in _users; that’s the one you need. If you’re unsure of your prefix, open wp-config.php and look for the $table_prefix variable.
Step 2 – wp_users
Click on the wp_users table (replace wp_ with your custom prefix if needed) and click the Insert tab at the top. Fill in each field as follows:
ID: Pick a number not already in use. Scroll through the existing rows to find the highest ID, then use the next number up.
user_login: The username for your new admin account. Keep it simple and unique.
user_pass: Your password. In the Function column next to this field, select MD5 from the dropdown. WordPress stores passwords as hashed values, and selecting MD5 here handles that automatically. On your first login, WordPress will upgrade the hash to a stronger format.
user_nicename: A URL-friendly version of your name: lowercase, hyphens instead of spaces (e.g. john-smith).
user_email: The email address for this account.
user_url: Optional. Your site URL or leave it blank.
user_registered: Today’s date and time in this format: 2026-05-20 12:00:00
user_activation_key: Leave blank.
user_status: Set to 0 (active).
display_name: How your name appears publicly on the site. Can match user_nicename or be your full name.
Click Go to save. Write down the ID you used; you’ll need it in the next step.
Step 3 – wp_usermeta
Click on wp_usermeta in the left sidebar (again, substitute your custom prefix if needed) and click the Insert tab. You need to add two separate rows to grant full administrator access.
Row 1, Capabilities:
umeta_id: Leave blank (auto-generated).
user_id: The same ID you used in Step 2.
meta_key: wp_capabilities (or yourprefix_capabilities if you have a custom table prefix)
meta_value: Paste this exactly: a:1:{s:13:"administrator";b:1;}
Click Go, then click Insert again to add the second row.
Row 2, User Level:
umeta_id: Leave blank.
user_id: Same ID as above.
meta_key: wp_user_level
meta_value: 10
Click Go. The wp_user_level value of 10 ensures compatibility with older themes and plugins that check this field when determining admin access.
Now try logging in to WordPress with the username and password you created in Step 2. If it works, move on to Step 4 to finish the setup.
Step 4 – Clean Up
Once logged in, go to Users in the WordPress admin sidebar and click on your new account. Scroll to the bottom and click Update User without changing anything. This prompts WordPress to rebuild the user’s capability data in its own serialized format, replacing the raw database value you inserted with a properly structured version.
While you’re in the Users section, review all existing accounts. Delete any unfamiliar usernames; attackers often create backdoor admin accounts alongside the damage they do. Then go to Settings > General and confirm the admin email address is correct.
If a hacker deleted your account, treat the entire site as compromised and complete this checklist before doing anything else:
- Change your database password: In cPanel or your host dashboard, regenerate the MySQL user password and update the DB_PASSWORD value in wp-config.php immediately.
- Scan for backdoors: Install a security plugin such as Wordfence or Malcare and run a full scan. Attackers frequently plant PHP backdoor files in wp-content/uploads/ or rename them to look like WordPress core files.
- Rotate all passwords: Change your hosting account password, your FTP/SFTP credentials, and any email accounts associated with the site.
- Check file modification dates: Via FTP, sort files by modification date. Any PHP file modified around the time of the attack that is not a plugin or theme update is suspicious.
Finally, head to Dashboard > Updates and apply any pending WordPress core, theme, or plugin updates. A site that was successfully attacked almost always had an unpatched vulnerability; staying up to date is the most effective way to prevent it from happening again.
Final Word: How to Add an Admin User to the WordPress Database via MySQL
If your login details have been deleted and you can’t access the backend of WordPress, use the steps above to create a new admin account directly in the database. It’s a reliable method that works regardless of email access or the state of your front-end login system.
Once you’re back in, take site security seriously. Install one of the better WordPress security plugins and review your WordPress user roles to make sure no accounts have unnecessary admin privileges.
Website Maintenance – Use Promocode: scanwp
Advanced JetPlugins for Elementor
Semrush 14 days trial
Kinsta – Managed WordPress Hosting
Bluehost Hosting