Skip to content
ThemesIonic — home
WordPress Tutorials

How to Add a WordPress Admin User via phpMyAdmin

One row in wp_users and two in wp_usermeta, with the table prefix inside the meta key names. The exact SQL, what each value does, and what breaks when one is wrong.

Updated 5 min read advanced

An administrator is one row in wp_users plus two rows in wp_usermeta — wp_capabilities and wp_user_level — with your real table prefix inside the meta key names. Miss the meta rows and you get an account that logs in and lands on the home page.

Export the database before you run anything; how to back up a WordPress site covers the quickest way.

An account row in wp_users linked by ID to two wp_usermeta rows that grant the administrator role.
The account lives in wp_users; the role lives in wp_usermeta. Insert only the first and the user logs in with no capabilities.

Step 1: read the table prefix

Open wp-config.php and find:

$table_prefix = 'wp_';

Many hosts randomise it. Everything below uses wp_; replace it in table names and in the two meta keys.

Step 2: run the whole insert at once

In phpMyAdmin, select the database, open the SQL tab and run all three statements in one go, so LAST_INSERT_ID() still refers to the new user:

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-passphrase'), 'rescue_admin',
     'you@example.com', UTC_TIMESTAMP(), 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');

UTC_TIMESTAMP() matches what WordPress itself writes to user_registered; NOW() also works but records the database server's local time.

What each value does, and what breaks if it is wrong

Row / field What reads it If it is wrong or missing
user_login The login form (username lookup) "The username … is not registered on this site"
user_pass wp_check_password() at login "The password you entered for the username … is incorrect."
user_email Login by email, password reset Reset mail goes nowhere; a duplicate email makes email login ambiguous
user_nicename Author archive URL /author/{nicename}/ Empty or with spaces: broken author links
user_registered, user_status, display_name Users list, bylines Cosmetic; user_status should stay 0
wp_capabilities WP_User — the role, per site Login succeeds, you are sent to the home page, /wp-admin/ shows "Sorry, you are not allowed to access this page."
wp_user_level Legacy; still used by the who=authors user query Admin works, but the account is missing from the editor's Author dropdown
administrator role in wp_user_roles (wp_options) Maps the role name to capabilities If a role plugin deleted the role, the capabilities row grants nothing

Two details in the capabilities row matter. It is a serialised PHP array: a:1: is the element count and s:13: is the byte length of administrator, so a single changed character makes it unreadable and WordPress treats the user as having no role. And the key is prefixed even though the table name already is — xy_usermeta holds xy_capabilities.

user_level still matters a little in WordPress 7.1.5: the REST users endpoint answers who=authors by querying user_level != 0, and the block editor builds its author list that way. Core rewrites the value from your role the next time the role is saved, but there is no reason to leave it out.

The password: what WordPress accepts in user_pass

Since 6.8 WordPress hashes with bcrypt, but wp_check_password() still accepts older formats:

Stored value How it is checked You can produce it in SQL?
32 characters or fewer Compared as an MD5 of the password Yes: MD5('…')
Starts with $wp (e.g. $wp$2y$12$…) WordPress bcrypt with a SHA-384 pre-hash No
Starts with $P$ Old phpass portable hash No
Anything else (e.g. plain $2y$…) PHP password_verify() No

On the first successful login, a hash that is not in the current $wp format is replaced automatically. So MD5() is a valid one-time bootstrap: log in once and the 32-character value becomes a $wp$2y$… hash.

On a WordPress 7.1.5 test install, a user inserted this way with MD5('Str0ng-Rescue-Pass') logged in and reached Users › Add User. The stored hash before and after that first login:

before: 5525151a2f67e3c9694705163581e2f4
after:  $wp$2y$12$4e…

Storing the password as plain text does not work: a short plain value is compared as if it were an MD5 hash and fails. If you need a ready-made bcrypt value instead, the WordPress password hash generator produces one in your browser with the matching SQL.

Changing an existing user to administrator

If the account exists and has lost its role — a role editor misfire, a membership plugin that demoted everyone — promote it instead of adding a second admin:

SELECT ID, user_login FROM wp_users WHERE user_login = 'yourname';

UPDATE wp_usermeta
SET meta_value = 'a:1:{s:13:"administrator";b:1;}'
WHERE user_id = 1 AND meta_key = 'wp_capabilities';

UPDATE wp_usermeta
SET meta_value = '10'
WHERE user_id = 1 AND meta_key = 'wp_user_level';

Replace 1 with the ID from the first query. phpMyAdmin reports "0 rows affected" when nothing matched, which looks like success; in that case the row does not exist and you need the INSERT INTO wp_usermeta statement from step 2 with that ID.

Verify before leaving phpMyAdmin

SELECT u.ID, u.user_login, LENGTH(u.user_pass) AS pass_len, m.meta_key, m.meta_value
FROM wp_users u
JOIN wp_usermeta m ON m.user_id = u.ID
WHERE u.user_login = 'rescue_admin'
  AND m.meta_key IN ('wp_capabilities', 'wp_user_level');

Two rows with pass_len 32 mean the insert is right. One row or none tells you which statement failed before you try the login screen. If login then loops back to the form instead of erroring, that is a cookie or URL problem — see the login redirect loop guide.

Multisite

Two differences:

  • Per-site role. Site 1 uses wp_capabilities; site 2 uses wp_2_capabilities, and so on. A user without a capabilities row for a site is not a member of it.
  • Super admin is not a user meta row. It is the site_admins row in wp_sitemeta: a serialised array of usernames. To add rescue_admin next to admin:
UPDATE wp_sitemeta
SET meta_value = 'a:2:{i:0;s:5:"admin";i:1;s:12:"rescue_admin";}'
WHERE meta_key = 'site_admins';

Recount the s: lengths and the a: count for your own names, and keep the existing entries.

Safer routes when you have them

With SSH, WP-CLI does all of this through WordPress's own functions, so hashing, prefix and user_level are handled for you:

wp user create rescue_admin you@example.com --role=administrator --user_pass='a-long-unique-passphrase'
wp super-admin add rescue_admin   # multisite only

With file access but no database, a must-use plugin in wp-content/mu-plugins/rescue.php does the same on the next page load:

<?php
add_action( 'init', function () {
	if ( username_exists( 'rescue_admin' ) ) {
		return;
	}
	$id = wp_create_user( 'rescue_admin', 'a-long-unique-passphrase', 'you@example.com' );
	if ( ! is_wp_error( $id ) ) {
		( new WP_User( $id ) )->set_role( 'administrator' );
	}
} );

Delete the file immediately after: it contains the password in plain text.

Afterwards

  1. Change the password from Profile, even though it is already rehashed.
  2. Check Users for accounts you do not recognise.
  3. When the real account is back, delete the rescue user and attribute its content to another user.

If you were locked out by someone changing your account rather than by a lost password, an attacker with database access can do far more than that — follow how to fix a hacked WordPress site.

Frequently asked

Find the user's ID in wp_users, then set the wp_capabilities row in wp_usermeta to a:1:{s:13:"administrator";b:1;} and wp_user_level to 10 for that user_id. If the UPDATE reports zero affected rows, the row does not exist and you need an INSERT instead.
Every table name and both meta keys. WordPress reads the role from a meta key built as prefix + capabilities, so a site with prefix xy_ needs xy_capabilities and xy_user_level in xy_usermeta. A wp_capabilities row on that site is simply ignored.
As a one-time bootstrap, yes. WordPress checks any stored hash of 32 characters or fewer as MD5, and on the first successful login it rehashes the password with bcrypt (a hash starting $wp$2y$). Change the password from the profile screen afterwards anyway, since the passphrase has passed through SQL history.
Tagged Security

Related guides