Locked out of WordPress with no working administrator account? If you can still reach the database, you can create a new administrator directly in MySQL. This guide shows the quickest SQL method, the phpMyAdmin method, and the mistakes that most often leave the new user without admin rights.
Note These steps were checked on WordPress 7.1.3 with PHP 8.2 in November 2026.
Before you start
- Take a database backup first. You are editing user tables directly.
- Find your table prefix. Open
wp-config.phpand look for$table_prefix. It iswp_by default, but many sites use something else, such aswpi_orwp7x_. Every table and meta key below must use your prefix. - If you have SSH access, try WP-CLI first. It is safer than editing tables by hand (see the next section).
The easiest way: WP-CLI
If WP-CLI is installed on the server, one command creates a proper administrator with a correctly hashed password:
wp user create rescue_admin [email protected] --role=administrator --user_pass='a-long-unique-password'
If you only need a new password for an existing administrator, update that account instead of creating another:
wp user update existing_admin --user_pass='a-long-unique-password'
If you do not have WP-CLI, use one of the SQL methods below.
Step 1 Run the SQL to create the user
Open phpMyAdmin (or Adminer, or the mysql command line), select your WordPress database and open the SQL tab. Replace wp_ with your table prefix in all three statements, then change the username, password and email:
INSERT INTO wp_users (user_login, user_pass, user_nicename, user_email, user_registered, user_status, display_name)
VALUES ('rescue_admin', MD5('a-long-unique-password'), 'rescue_admin', '[email protected]', NOW(), 0, 'Rescue Admin');
SET @uid = LAST_INSERT_ID();
INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES
(@uid, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}'),
(@uid, 'wp_user_level', '10');
Run all three statements together, so LAST_INSERT_ID() still holds the new user’s ID.
Important Both meta keys start with your table prefix too. On a site whose prefix is wpi_, they must be wpi_capabilities and wpi_user_level. With the wrong prefix the user can log in but has no role, so the dashboard shows “Sorry, you are not allowed to access this page.”
Why MD5 is safe to use here
WordPress has not stored passwords as MD5 for many years, and since WordPress 6.8 it uses bcrypt. It still accepts an old MD5 hash once, so emergency fixes like this one keep working. In our test on WordPress 7.1.3, the MD5 value inserted above was accepted, and on the first successful login WordPress replaced it with a bcrypt hash starting with $wp$2y$. You do not need to do anything else, but do log in straight away so the weak hash is replaced.
Step 2 Or do it through the phpMyAdmin forms
If you prefer the forms to SQL, the same values go in through Insert:
- Open the
wp_userstable (with your prefix) and click Insert. - Leave
IDempty. Fill inuser_login,user_email,user_nicenameanddisplay_name. Setuser_statusto 0 anduser_registeredto the current date and time. - For
user_pass, type the password and choose MD5 in the Function column. Click Go, then note the new user’sID. - Open the
wp_usermetatable and insert two rows for thatuser_id:meta_keywp_capabilities,meta_valuea:1:{s:13:"administrator";b:1;}meta_keywp_user_level,meta_value10
Tip Older tutorials, including the first version of this one, use a:1:{s:13:"administrator";s:1:"1";} for the capabilities value. That still works. The b:1 form above is what WordPress itself writes.
Step 3 Log in and tidy up
- Go to
/wp-login.phpand log in with the new account. - Open Users › Profile, check the details and click Update Profile. This lets WordPress fill in any fields you left empty.
- Fix the original problem: reset the password of your normal account, or remove an account you no longer trust.
- When you are back in, delete the rescue account or give it a strong password and two-factor authentication. Do not leave a spare administrator lying around.
Note If a security plugin such as Wordfence adds a CAPTCHA or two-factor check to the login form, it still applies to the new account. Complete it as usual.
Troubleshooting
- “Sorry, you are not allowed to access this page”: the capabilities row is missing or uses the wrong prefix. Check
SELECT * FROM wp_usermeta WHERE user_id = 123;(with your prefix and the new user’s ID). - Login says the password is incorrect: make sure MD5 was applied to the password, and that the value in
user_passis 32 characters long, not the plain password. - Duplicate entry error: the username or email already exists. Pick another, or reset that user’s password instead.
- Multisite: a network super admin is also listed in the
site_adminsrow of thewp_sitemetatable. Creating the user as above only makes them an administrator of the main site.
When you should not do this
If you did not lose access yourself, an unknown administrator or missing account can be a sign the site was hacked. Creating another admin will not fix that. Check the users list for accounts you do not recognise, change all passwords and your database password, and scan the site before you carry on.
Conclusion
With database access, three SQL statements give you a working WordPress administrator again: one row in wp_users and two rows in wp_usermeta, all using your table prefix. Log in straight away so WordPress upgrades the password hash, then remove the rescue account once you have fixed the original problem.
Official reference Resetting your password · wp user create · wp-config.php
Leave a Reply