When you are working to the WordPress site and sometimes you need to create an Admin user directly from the Database by using the phpMyAdmin.
Please follow the following steps to create an Admin user directly from the database using PhpMyAdmin. Here, I am assuming you are login to your hosting cPanel.
First of all, locate the name of the database associated with your website. If you know, that’s great but if you don’t, please follow the following steps:
Go to cPanel > Files section > File Manager:
From your website root directory, find the file “wp-config.php” and click on the “View” link.
Search for the line like define(‘DB_NAME‘,'<YOUR DATABSE NAME>’). This is important to know the database you want to add a user.
Now, as we know the database name, let’s find the phpMyAdmin from your Cpanel which generally listed under database tools.
Once phpMyAdmin is opened, select the site database and find the table “wp_users” and click on it.
Once the “wp_users” table shows the users’ data to the right side of the panel, click on “Insert” from the top tab and fill the data as per the below image.
Now, the new user is added to the table. Click on the “Browse” button and sort the first column “Id” by descending order to get the id of the recently added user (i.e. 21)
Now, go to table list and click on “wp_usermeta”
Click on the “Insert” tab and fill the following data:
user_id — 21 (The id of the user we recently added from the above step)
meta_key – wp_capabilities
meta_value — a:1:{s:13:”administrator”;b:1;}
Again, click on “Insert” and fill the following data:
user_id – 21 (The id of the user we recently added from the above step)
meta_key – wp_user_level
meta_value – 10
That’s it. You did it. Now, you should be able to access the site with your new Admin user. If you face any issues recheck all the above-mentioned steps are done exactly as described.
Note: If you have a custom database prefix, make sure you’ve done all the above steps in the respective custom prefix table names.
If you are a developer and want to speed the process, you can simply use the following SQL query to the site database:
1 2 3 | 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 ('21', 'newuser', MD5('userpassowrd'), 'User Name', '[email protected]', '', '2020-05-23 00:00:00', '', '0', 'Display Name'); INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '21', '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, '21', 'wp_user_level', '10'); |
Thanks for your blog, nice to read. Do not stop.