How to Create an Admin Account in WordPress via MySQL

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.

Did you know? Not all hosting companies provide free access to cPanel. InMotion does and it’s just one of the many features of our various {web hosting plans}.

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‘, ‘[email protected]‘, ‘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.

If you need a new home for your WordPress site, look no further than InMotion’s WordPress Hosting solutions for secure, optimized, budget-friendly servers.

check markFast & Easy Transfers check markFree SSLs check markHack Protection check markAffordable

View WordPress Hosting Plans

63 thoughts on “How to Create an Admin Account in WordPress via MySQL

  1. copying directly into phpmyadmin SQL area and it complains about syntax error near ‘lastname’ at line 1

    1. Hello Keith – We would need to be able to see the entire query to determine why you have a syntax error. Check for stray spaces, missing punctuation and misspelled keywords. Please provide the complete query if you wish for us troubleshoot the issue in this post.

  2. Check whether you are referring to the right table prefix if your database doesn’t use the default one i.e `wp_users`. your might be different e.g ‘wp_client’ ‘users_wp’ ‘wpcredentials’

    I had the same problem until I figured out that. So make sure you are typing the right table prefix.

  3. I keep getting the “Sorry, you are not allowed to access this page.” when I try to go to the dashboard. Any Advice? 

    1. Check your .htaccess file for rules that may be causing this. Often, during troubleshooting, I’ll simply rename the .htaccess to .htaccess.old and now I’ll reload the website. If the site loads I then know the issue resides in my configuration of the .htaccess file. If it does not fix the issue I was having, I’ll rename the .htaccess by removing the .old I added to the end. That way, it won’t affect my website after I resolve the issue. If your problems persist our WordPress Troubleshooting guide can help narrow the cause down further.
      Thank you,

  4. 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?

  5. 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?

    1. Hello,

      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.

    1. Hello,

      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

  6. Hi,


    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?

  7. 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', '[email protected]', '0');

    MySQL said: 
    #1046 - No database selected 
    that is what it shows. I do not know what to do next. Please reply me 
    Thank you

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

    1. Hello, This means the insertion ran smoothly. You should now be able to log in with the added user.

  9. 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.

    1. 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.

  10. Thanks!

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

    Best reggards

    Kenneth Meijer, Sweden

    1. 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.

  11. 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.

  12. 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.

    1. 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. 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?

  14. Hello,

    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 :\


    1. You will want to make sure the WordPress is pointed to the same database you made the alterations to.

  15. 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"),
  16. 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 = '[email protected]';
    -- Specify table prefix (WordPress default = 'wp_')
    SET @prefix='wp_';
    -- STOP! That's all, stop editing.
    -- Table names based on prefix SET @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 create_user; DEALLOCATE PREPARE set_capabilities; DEALLOCATE PREPARE set_user_level;


    1. 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,

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

    1. 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

  18. 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.

    1. 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.

Was this article helpful? Join the conversation!