InMotion Hosting Support Center

When working with programs that require you to log in, such as Wordpress, there can be times when you seem to be locked out of your account. This can happen via a code error, a hack, accidental admin account deletion, or a malicious site partner changing information on you. If this happens, you will need to create a new admin account in order to regain access to the administration interface. You will need to do this by interacting directly with the database. Below is a step by step guide for doing just that in your WordPress installation. We also have a helpful guide on How to Create a Wordpress User in the Dashboard.

Creating a new admin account via MySQL

The following instructions assume that your database table prefix is set to "wp_". If you are using something different, then make sure to adjust your code accordingly. For example, if you are using "wptables_" instead of "wp_", then the code "INSERT INTO `wp_users`" would be "INSERT INTO `wptables_users`".

  1. To begin, log into your cPanel interface.
  2. click the phpmyadmin iconFrom the main cPanel screen, find the Databases category and click on the icon entitled phpMyAdmin.
  3. Once the first screen appears, look to the left hand sidebar and click on the database for your specific WordPress installation. If you do not know which database is the correct one, you can find out by using these instructions.
  4. click on the SQL tabAfter the database information loads, you will need to find the tab named SQL and click on it.
  5. This leads you to an SQL editor where you will enter some code that will create a new admin account for you. Below is the code to create a new admin account named newadmin with the password pass123. You may change any of the content in red to fit your needs, but leave all other data as is.
    INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
    VALUES ('newadmin', MD5('pass123'), 'firstname lastname', '', '0');

    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
  6. click go buttonAfter replacing any data fields you need, click the Go button to perform the insertion.
  7. This should simply refresh the screen and you should see the messsage '1 row affected' after each of the three SQL statements. This means the insertion ran smoothly. From here, visit your wordpress admin login area as normal and use the new admin login information. You should get to the admin interface without issue.
Continued Education in Course WordPress
You are viewing Section 23: 333: How to Add an Admin account in WordPress via MySQL
Section 22: 331: Setting Up the Max Upload File Size for a Wordpress MS installation
Section 24: 330: Finding the Network Administrator Interface for Wordpress MS

Support Center Login

Social Media Login

Social Login Joomla

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-09-28 12:57 pm

Thanks Man! This saved me time.

n/a Points
2015-04-04 11:42 pm

Thanks Man

n/a Points
2015-04-07 1:16 pm

Thank you so much for this tutorial. I'm very thankful for the help. You really saved me today.


n/a Points
2015-05-06 4:44 am

This works only if the prefix for wordpress tables is set to "wp_". Otherwise, it will fail, and result to permissions errors. As such, don't forget to set 'wp_capabilities' to whatever prefix your Wordpress installation has. For instance, if your prefix is wp_en, then your wp_capabilities should be wp_encapabilities.

37,501 Points
2015-05-06 5:55 am
Hello Rommel,

Thanks for pointing that out. The database prefix is definitely something that can be set to something OTHER than "wp_", so to anyone reading these comments and this tutorial, please be aware of that. I will update the article to make note of this issue.

Arnel C.
n/a Points
2015-05-30 3:38 pm

This doesn't work for multisite. I tried this and after that I only see one site. Please advice.

43,209 Points
2015-06-01 11:30 am
Hello Sam,

This article is specific to regular WordPress. We have not tested this on multi-site so we do not know the specifics for it as of yet.

Kindest Regards,
Scott M
n/a Points
2015-06-25 4:19 pm

We really need to know how does this work for multisite

27,869 Points
2015-06-25 6:46 pm
Hello Sam,

Thank you for contacting us. I spent some time looking into this, and couldn't find a helpful tutorial on creating an admin in multisite. If there are other user accounts in the database, you can give a user Super Admin access.

This should allow you to regain admin access with a different user account. Then, you can create users from the dashboard again.

If your problems persist, the official Multisite Support Forums are a good place to seek help since it it is frequented by multisite users/developers.

Thank you,
n/a Points
2015-06-03 1:49 am

Thanks for one of the simplist how 2s on a complicated issue that i have

seen in a while

n/a Points
2015-06-24 9:16 pm

You've Helped me with this problem, a hacker who changed all accounts! Now I can tell him you are wrong hacker!

n/a Points
2015-08-23 11:55 pm

thx u bro,, grat job :))

n/a Points
2015-11-09 10:35 am

i tried running this but it doesn't work with mysql 5.5

