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

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

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

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

    • 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,
      John-Paul

  • 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?

  • 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?

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

    • 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

  • 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?

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

    Error

    SQL query:

     

    INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
    VALUES ('Agatha', MD5('alive4U2017'), 'agatha nampeera', 'anampeera@gmail.com', '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

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

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

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

  • Thanks!

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

    Best reggards

    Kenneth Meijer, Sweden

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

      Regards,
      Arnel C.

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

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

    • 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?

  • 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?

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

    Thanks

  • 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"),
  • Here’s a way to do it that lets you set the table prefix:

    -- Specify new user data
    SET
    @user_login = 'newadmin', 
    @user_PASSWORD = 'newpass',
    @user_nicename = 'firstname lastname',
    @user_email = 'email@example.com';
    
    -- 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;

     

    • 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,
      John-Paul

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

    • 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

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

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

      Regards,
      Arnel C.

Leave a Reply to Sam Cancel reply