• Skip to primary navigation
  • Skip to main content
  • Skip to footer

WPJohnny

WordPress Performance Guides and Reviews

  • Start a WordPress site
  • Hosting
  • Themes
  • Plugins
  • Blogging
  • Marketing

Get WordPress admin access through database

WordPress hosting May 29, 2019 by Johnny 5 Comments

Ever needed to hack your way into a WordPress through the database?

Sometimes it happens that you lock ourselves out of the WordPress admin dashboard because you either made changes unexpectedly or lost access somehow due to some other issue. I’ll show you how to get admin access by editing admin users in the database, or creating a new admin user in the database.

Follow this simple guide…

To edit your database, you can use any database administration tool. Most webhosts have phpMyAdmin or one that works similarly. You can also use adminer, which is a single file that you can upload via FTP to your website root folder.

METHOD #1 – change password for existing user (EASY)

This method gains access by editing the password for an existing admin user.

  1. From phpMyAdmin or whichever database administration tool, scroll down to the “wp_users” table. (It might have another prefix, like “123vw_users”.)
  2. Click “edit” on a user that you know has admin access.
  3. For the “user_pass” column, select “MD5” for varchar type, and then enter in the desired password in the “Value” field.
  4. If you see anything in the “Value” box next to the “user_activation_key” column, delete it.
  5. Click [GO].

You should be able to log in using that username or email, and then the password you entered.

If you have too many users and can’t find (or don’t know) the admin ones, you can search for them below using this SQL command. (You can run it by clicking the [SQL] tab in your MySQL administration tool.)

SELECT u.ID, u.user_login, u.user_nicename, u.user_email
FROM wp_users u
INNER JOIN wp_usermeta m ON m.user_id = u.ID
WHERE m.meta_key = 'wp_capabilities'
AND m.meta_value LIKE '%administrator%'
ORDER BY u.user_registered
  • If your database uses a custom prefix, make sure you replace all the “wp_” with your prefix.
  • After you run this SQL command, it’ll show you the admin users. Then you can go back to the users table, sort by name or email, and edit one of them to gain access.

METHOD #2 – create new user (takes 5 minutes)

This method gains access by adding a new admin user.

Open up phpMyAdmin or whichever MySQL administration tool you have, click “SQL” and paste the code below. Make sure you change the name, username, mail and password which you need to create for the new user…they are marked in BOLD.

Also, if your database is not using the default WordPress prefix _wp, make sure you also change the prefix of of the database tables wp_users, wp_usermeta, wp_capabilities and wp_user_level to the one your website is using. So if your website is using the table prefix wpstg0_ the new table name for wp_capablities is wpstg0_capabilities.

Enter this code below…

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`,
`user_status`)
VALUES ('username', MD5('password123'), 'John Doe', '[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');

Click “GO” after you enter it with your specified changes. After executing the function you will be able to access your WordPress dashboard again with that new user credentials.

METHOD #3 – give admin permissions to existing user (10 seconds)

  • Go into phpmyadmin and look in the _usermeta table.
  • Scroll to the user you want to alter permissions for.
  • Look for the _capabilities meta_key and change the meta_value to a:1:{s:13:"administrator";s:1:"1";}.

Share this post:

Share on FacebookShare on X (Twitter)Share on LinkedInShare on WhatsAppShare on EmailShare on SMS

Read all my posts on WordPress hosting Popular

About Johnny

Right on the edge of WordPress development! 10+ years of WordPress design, development, hosting, speed optimization, product advisor, marketing, monetization. I do all that.

More WordPress Guides

How to Write an Interesting Story

Best WordPress Hosting Reviews (UPDATED 2025)

Not a fan of Pinegrow for creating WordPress themes

The MONSTER GUIDE to WordPress Image Optimization

How to pick a good MEMBERSHIP platform

Best WordPress Plugins – UPDATED 2025

Reader Interactions

5 Comments

  1. geo

    May 30, 2019 at 10:14 am

    Indeed – this is a nice one. Had to use it the other day 🙂

    Reply
  2. Alan

    June 24, 2019 at 11:01 am

    You can also create a user with just code, useful if for some reason you only have lets say FTP access.

    e.g. https://gist.github.com/alanef/08ad974f07110323244ad20317aa4fa3

    Reply
    • Johnny

      June 25, 2019 at 2:41 am

      I love it, Alan. Thank you for this! Do you mind if I make a separate post sharing this code and giving credit to you? Let me know where you’d like to link to directly. Perhaps the code page and also your own personal/professional work link?

      Reply
  3. Scott Dayman

    October 10, 2020 at 5:04 pm

    I’ve had to do this before…and then realized it’s so much easier to us WP-CLI. You’ve only mentioned WP-CLI a few times, but I use it *so much* for admin tasks. Its built in syntax help always makes it easy for me to stumble my way through any task, including password changes, role changes, and user creation.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

More links

  • Gadget reviews
  • Try my free WPJ plugins
  • Join the WPJ FB Group
  • WPJ YouTube & newsletter
  • Become a WPJ Affiliate

Popular Reviews

  • Best WordPress Hosting
  • Best WordPress Themes
  • Best WordPress Plugins
  • Best WordPress Cache Plugins

Services

  • Speed optimization
  • Speed optimization courses
  • WordPress hosting
  • Hire me or other experts
  • Client login

About Johnny

10+ years of WordPress design, development, hosting, speed optimization, marketing.
Contact me.

newsletter block

Copyright 2025 | WordPress guides by Johnny Nguyen

Click to Copy