If you are locked out of a WordPress website you administer, database access can be used to create an administrator account for recovery. This guide explains the MySQL method for a standard single-site WordPress installation.
Before you start
Try WordPress’s password reset or an existing administrator account first. Direct database changes bypass WordPress’s normal user creation checks and plugin actions.
Back up the database and confirm which database belongs to the website. Check the table prefix in wp-config.php: the example below uses wp_ and must be adjusted if yours differs. This procedure is not a WordPress Multisite administrator recovery procedure.
Create the recovery account
-
Open phpMyAdmin from your hosting control panel and select the website’s database.
-
Check that the proposed username and email address are not already used in the users table.
-
Open the SQL tab.
-
Replace the username, email address and password placeholders below with your own values. Use a strong, unique temporary password. Escape any single quote inside a SQL string as two single quotes.
-
Replace
wp_in both table names and both metadata keys with the installation’s actual prefix. -
Run all these statements together so
LAST_INSERT_ID()refers to the account just created:INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_registered`, `user_status`, `display_name`) VALUES ('recoveryadmin', MD5('REPLACE_WITH_A_UNIQUE_TEMPORARY_PASSWORD'), 'recoveryadmin', '[email protected]', UTC_TIMESTAMP(), 0, 'Recovery administrator'); SET @new_user_id = LAST_INSERT_ID(); INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`) VALUES (@new_user_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}'), (@new_user_id, 'wp_user_level', '10'); -
Check for SQL errors. If any statement fails, inspect the records created before retrying rather than running the entire block again blindly.
-
Sign in to WordPress using the new account.
Complete the recovery
Immediately set a new password through the WordPress profile screen. The SQL example uses the legacy MD5 format that WordPress accepts for compatibility; it should not be used as a normal password storage method.
Review existing administrator accounts and investigate why access was lost. Once a permanent administrator account is working, remove the temporary recovery account if it is no longer needed.