Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Add an Admin User to the WordPress Database via MySQL

Few days ago, we ran into an issue where a user’s site got hacked and their admin account was deleted from the database. This locked them out of their site without any other entry. We went in to the phpMyAdmin and created a new admin user to grant them access. In this article, we will show you a step by step guide on how to create an admin user in WordPress Database via MySQL.

Note: You should always make a backup of your database before performing any MySQL edits. This tutorial requires basic understanding of how phpMyAdmin works.

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

First, you need to login to phpMyAdmin and locate your WordPress database. (Below is a screenshot of a HostGator cPanel)

cPanel phpMyAdmin

Once you are in, we will be making changes to the wp_users and wp_usermeta tables. Lets go ahead and click on wp_users table.

phpMyAdmin wp_users table

We need to insert our new admin user’s information, so click on the Insert tab like it shows in the image above. In the insert form, add the following:

  • ID – pick a number (in our example, we will use the number 4).
  • user_login – insert the username you want to use to access the WordPress Dashboard.
  • user_pass – add a password for this username. Make sure to select MD5 in the functions menu (Refer to the screenshot below).
  • user_nicename – put a nickname or something else that you would like to refer yourself as.
  • user_email – add the email you want to associate with this account.
  • user_url – this would be the url to your website.
  • user_registered – select the date/time for when this user is registered.
  • user_status – set this to 0.
  • display_name – put the name you like to display for this user on the site (it can be your user_nicename value as well).
  • Click on the Go Button

phpMyAdmin Insert values in wp_users table

Next we are going to have to add the values to wp_usermeta table. Click on the wp_usermeta table and then click on the Insert tab just like the previous step. Then add the following information to the insert form:

  • unmeta_id – leave this blank (it will be auto-generated)
  • user_id – this will be the id of the user you created in the previous step. Remember we picked 4.
  • meta_key – this should be wp_capabilities
  • meta_value – insert this: a:1:{s:13:"administrator";s:1:"1";}

Insert another row with the following information:

  • unmeta_id – leave this blank (it will be auto-generated)
  • user_id – this will be the id of the user you created in the previous step. Remember we picked 4.
  • meta_key – this should be wp_user_level
  • meta_value – 10

Then click on the Go button, and you have created yourself a new username. Now you should be able to login to your wp-admin with the username and password you specified for this user. Once logged in, click on Users and edit the username you just created. Go down and click on the Save button (you don’t have to change anything). This will allow WordPress to go through and add some more information and clean-up the user we just added.

SQL query

For developers who want to speed this process up, you can simply drop this SQL query in your database.

INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Your Name', '', '', '2011-06-07 00:00:00', '', '0', 'Your Name');

INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');

Remember to change the databasename to the database you are working with. Also don’t forget to change the appropriate values.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

