WordPress

Create fast a new WordPress admin user in the database (3 Methods)

watchLast Updated:

bookmarkWritten by: Yakovos Frountas

    Sometimes you have to take an alternative step to gain access to your WordPress dashboard. Probably you are unable to receive a password reset email, or you lost your password. There are two options to regain access to your WordPress account.
    [toc]

    • Submit our Free Quote form and one of our experts can do it for you for a fee.
    • Follow the instructions in the article below and do it yourself. You need to have cPanel access.

    WordPress Premium Support

    How to create a new WordPress admin user in the database

    Our support experts can perform the following services for you for a fee:

    • Reset your WordPress password
    • Update a user’s email address in the WordPress database
    • Create a new WordPress admin user
    • Delete old or unused users
    • Replace a missing wp_users table

    1. Create a new WordPress admin user in the database

    Use this method to create a new WordPress admin user if your previous user role was admin too.

    1. Log into phpMyAdmin
    2. Click the _users table
    3. Click the Insert tab
    4. Fill in the following fields.
      • ID is any number you choose
      • user_login is the username for accessing the WordPress Dashboard.
      • user_pass is the password for the user. Make sure to select MD5 in the functions menu
      • user_nicename is the nickname for the user
      • user_email is the email address you want to associate with this user
      • user_registered is the date and time for when this user is registered
      • user_status should be set to 0
      • display_name is the name that will be displayed for this user on your site
    5. Click the Go button
    6. Click the _usermeta table
    7. Click the Insert tab
    8. Fill in the following fields:
      • user_id is the ID you entered in the previous step
      • meta_key should be the phrase wp_capabilities
      • meta_value should be
        a:1:{s:13:"administrator";s:1:"1";}
    9. Click Go
    10. Click the Insert tab again
    11. Enter the following information:
      • user_id is the same number you entered in the previous step
      • meta_key should be the phrase wp_user_level
      • meta_value should be the number 10
    12. Click the Go button.

    Now you are able to log in with your new WordPress admin user.

    Video with the steps

    YouTube video

    Important Note

    You have to rename wp_capabilities and wp_user_level with your database table prefix. In my case for the video was tested_ so the above will be renamed to test_capabilities and test_user_level. In any other case, you will not be able to log in to your WordPress site.

    2. Add a WordPress Admin User to the Database via PHP

    As a developer, you will occasionally need to create a new administrative user in the database to gain access to the site. Typically, this is necessary when you are provided with an export of a WordPress database, but you aren’t provided with the login credentials for the admin user.

    Sure, you can gain access via the database. However, many developers aren’t very comfortable with MySQL and the process is pretty slow compared to what I’m about to show you. Here’s all you need to do:

    • Create an mu-plugins/ directory in your site’s wp-content/ directory.
    • Create a new file in the wp-content/mu-plugins/ directory you created and name it anything you want. Something like create-admin-user.php would work nicely.
    • Copy this code snippet and paste it into the file you just created:
    <?php
    
    add_action( 'init', function () {
      
    	$username = 'admin';
    	$password = 'password';
    	$email_address = 'webmaster@mydomain.com';
    
    	if ( ! username_exists( $username ) ) {
    		$user_id = wp_create_user( $username, $password, $email_address );
    		$user = new WP_User( $user_id );
    		$user->set_role( 'administrator' );
    	}
    	
    } );
    • Edit the username, password and email address.
    • Login to the site using the information you just edited.
    • Once you have logged in, delete the file.

    3. Create WordPress Admin user with WP-CLI

    If you are familiar with super tool WP-CLI then you can create an admin straight from your console in just a single line.

    wp user create bob bob@mail.com --role=administrator

    Leave a Comment

    Ready to get started?

    Contact us today to learn how our customized plans can help grow your business.