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 a lot, Yes I got my problem solved and this was due to the the role assigned to my user name. Cheers

  2. Really very simple and clear guide to how to create a user through MYSQL WordPress database, thank you.

  3. Thank you so much for this. Just had a client that locked herself out of her site and I was able to get her back in with these instructions.

  4. I’ve used this on my websites. Works like a charm…very easy to follow!

    Thank you for this amazing time saver technique.

  5. I have changed my admin access to editor because i was trying to change role capabilities to edit gravity forms. Suddenly i no longer see edit cornerstone or have access!! HELP!

  6. I don’t now if it is an update to WordPress data structure, but I’ve just encounter a site in which I’ve had to enter the wp_options meta_key values as:

    [table_prefix]capabilities instead of wp_capabilities
    [table_prefix]user_level instead of wp_user_level

    I leave this here as it might be of help.

    • You sir are awesome!

      I guess it uses the database prefix but in case the site has been moved, or someone changed the prefix from “wp_” to something else, capabilities and user_level should be changed accordingly.

    • Thanks, this comment helped a lot.

      I had to double-check and get the exact table_prefix value from our wp-config.php file. Ours meta_key values were correct except for capitalization. I believe some hosting companies with single-click wordpress installs will set their own table_prefixes, so be sure to check for that as well.

  7. I’ve used this on three different websites so far. Works like a charm!

    Thank you for this amazing time saver.

  8. It looks like there’s been a database change in the most recent version of WP, so this post may need to be updated.

    I’s been an awesome resource, thank you!

    • I can’t verify this with previous versions of WordPress, but I just tested this with the latest version of WordPress, and it worked fine for me. Can anyone also confirm if this was a fluke?

  9. I have done same sql quires to make admin user. User created and logged but showing Sorry, you are not allowed to access this page error. Please help me about this.

  10. THANK YOU SO MUCH! I had an issue with WooCommerce Product Vendors, where I have applied as a vendor while logged in as admin. From that point on I couldn’t log in and I was receiving a message”You will be notified once your account has been approved” O_o

    Previously I had to re-install WP because of this!!! Now I found your post and it was such a help!!! Thank you so much for sharing this :) x

  11. Didn’t work at all for me. I get a “ERROR: Incorrect username or password.”

    Yeah yeah, I’ve check it. Password and user are correct.

    So what now? I used to have admin access but now only have a lower basic level that doesn’t show the user settings.

  12. Awesome….saved me tons of hardship like for other issues. I saw that for some reason all the administrators in my site became something else…


    The guys who discussed about wp_prefixes…..perfect….

    Ah !!!

  13. For me it is a great helpful post. I have modified this SQL script and re-animated my door to the administrator entry of my wordpress homepage. Thanks.
    Werner Ullrich

  14. Okay this YouTube video is much enhanced than last one, this one has pleasant picture feature as well as audio.

  15. I wanted to change several “Nicename” entries to other values than that user’s Login ID. From within PhpMyAdmin, I exported the “wp_users” table.

    Then I made the necessary changes in my code editor.

    Then after saving a backup of the original users table and the entire database, I “Import”ed just the “wp_users” table back into the database using PhpMyAdmin.

    Worked fine for me.

  16. I followed this and was able to login but cannot go to the dashboard. I get this error: You do not have sufficient permissions to access this page.

      • I had the same problem but in wp_usermeta where we are told to write:
        meta_value – insert this: a:1:{s:13:”administrator”;s:1:”1″;}

        I changed the value to:

        and it worked. I found this value in the corresponding value further up in the table for the original administrator account. Check your table and see if there are any other previous administrators, and copy the same value (just in case it differs to my value).

    • For this to work with the latest WordPress 4.4.2 I had to update the meta_key names because my WordPress install was using a table prefix of wp_brnq_ instead of the typical wp_ prefix.

  17. Thank you for this! It saved me from an errant plugin that over-wrote my admin record in the users table!

  18. I am currently fixing the website of my mom for her own company and I am a kind of wordpress-dummy. I couldn’t properly log in because she sent me the wrong password. After three failed attempts it said I should look in the data. Message: ‘Username or password are not correct. Please check your data.’
    I followed these steps here and I followed all of these steps very precisely, but still, with my new username and password, I am unable to log in. My prefix was different than wp_ what this article stated, so I changed the prefix as well – but can’t come through. Now I am locked out until tomorrow.

    What happened, can someone maybe help me / explain me what I did wrong and how can I fix this. I really promised my mom to build her website, and it needs to be updated really soon! :(

  19. you were doing a great job of step by step until you got to

    “meta_key – this should be wp_capabilities”

    What does “should be” mean in this context? Does it mean that it should already say that that in that field, perhaps generated from something prior? If is not there what is required?

    There’s a drop down field to the right of meta_key. That file name “wp_capabilities” does not exist as a selection. There’s a blank field to the right of that. Do I paste wp_capabilities into it? Is there a value of that name somewhere that I should be putting in that field?

    And I see more trouble ahead. You say “insert another row.”

    I take the word insert as a verb. Where and how do I do that? I am already on the Insert page. There is nothing on it says “Insert new row.”

    Looking further down – all the way at thre bottom – skipping over the next section (which I an told to do) I see a field that says “Insert as a new row.”

    But “insert a new row” and being told to go to a field that contains the phrase “Inert as a new row” are not all the same thing.

    and there is a checked box that says “ignore” right above it. What’s the point of going further if that box is still checked ignore – and is “insert a new row” the same as “insert a new row?”

    And I see the same “should be” confusion ahead again in the next set of instructions.

    But I’m stuck back the first “should” because I am literal minded. Please clarify?

    • Hi Joe,

      “meta_key – this should be wp_capabilities” means that the meta_key value (the textbox in phpmyadmin) should be wp_capabilities

      When he refers to inserting a new row, you can do so by clicking insert from the navigation at the top of phpmyadmin this tutorial assumes you have already done the first insert and are on the browse tab.

  20. I had a multiple site setup. After doing this I can access both sites, however I have no Network Admin capability and not Plugin management… Under “My Sites” I see my two sites, but no “Network” option. On the vertical menu area for my site I seem to have everything other than “Plugins.”

    Seems I do not have Administration over my WP Network for multiple sites?

  21. This worked for me with the following modification: the wp_capabilities value had to be taken from another admin users row because it had additional permissions or whatever those are. copy the values in that case from an existing user if necessary

  22. If you’ve gone through all of the steps and you’re STILL getting the “You do not have sufficient permissions to access this page” error message when trying to log in…

    I had to replace the first example meta_key (wp_capabilities) with my own prefix: change wp_capabilities to whateveryourprefixis_capabilities

    Same with the second meta_key example (wp_user_level). I changed it to my specific prefix: change wp_user_level to whateveryourprefixis_user_level

  23. Such a helpful article. Perfectly done, easy to understand. Thanks for the time you spent putting it together. :)

  24. for those who still got the You do not have sufficient permissions to access this page.
    you might want to check that the wp_capabilities adn stuff follows your db prefix name..
    like if your normally wp_usersmeta has blab787_usersmeta the wp_capabilities will be blab787_capabilities etc.

  25. Fantastic walk-through. This is spot on with multiple versions of phpmyadmin so ignore the differences in the screenshots. Thanks for the write-up!


  26. Same here, in September 2015 I get “You do not have sufficient permissions to access this page.” error after using the SQL code provided. Which is strange, since this article is only 6 months old!

  27. I followed your instructions to the letter but something went wrong (don’t know what) and now I don’t have access to my website. I get the message: database error.
    Can I undo the changes I made? Please help.

  28. all I had to do was revert the meta data back to admin and it worked great. Thanks for the article.

  29. Hello, I dug a little deeper into the problem and found that existing entries in the “usermeta” table had a prefix that was unique to my site. My wordpress tables all begin with ar_, and once I edited those 2 rows to reflect that, my login was complete, with all priveleges.



  30. Hello, and thank you for the above write-up on this subject. I have been locked out of my local site (XAMPP) and other articles I have read deal with changing the existing admin user password using phpMyAdmin. I did not have success with those methods.

    I followed your instructions above and the login screen did accept the credentials.

    Unfortunately I was redirected to domain//wp-admin/profile.php and the phrase “You do not have sufficient permissions to access this page”.

    From the front end of the site, I can see I am logged in but when I click on Dashboard, the same phrase appears.

    Do you have any suggestions that would allow me access?

    Thanks in advance,


  31. Hi, tried the fix by following it to the “T” yet when I try logging in: url/wp-admin takes me to a url/25/ page as before. Wonder what I did wrong. Please advice. Thanks in advance.

Leave a Reply to blainesch 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.