How to add an Admin User to a WordPress database
If you have lost access to your WordPress site and cannot reset the password (e.g. the site has been hacked and the admin user has been deleted), you can still create a new admin user via the database.
To prevent your website from being hacked in the future, read our recommendations on how to improve the security of a WordPress site.
This article shows you how to add an admin user to the WordPress database using MySQL, which will allow you to regain access.
Note: Before you make any changes to your database, we strongly recommend making a backup first.
- Step 1 - Open your database in PhpMyAdmin
- Step 2 - Add a user to the _users table
- Step 3 - Add a user to the _usermeta table
- Step 4 - Confirm new user in WP Admin
Step 1 - Open your database in PhpMyAdmin
- Log in to your one.com Control Panel and click PHP & database settings under Advanced settings.
- Select your WordPress database in PhpMyAdmin and open the database.
- If the table content list in the left-hand menu is not open, you can click the plus symbol next to the database name to open it.
- Select the table that ends on _users, for example, wp_users.
Tip: If you have more than one WordPress installation on your web space, you need to ensure you are accessing the right table. You can verify this by looking up the table prefix in wp-config.php. If in doubt, you can always contact our support.
Step 2 - Add a user to the _users table
- Click on the table that ends on _users (f.e. wp_users) to view the current list of users.
- Click the Insert tab at the top of the screen to insert the information for a new admin user.
- To complete the Insert form, add the following information:
- ID: pick a unique number (in our example, we’ll use 2)
- user_login: the username that will be used when logging in
- user_pass: add a password, and make sure to select MD5 in the function menu (see the screenshot below)
- user_nicename: the user’s full name or nickname
- user_email: the user’s email address
- user_url: your website address
- user_registered: select the date and time the user was registered using the calendar
- user_activation_key: leave blank
- user_status: set this to 0
- display_name: public name that is displayed
- Click Go on the bottom right to save the new user.
Step 3 - Add a user to the _usermeta table
The next step is to add the appropriate permissions to the user.
- Look for the table that ends on _usermeta (f.e. wp_usermeta) in the menu on the left and click it.
- Click on the Insert tab as you did in the previous step.
- Add the following information to the Insert form:
- umeta_id: leave this blank (it will be auto-generated)
- user_id: add the same user ID you used in the previous step
- meta_key: insert your table prefix_capabilities (in our example this would be wp_capabilities)
-
meta_value: copy and insert this value:
a:1:{s:13:"administrator";s:1:"1";}
- Next, scroll down to find fields for a second row and add this information:
- umeta_id: leave this blank (it will be auto-generated)
- user_id: the user ID you used in the previous steps
- meta_key: enter wp_user_level
- meta_value: 10
- Click Go on the bottom right to save.
Step 4 - Confirm the new user in WP Admin
With the username and password you specified for this user, you should now be able to log in to your WordPress admin. You can access the login page of your WordPress installation by adding /wp-admin at the end of your URL, for example: one-example.net/wp-admin
- Log in to WP Admin with the newly created user account.
- After you logged in, you need to navigate to Users > All Users.
- Click on the username you just created.
- Newly created users should be edited and saved once - no data needs to be changed. Scroll to the bottom of the page and click Update Profile.
When you do this, WordPress will clean up the user you just created and add some extra information that is needed. - Done!
Note: If your site was hacked and you've now regained access to your WP Admin, continue with this guide: How do I repair a hacked WordPress site?
Related articles: