How to create new admin user via database in WordPress

Creating a new admin user directly via the WordPress database can be useful if you’re locked out of your admin panel or if you need to add a user without access to the WordPress dashboard. Here’s a step-by-step guide on how to do it safely.

How to Create a New Admin User via Database in WordPress

Step 1: Access Your Database

  • Use phpMyAdmin or any database management tool provided by your hosting.

  • Select your WordPress database.

Step 2: Insert New User into wp_users Table

Run this SQL query to add a new user:

INSERT INTO `wp_users`
(`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `display_name`)
VALUES
('newadmin', MD5('StrongPassword123'), 'newadmin', '[email protected]', 0, 'New Admin');
  • Replace 'newadmin' with your desired username.

  • Replace 'StrongPassword123' with a secure password.

  • Replace '[email protected]' with the user’s email.

Note: By default, WordPress uses salted hashes, but using MD5() here works for immediate login; WordPress will update the password hash on first login.

Step 3: Get the ID of the New User

After insertion, note the ID of the newly created user from the wp_users table. If you’re using phpMyAdmin, it will show the last inserted ID.

Step 4: Add User Capabilities in wp_usermeta Table

Run these two queries to give admin capabilities:

INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES
(LAST_INSERT_ID(), 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES
(LAST_INSERT_ID(), ‘wp_user_level’, ’10’);

  • Replace LAST_INSERT_ID() with the actual user ID if your tool doesn’t support it.

  • Make sure the meta_key prefix (wp_) matches your database table prefix (e.g., wp_, wp123_).

Step 5: Log in to WordPress

  • Go to your WordPress login page.

  • Log in with the new username and password.

Important Tips

  • Always backup your database before making direct changes.

  • Adjust table prefixes (wp_) if you use a custom prefix.

  • Use a strong, unique password.

  • After logging in, update the password from the dashboard for proper hashing.

Here’s a ready-to-run SQL script template you can use to create a new admin user via the database in WordPress. Just replace the placeholders to fit your setup:

-- Replace `wp_` with your actual table prefix (e.g., wp123_)
-- Replace 'newadmin' with desired username
-- Replace 'StrongPassword123' with your password
-- Replace '[email protected]' with user email
-- Replace 'New Admin' with display name

INSERT INTO `wp_users`
(`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `display_name`, `user_registered`)
VALUES
('newadmin', MD5('StrongPassword123'), 'newadmin', '[email protected]', 0, 'New Admin', NOW());

-- Get the ID of the newly created user
SET @user_id = LAST_INSERT_ID();

INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES
(@user_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');

INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES
(@user_id, 'wp_user_level', '10');


How to use:

  1. Open phpMyAdmin or your database tool.

  2. Select your WordPress database.

  3. Paste the above SQL script into the SQL query box.

  4. Update the wp_ prefix if your tables use a different prefix.

  5. Change the username, password, email, and display name as needed.

  6. Run the query.