43,209 Points
2015-11-09 7:48 pm

Did you get any errors when trying this method?

Kindest Regards,
Scott M
n/a Points
2016-01-25 3:03 am

Thank you very much :)

n/a Points
2016-02-07 4:55 pm

Here's a way to do it that lets you set the table prefix:

-- Specify new user data
@user_login = 'newadmin', 
@user_PASSWORD = 'newpass',
@user_nicename = 'firstname lastname',
@user_email = '';

-- Specify table prefix (WordPress default = 'wp_')
SET @prefix='wp_';

-- STOP! That's all, stop editing.
-- Table names based on prefix
@wp_users = CONCAT(@prefix, 'users'),
@wp_usermeta = CONCAT(@prefix, 'usermeta');

-- SQL statement strings with question marks for data placeholders
SET @create_user = CONCAT("INSERT INTO ", @wp_users, " SET `user_login`= ?, `user_pass`= ?, `user_nicename`= ?, `user_email`= ?, `user_status`=0");
SET @set_capabilities = CONCAT("INSERT INTO ", @wp_usermeta, " SET `umeta_id`=NULL, `user_id`=(SELECT max(`id`) FROM ", @wp_users, " WHERE `user_login`= ?), `meta_key`='wp_capabilities', `meta_value`='a:1:{s:13:\"administrator\";s:1:\"1\";}' ");
SET @set_user_level = CONCAT("INSERT INTO ", @wp_usermeta, " SET `umeta_id`=NULL, `user_id`=(SELECT max(`id`) FROM ", @wp_users, " WHERE `user_login`= ?), `meta_key`='wp_user_level', `meta_value`='10' ");

-- Prepare and execute the statements
PREPARE create_user FROM @create_user;
PREPARE set_capabilities FROM @set_capabilities;
PREPARE set_user_level FROM @set_user_level;

EXECUTE create_user USING @user_login, @user_password, @user_nicename, @user_email;
EXECUTE set_capabilities USING @user_login;
EXECUTE set_user_level USING @user_login;

DEALLOCATE PREPARE set_capabilities;
DEALLOCATE PREPARE set_user_level;


n/a Points
2016-02-07 5:00 pm

EDIT: Forgot the MD5 wrapper for the password. Please update before posting:

Change this:

@create_user = CONCAT("INSERT INTO ", @wp_users, " SET `user_login`= ?, `user_pass`= ?, `user_nicename`= ?, `user_email`= ?, `user_status`=0"),

to this:

@create_user = CONCAT("INSERT INTO ", @wp_users, " SET `user_login`= ?, `user_pass`= MD5(?), `user_nicename`= ?, `user_email`= ?, `user_status`=0"),
n/a Points
2016-02-28 3:50 am

Thanks Man it helped me a lot

n/a Points
2016-05-01 6:57 pm

Thanks! :)

n/a Points
2016-06-19 10:35 am


I've tried running this query but it doesn't seem to work.

i.e - the query itself executed correctly, all the tables were affected like they should have been, but I simply can't log in with the new username & password :\


43,209 Points
2016-06-20 12:29 pm
You will want to make sure the WordPress is pointed to the same database you made the alterations to.
n/a Points
2016-07-19 1:31 am

I tried this and then I got the error after I t: ERROR: User has not been activated.

Is there anything else I need to do?

7,695 Points
2016-07-19 2:33 pm
Is the user present in your WordPress installation under the Users section?
n/a Points
2016-08-23 9:10 am

Thanks a lot! Very useful trick! :)

n/a Points
2016-09-25 7:50 am

Very thank you!

n/a Points
2016-12-04 5:51 pm



n/a Points
2017-02-08 12:31 pm

Please note that the prefix used in the meta_key and meta_value is case-sensitive, otherwise you will get a 403 permission error (or at least I did, I got the case wrong for the table prefix at first.

n/a Points
2017-02-12 4:18 am

Super Useful

n/a Points
2017-02-22 4:40 pm

I got error 1146: table does not exist. 

37,501 Points
2017-02-22 7:43 pm
Hello Scott,

If your table names have been changed, then you need to change the code to match the new table names. Typically, it's just the prefixes you need to change.

If you have any further questions or comments, please let us know.

Arnel C.
n/a Points
2017-03-15 5:50 pm


I'm very greatfull for your support, how you show how to add an admin-account.

Best reggards

Kenneth Meijer, Sweden

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

34 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!