Pages Navigation Menu

Add new Admin User for WordPress directly in database

If you have no access to “/wp-admin” area of your WordPress:

  1. Connect to the database

    • PHPMyAdmin


    • console:
      mysql -uUSER -pPASS -hmysql DB;
  2. Copy the following code and modify the appropriate fields
    INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`) VALUES ('<username>', MD5('<password>'), '<full_name>', '<email_address>', '0');SET @newUserId = LAST_INSERT_ID();INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, @newUserId, 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'),(NULL, @newUserId, 'wp_user_level', '10');

    You may need to change the prefix for the database tables
  3. If the site is a multi-site, you will also need to make yourself a super-admin
    1. Run the following SQL to locate the current list of super-admin users
      SELECT * FROM `wp_sitemeta` WHERE `meta_key`='site_admins'
    2. This will return a serialized php array, so you will need to add yourself into this list
    3. Modify the string to add yourself. This consists of incrementing the ‘a’ count, and defining a new string at the end. Note: ‘1’ gets incremented, and the ‘s’ value should be the length of your username (don’t forget the trailing ‘;’ after your username)
    4. Execute the following query with your updated string
      UPDATE `wp_sitemeta` SET `meta_value`='<value-from-c>' WHERE `meta_key`='site_admins'
    5. The easiest way to add yourself to be an admin to the remaining sites is to use the network-admin sites panel.

Leave a Reply