How to Add an Admin User to the WordPress Database via MySQL
Are you searching for a way to add an Admin User to the WordPress Database via MySQL? This post will share, How to Add an Admin User to the WordPress Database via MySQL.
If you can not access your wp-admin area for reasons such as your site being hacked, you forgot your password, your site displaying some error, or are locked out of your site. Don’t worry! There’s another way to gain access to your site.
You can make a new WordPress admin user by editing your site’s database.
Creating a new WordPress admin user with phpMyAdmin
You can make a new WordPress admin user by following the steps below:
- Access your MySQL database
- visit the wp_users table
- Insert a new WordPress admin user in the user’s table
- Insert user meta values
Note: Before doing anything, You must create a backup of your database.
Let’s get started!
Step 1: Access your MySQL database
To start, you have to access your hosting c-panel and then locate your WordPress database section to edit it. Then click on the phpMyAdmin option provided there.
Step 2: Visit the wp_users table.
After that, search for the wp_users and click it. We have to edit the wp_users and wp_usermeta tables.
Step 3: Insert a new WordPress admin user
Now, click the insert option in the wp_users table to insert our new admin user’s information.
Next, you will see the insert form. you have to add the following details:
- ID – select any number like (3,4,5). We will use 3 for now.
- user_login – Enter the username you like to use to access the wp-admin Dashboard.
- user_pass – enter a password for this username and select MD5 in the functions menu next to it ( see our example ).
- user_nicename – pick a nickname you would like to refer yourself as, or you can leave it for now.
- user_email – Enter the email you want to link with this account.
- user_url – enter your website’s URL.
- user_registered – Enter the date/time when this admin user is created.
- user_status – Fix this value to 0.
- display_name – Enter the name you would like to display for this user on the site.
After filling in the details, scroll to the bottom and click the Go tab.
Step 4: Insert user meta values
In the next step, we have to edit the wp_usermeta table.
Now, Click on the wp_usermeta table and click on the Insert button again. Next, you will see the insert form. you have to add the following details:
- unmeta_id – leave this empty
- user_id – This will be the id of the user you created in the last step. Recall we used 3.
- meta_key – Enter wp_capabilities
- meta_value – insert this: a:1:{s:13:”administrator”;s:1:”1″;}
Now, Insert another row with the following details:
- unmeta_id – leave this blank
- user_id – this will be the user id, enter 3 ( we used in the last step)
- meta_key – enter wp_user_level
- meta_value – 10
After that, click on the ‘Go’ tab, and you have successfully created a new username. Now you will be able to login to your wp-admin with the username and password you enter for this user.
Extra tip: SQL query
You can copy the following code and drop this SQL query in your database if you want to speed up this process.
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', 'test@yourdomain.com', 'http://www.test.com/', '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');
Note: Remember to change the database name to your database name. Also, don’t forget to change the values.
To conclude: There can be many reasons why you can’t log in to your WordPress admin dashboard using the correct details. Maybe your admin user is deleted by the hackers, or you forgot your login details. In that case, you have to create a new admin user using MySQL. We hope this write-up helped you to add an Admin User to the WordPress Database via MySQL.
If you are experiencing any other error on your site, you can fix it by following the steps told in our other article on what to do when you are logged out of the WordPress admin area.