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.
Was this article helpful?
Continued Education in Course WordPress
You are viewing Section 28: How to Create an Admin Account in WordPress via MySQL
Section 27: 331: Setting Up the Max Upload File Size for a Wordpress MS installation
Section 29: 330: Finding the Network Administrator Interface for Wordpress MS

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

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

n/a Points
2018-04-15 1:12 pm

Thanks worked great.

n/a Points
2018-04-09 11:13 am

Worked perfectly! Thanks so very much for sharing your expertise. 

n/a Points
2018-03-26 12:39 pm

thank you for the guide! kudos

n/a Points
2018-02-21 11:42 pm

Hi , I have done everything and created the account but even though I can log in it says that I do not have access to admin  when I type in the correct URL. Any way I can get some help?

31,035 Points
2018-02-22 5:26 pm
I recommend following our WordPress Troubleshooting guide to narrow the issue down further.

Thank you,
n/a Points
2018-02-05 8:03 pm

Hi.  This worked insofar that I can now login with a new username & password; however, after logging in, it doesn't take me to my wordpress admin dashboard (where I can edit posts, pages, plugins, etc.)  It just takes me to the homepage (but shows that I am logged in).  Hmmm...  Any ideas?

41,498 Points
2018-02-07 11:30 am

We would need to know the actual URL you're using. Additionally, if you're using a security plugin, I would recommend you either re-load or reset it so that the new login is recognized. This article is simply for adding an admin user in an emergency such as when the admin password can't be recovered. Changing the URL does not change the way you login to the WordPress Administrator. It just adds a user that you can use to login as the Admin.

n/a Points
2018-01-23 11:07 am

thanks for info guys...

10,484 Points
2018-01-23 11:26 am
We're glad you found this helpful.
n/a Points
2017-12-11 11:21 am

Hello, can you confirm that it is still working ? Thanks.

1,046 Points
2017-12-11 12:55 pm

This does still work however you may need to change the "wp_" table prefix to match your configuration if you are not using the default.

Best Regards,
Kyle M
n/a Points
2017-12-10 1:57 am

Thanks man!

n/a Points
2017-11-09 1:31 pm



Thanks this worked and it let me create the admin however, when i go to the domain/wp-admin it still is not letting me login using the new username I just created. Any thoguths?

31,035 Points
2017-11-09 2:49 pm
Check your wp-config.php file to verify you are making the change to the right database.

If your problems persist, I recommend following our WordPress Troubleshooting guide to narrow it down further.

Thank you,
n/a Points
2017-10-22 12:36 am


Thank you.

n/a Points
2017-09-20 12:21 pm

Thank you very much..

n/a Points
2017-09-06 1:22 pm

Just use wp-cli:wp user create john --role=administrator --user_pass=password

n/a Points
2017-07-21 2:36 pm

Hi, thank you for the detailed tutorial. I have tried using it but it has failed. Instead, it brings up this 


SQL query:


INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('Agatha', MD5('alive4U2017'), 'agatha nampeera', '', '0');


MySQL said: Documentation

#1046 - No database selected 


that is what it shows. I do not know what to do next. Please reply me 

Thank you

n/a Points
2017-06-14 12:39 am

Greate tutorial. It was helpful to add an admin account in wordpress via mysql. Its really saved me Time.

n/a Points
2017-06-12 12:58 pm

Hi. I am getting a ONE ROW AFFECTED MESSAGE, I appreciate your help


43,761 Points
2017-06-12 1:08 pm
Hello, This means the insertion ran smoothly. You should now be able to log in with the added user.
n/a Points
2017-05-09 9:50 am

Thanks a lot. One week issue solved in minutes.

n/a Points
2017-04-24 5:15 pm

This is a great tool.  Thanks for spelling it out, but I have a problem.  

I am getting ERROR: User has not been activated.

The user name does show up in the user section.

43,761 Points
2017-04-24 7:10 pm
If you have no user on your WordPress site, it may be easier to just remove and re-install WordPress. The installation should start with an admin user. If it did not, there is no telling what else went wrong during the installation process.
n/a Points
2017-04-03 5:54 am

Thanks, Dude!

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

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

I got error 1146: table does not exist. 

41,498 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-02-12 4:18 am

Super Useful

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-03 6:08 am

The query ran ok - no errors. I can see the user in the wp_users table but WP won't let me login. I just get the shakey username box and and error that the username/password are incorrect.

2,858 Points
2017-02-03 11:24 am
Gordon, are other users still able to login? Have you tried clearing your cookies, and trying again? Are you using WordPress multi-site? Have you tried disabling your plugins, and deactivating your theme?
13,821 Points
2017-03-16 8:02 am
Try creating a new user again.
n/a Points
2016-12-04 5:51 pm



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

Very thank you!

n/a Points
2016-08-23 9:10 am

Thanks a lot! Very useful trick! :)

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?

10,484 Points
2016-07-19 2:33 pm
Is the user present in your WordPress installation under the Users section?
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,761 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-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
2017-04-07 4:09 pm

Also need to update wp_user_level and wp_capabilities to include Table Prefix

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
2015-11-09 10:35 am

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

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

Did you get any errors when trying this method?

Kindest Regards,
Scott M
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-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-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,761 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

31,035 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-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.

41,498 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-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-04-04 11:42 pm

Thanks Man

n/a Points
2014-09-28 12:57 pm

Thanks Man! This saved me time.

Post a Comment

Email Address:
Phone Number:

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

56 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!