WordPress emergency admin user generator
Builds the SQL that adds a new administrator straight to the database — for the day every admin account is lost and nothing else works. The password is hashed as WordPress 6.8+ $wp$2y$ in your browser.
Fill in the account above, then select Generate SQL.
Run all statements together in one session: LAST_INSERT_ID() only refers to the row this session just inserted. Then sign in, set a new password from the profile screen, and delete the emergency account once a normal administrator exists again.
What the SQL does
A WordPress account lives in two tables. The first statement adds the row in the users table — login, the hashed password, a URL-safe user_nicename, email and the registration time in UTC. The second captures the new row's ID, and the last one gives that ID two pieces of user meta: {prefix}capabilities, holding the serialized array a:1:{s:13:"administrator";b:1;} that makes the account an administrator, and {prefix}user_level set to 10, which older plugins still check.
Both meta keys start with the table prefix — wp_capabilities on a default install, wpx9_capabilities on a wpx9_ one. Getting that wrong is the classic failure: the account exists and the password works, but WordPress sees no role and refuses the dashboard with "Sorry, you are not allowed to access this page." If you are not sure of the prefix, read $table_prefix in wp-config.php, or follow the users table guide.
Quick answers
When should I create an admin user with SQL?
Only when no administrator can sign in, the email reset cannot reach any admin, and there is no shell access for WP-CLI. If even one admin account still exists, resetting its password is safer than adding a new account — see the guide to every reset method.
Does this work on WordPress multisite?
It creates an administrator of the main site only. A network super admin is also listed in the site_admins row of the network's sitemeta table, as a serialized array of usernames, so on multisite add the new login there too — or use WP-CLI's super-admin command once you have shell access.
Why does the new admin see "Sorry, you are not allowed to access this page"?
The capabilities meta key does not match the site's table prefix, or the serialized value was altered. Check that the key is exactly the prefix followed by capabilities and that the value is a:1:{s:13:"administrator";b:1;} with the 13 unchanged.
Which WordPress versions accept the generated password hash?
The $wp$2y$ hash works on WordPress 6.8 and later. For 6.7 and earlier, generate a phpass hash with the legacy generator and replace the user_pass value in the first statement before running it.