216 CommentsLeave a Reply

  1. Thanks for the tips it really worked and i could know a lot more about configuration i wordpress.

  2. Thank you. This might come handy in other cases too… I made a Local AMPPS WordPress Install and for some reason first registrant got Subscriber rights instead of Admin. Really interesting. Anyways, PhpMyAdmin and fix of wp_usermeta -> wp_usercapabilities -> “a:1:{s:13:”administrator”;s:1:”1″;}” sorted it out.

  3. Hi, thanks for the info. I’ve only been able to login as a general ‘User’ using this method – I can’t see/access the Admin Dashboard. The site is a directory site that i migrated from a backup to a new domain. Any suggestions to get full admin privileges?

  4. I come here 2-3 times a year to get that nice set of SQL boilerplate. Should probably just save it to my notes at this point. Thanks so much!

  5. Thank you so much for this post! I had so many problems after migrating and changing the base url of my site and this post solved them all.

  6. I followed these steps and see my new account, but my site still will not allow me to log in. It says invalid user, then if I try resetting the password it says no account exists. What’s my next step to fix this?

    • You may want to ensure you added the user to the correct database, you should also be able to reach out to your hosting provider for them to take a look.


  7. 1. Please change the post to include information about table prefixes – a problem that appeared quite a few times in the comments and will keep you from succeeding if you just follow the post and have an alternative prefix.
    2. Thanks for the information presented here :-)

  8. For everyone who can login but not see the wp-admin, these instructions aren’t wholly correct.
    The wp_cabailities meta_value actually needs to be set as a:1:{s:13:”administrator”;b:1;}
    Otherwise your user doesn’t end up with a role set and you can’t see wp-admin.

  9. Hi. My WordPress website is being managed by a remote developer. He is an admin and so am I. We have a monthly agreement and I have every intention of paying him his dues. What measures can I do to make sure that I keep the access as well as my website should things go sideways? Can you please help me? Thanks in advance.

    • Create backups of your site and as long as you are the one paying for hosting you can restore the site


  10. Hi,
    Thanks for writing this! I see I am not the only one who was looking for instructions. My user was created, and I can click on the “Reset password” link and also get an e-mail from the system, but I am not able to log in. I saw that my “usermeta” table looks different from the other users’ – mine starts with “closedpostboxes_attachment”, not “first_name” etc. What might be the reason for that?

    • That table is for meta boxes that you have closed, the order you’re seeing the table shouldn’t cause an issue


  11. Hi!
    I did all the process but when I log in to the dashboard I only see the “Welcome to WordPress” section, I don’t see anything else in the admin area.

    Please, can you help me?

    • Your hosting provider may have customized their login area, there is normally an advanced section you can go to or reach out to your host and they should be able to assist :)


  12. I have a WP blog site which I have been locked out of. I created a new admin and can log in, but not to my dashboard. Instead, I go to my main blog page with my name and admin # at the top right and a logout button. How do I gain access to my admin/dashboard area?

  13. Hello,
    Well, this is embarrassing but… would anyone be able and kind enough to help me solve the father of problems? – wp_users table gone/missing… :(
    Thank you in advance.

    • You would want to reach out to your hosting provider if that table is not with your database to see if they have a backup of your database to restore.


  14. hi! thank you for your tutorials,
    i did all these steps and my issue still the same, when I want to login to my wp-admin, show me this message “Sorry, you are not allowed to access this page.” please if know how to fix this I will so thankful
    thank you

  15. After backing up my database with updraftPlus, then restoring it, we lost all admin access. I followed these instructions but am still getting an error saying I do not have access. Help!

  16. you are an absolute legend! after3 hours of trying useless suggestion from forums, you came up trumps, thank you!

  17. Thanks your information!
    But after inserting a admin accout, i can not login my site.
    Appear “Protection” button stop me to login WP dashboard.
    Please help me!

  18. Didn’t work, I’m getting the “Sorry, you are not allowed to access this page.” message. I checked my wp-config.php and the prefix is “wp_” but it still doesn’t work. Any ideas?

  19. Thank you very much. This article really helped me a lot, after my admin account was set to customer by a plugin I set to change user role from whatever to customer when they made a purchase.
    I never knew it will affect the admin role as well.

  20. is there a common reason why user can login but Dashboard is not made available? I see a lot of meta key values in the db

  21. Thank you sooooo much for this. Just this morning my wordpress site was hacked and I could not login into wp-admin. It was giving “user not found” error. I used this to fix things in my hostgator account.
    Very very grateful. Written instructions are excellent but the video could be slower with more details.

  22. Hi all,

    it didn’t work for me…

    an error message tell me that I can’t access to the dashboard

    !!HELP !!

    • It is simple mate.See what is written in you database name.
      Like in my case it was wprn_capabilities,wprn_user_level..

  23. I messed around with this more; watched the video several times and it’s still not working.

    In my case, I lost admin access after I migrated my WP site from one hosting account to another.

    my old admin login is able to login but once in, isn’t able to do anything.

    Using mysql, i tried creating a new user and adding the meta data. When I try to login with the new user, it says the password is incorrect. I tried saying “forgot password” and I did not receive any email to the email address i included when making the user with msql.

    In mysql i can see my old admin user is still there. I tried adding meta data to give admin privledges to that user, by putting in the corresponding userID. This didn’t change anything. I am still able to login with that user but don’t have access to anything. If anyone has any advice it would be much appreciated!

Leave a Reply to Phil Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.