WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My site recently got hacked, and all my admin users lost their administrator level access. But when I access mySQL database, I saw all the users still exist.

How can I create an administrator when I can access the database only?

share|improve this question
Google "wordpress create user in the database". The first three or four results will tell you exactly how to do it. – bcorkins Mar 6 '13 at 14:28
@bcorkins We collect canonical answers here. – toscho Mar 6 '13 at 14:47
up vote 3 down vote accepted

Run this script in phpMyAdmin or whatever tool you use to access MySQL:

SET @user_login := 'justin_foell';
SET @user_pass := 'Q9xiHgzZ';
SET @user_email := 'justin@9seeds.com';

INSERT INTO `wp_users` 
(`user_login`, `user_pass`, `user_email`, `user_registered`) 
(@user_login, MD5(@user_pass), @user_email, now());

SELECT @user_id := LAST_INSERT_ID();

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

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

Replace the set values at the top for @user_login, @user_pass and @user_email with your own settings. Also, if your WordPress installation uses tables that start with a prefix other than wp_, you’ll want to replace that in the table names as well.

From: https://9seeds.com/tech/inserting-yourself-as-admin-into-wordpress/

share|improve this answer
Wow super helpful! Site back to live :D Thanks! – Adam Mar 6 '13 at 15:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.