By - - 1 Comment

If you have been struggling with your WordPress databases and backup, it is most probable that you would have faced the need to create an admin for WordPress through phpMyAdmin. Here is a step by step that will tell you how to add a WordPress admin using SQL via phpMyAdmin.

Step 1:

Navigate to phpMyAdmin from your cPanel. If using localhost, simply to to localhost/phpmyadmin. Make sure your Apache and MySQL are running.

phpmyadmin in cpanel

Step 2:

Select the database that you want to create an admin user for. For WordPress, most of the times it will be something like wp_dbname.

sql for wordpress in phpmyadmin

Step 3:

Now copy and paste the following code into the text area and click “Go”. Don’t forget to replace ‘YOUTDBNAME’ with name of the WordPress database. It must be similar to the one you clicked during step 2.

INSERT INTO `YOURDBNAME`.`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’), ‘Imran Hunzai’,
[email protected]’, ‘http://www.ihunzai.com/’, ‘2011-06-07 00:00:00′, ”, ‘0’,
‘Imran Hunzai’);
INSERT INTO `YOURDBNAME`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`,
`meta_value`) VALUES (NULL, ‘4’, ‘wp_capabilities’, ‘a:1:
{s:13:”administrator”;b:1;}’);
INSERT INTO `YOURDBNAME`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`,
`meta_value`) VALUES (NULL, ‘4’, ‘wp_user_level’, ’10’);

 

Once the server has process the query, you will be able to login to your WordPress Dashboard with the default admin privilege.

If you are unable to create an admin user with the given SQL code, make sure that there is no existing user with the same attributes. For example if there is already a user with user_login and/or ID same as the one you are entering, you would not be able to add a new user. in this case, you can manually remove the existing user.