Creating an admin user through MySQL

Steps to create an admin user account without access to a site:

  1. Login to the cPanel server for the type of site you need to add a user for, e.g. B&B/HiL, VR, for Demo.
  2. If adding a user to a site on the B&B/HiL or VR servers select the site account from the drop down in the upper right. If adding a user to a demo account skip this step.
  3. Select the “phpMyAdmin” menu item.
  4. Select the database that corresponds to the site you are adding to and then select the `wp_users` table inside of the database.
  5. Check that a user with the desired username doesn’t already exist. If it does either remove it or use a different username for your account depending on whether the existing account is needed.
  6. Select the “SQL” tab at the top of the page (should be the third tab from the left).
  7. Click inside the editor box and clear out any existing content.
  8. Paste the following code into the text area:
    SET @UserName = 'USERNAME_HERE';
    SET @UserEmail = 'EMAIL_HERE';
    SET @UserPass = 'PASSWORD HERE';
    SET @RegTime = NOW();
    
    INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `display_name`, `user_registered`)
    VALUES (@UserName, MD5(@UserPass), @UserName, @UserEmail, '0', @UserName, @RegTime);
    
    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'rich_editing', 'true');
    
    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'syntax_highlighting', 'true');
    
    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'nickname', @UserName);
    
    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users),
    'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
    
    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
  9. Update the @UserName, @UserEmail, and @UserPass with the appropriate values. Make sure to keep the quotation marks surrounding the value.
  10. Record the user name and password values in your password manager for later user.
  11. Press the “Go” button at the bottom right.

You should now be able to go to the login page with either DOMAIN/wp-login.php or DOMAIN/wp-admin and use the credentials you set up to login.

Leave a Reply