How to Add Admin user in WordPress Database using MySQL

How to Add Admin user in Wordpress Database using MySQL

Many wordpress website get hacked and admin account gets deleted from the database and webmaster is unable to login on the wordpress website. All we can do is add new admin user using phpMyAdmin and grant all the admin access. In this article, we will guide you how to add admin user in wordpress database using MySQL.

Adding Admin user in WordPress Database using MySQL

Note 1: Always take the backup of the database or full website before performing any changes in database. So that, if thing goes wrong in database then you can restore it. In our previous article we had explained how to Backup WordPress Database using MySQL Command and how to backup wordpress database using phpMyAdmin

Note 2: Changes the database name and values before making any changes.


Firstly, login to your website hosting cpanel and click on phpMyAdmin from Databases


Now search for the website database from the list and click on wp_users table from list of the table. We will make the necessary changes in wp_users and wp_usermeta tables.


Now we will add all the admin information in the table, so click on insert tab as shown in above picture. Now fill the details in the column as mentioned below

  • ID – pick any number.
  • user_login – insert the username of the user, you want him/her to use it while login on the WordPress Dashboard.
  • user_pass – Add the password for the username. (Don’t forget to select MD5 in the functions option).
  • user_nicename – Enter the nickname for the user.
  • user_email – Add the user’s email id which you want to associate with this account.
  • user_url – URl will be to your website.
  • user_registered – Select the date/time for when this user is registered.
  • user_status – set this to 0.
  • display_name – Enter the display name for this user on the website.( You can add user_nicename value as well).

At last, click on Go button to save the changes.

Now we are going to add the entries in wp_usermeta table. Click on the wp_usermeta table from the list and click on the Insert tab same as mentioned previous step. Now add the following details in the insert form

  • unmeta_id – leave it blank (it is auto-generated)
  • user_id – It is the same ID created in previous step of wp_users
  • meta_key – this should be wp_capabilities
  • meta_value – insert this: a:1:{s:13:”administrator”;s:1:”1″;}

Insert another row with the following information:

  • unmeta_id – leave it blank (it is auto-generated)
  • user_id – It is the same ID created in previous step of wp_users
  • meta_key – this should be wp_user_level
  • meta_value – 10

Now click on Go button, in this way you had created yourself as new user with admin rights. Now you will be able to login on your wordpress website with the username and password mentioned in above steps.

After logged in website, click on users option available at admin dashboard. Now click on edit the username which you had created in above steps. Go down and save the form (NOTE: don’t make any changes). In this wordpress will go through and will add some more details and clean up the username we just added.


Below steps are only for developers or who are aware about the SQL queries. Just copy and run this SQL query in your database.

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’, ‘[email protected]’, ‘’, ‘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’);

Hope we had explained you well how to add Admin user in WordPress Database using MySQL. You can share this article with your friends and family members or you can also subscribe to our newsletter for latest update. You can join us on Twitter, Facebook and Google+