Sometimes, you may feel the necessity of creating a new administrator account or an admin user via MySQL database if you loose access to the admin user or for some other reasons. Here I will describe a step by step method to create an admin user directly via MySQL from cPanel.
Step by Step Method to Create New WordPress Administrator via MySQL:
Step 1: Access Your MySQL Database
- Log into your cPanel/Control panel
- Go to “Database” section
- Click on PHPMyAdmin icon
Step 2: Go to the wp_users table
- Select your WordPress database from the list of databases in PhpMyAdmin
- Go to the wp_users table and click on the “insert” link
Step 3: Insert a New Record in the Users Table
You will need to fill in the following fields to insert a new user record:
- ID – Keep the value of this field empty (it will automatically assign the correct value for it)
- user_login – insert the username you want to use
- user_pass – add a password for the account. Select MD5 in the functions menu (Refer to the screenshot below).
- user_nicename – leave this field empty for now
- user_email – add the email address you want to use for this account.
- user_url – leave this field empty for now
- user_registered – select the date/time for when this user is registered.
- user_status – set this to 0.
- display_name – leave this field empty for now
- Click on the Go Button (you should see a success message)
You can go back to the wp_users table and browser the entries to verify that the user record has been inserted correctly.
Step 4: Insert User Meta Values
- This is the final step where we will assign some user meta values to the user account we just created.
- Go to the “wp_usermeta” table and click on the “insert” link:
- Use the following values and click the “Go” button to insert the usermeta data
- umeta_id – Leave it blank (it will be generated for you)
- user_id – This is the ID of the user we created in the previous step. In my case, it is 10.
- meta_key – Use: wp_capabilities (This is very important step: You must change it according to table_prefix. i.e, if your table_prefix is “bp_” instead “wp_” then you must use “bp_capabilities” instead of “wp_capabilities”.)
- meta_value – Use the following value for this field:
Almost done! You can now log into your WP site using this newly created WP User account. You can use this account to change the password of your other user accounts or delete them (if you want to).
Final Step (Important):
Though you now have an active administrator account, but you must update your nicename or just click on “Update Profile” from WordPress Backend. It gives you some additional permissions. Otherwise, you may face some errors. I hope you have successfully created a new administrator account or admin user. But if you are facing any problem please email me at zubaer[at]wordpressinsights[dot]com.