Adding a WordPress admin user directly through the database can be useful if you’ve lost access to your WordPress admin area. You can accomplish this by using phpMyAdmin, a popular tool for managing MySQL databases. Follow these steps to add a WordPress admin user via phpMyAdmin:
- Access phpMyAdmin: Log into your web hosting control panel (such as cPanel, Plesk, or DirectAdmin) and open phpMyAdmin.
- Select Your WordPress Database: Once in phpMyAdmin, you’ll see a list of databases on the left-hand side. Select the database that your WordPress site uses. If you’re unsure which one it is, you can find the database name in the
wp-config.php
file of your WordPress installation. - Open the wp_users Table: Inside your WordPress database, look for the
wp_users
table. The prefixwp_
might be different if you or your hosting provider changed it during WordPress installation for security reasons. Click on the table name to open it. - Insert a New User: Click on the “Insert” tab at the top of the
wp_users
table page. You will need to fill in the following fields:
user_login
: The username for logging into the WordPress admin area.user_pass
: The password. Use the MD5 function in the dropdown to encrypt your password.user_nicename
: A nicer version of the username (can be the same asuser_login
).user_email
: The user’s email address.user_registered
: The date and time when this user is registered. You can use the current date and time.user_status
: Set this to 0.display_name
: The name that will be displayed for this user on the site.
- Add User Meta: After creating the user, you need to give this user administrative rights. Go to the
wp_usermeta
table and insert two new records for your new user:
- For the first record:
user_id
: The ID of the user you just created in thewp_users
table.meta_key
: This should bewp_capabilities
.meta_value
: Inserta:1:{s:13:"administrator";b:1;}
to grant administrator rights.
- For the second record:
user_id
: Again, the ID of the new user.meta_key
: This should bewp_user_level
.meta_value
: Set this to 10 to grant the highest level of access.
- Finish: After inserting these records, you can log into your WordPress admin area using the new username and password.
Remember, directly editing the database can be risky. Always backup your database before making any changes. This way, if anything goes wrong, you can restore your site to its previous state.