If you need to create a new admin account in WordPress but cannot access the dashboard, you can achieve this through MySQL.
Note: These instructions assume your WordPress database table prefix is set to “wp_”. If you use a custom prefix like “wpsqltable_”, adjust the code accordingly. For example, replace “INSERT INTO ‘wp_users’” with “INSERT INTO wpsqltable_users.”
Follow the steps below:
- Log in to cPanel:
- Access your cPanel account using your credentials.
- Navigate to the “Databases” section.
- Open phpMyAdmin:
- Click on the “phpMyAdmin” icon in the Databases section.
- This will open the database management interface.
- Click on the “phpMyAdmin” icon in the Databases section.
- Select the WordPress Database:
- In phpMyAdmin, locate the left-hand sidebar.
- Click on the database associated with your WordPress installation.
- In phpMyAdmin, locate the left-hand sidebar.
- Open the SQL Tab:
- Once the database information loads, click on the SQL tab at the top.
- Once the database information loads, click on the SQL tab at the top.
- Add a New Admin User:
- In the SQL editor, enter the following code to create a new admin account:
INSERT INTO ‘wp_users’ (‘ID’, ‘user_login’, ‘user_pass’, ‘user_nicename’, ‘user_email’, ‘user_status’, ‘display_name’) VALUES (‘1000’, ‘newadmin’, MD5(‘pass_abc’), ‘New Admin’, ‘[email protected]’, ‘0’, ‘New Admin’); INSERT INTO ‘wp_usermeta’ (‘umeta_id’, ‘user_id’, ‘meta_key’, ‘meta_value’) VALUES (NULL, ‘1000’, ‘wp_capabilities’, “‘a:1:{s:13: “administrator”;b:1;}’); INSERT INTO ‘wp_usermeta’ (‘umeta_id’, ‘user_id’, ‘meta_key’, ‘meta_value’) VALUES (NULL, ‘1000’, ‘wp_user_level’, ‘10’);
- Replace the following fields as needed:
- newadmin: Set your desired username.
- pass_abc: Set a secure password.
- [email protected]: Replace with the admin’s email address.
- Execute the Query:
- After making the necessary changes, click the Go button to execute the code.
- If successful, you’ll see the message 1 row affected for each of the three SQL statements.
- After making the necessary changes, click the Go button to execute the code.
- Log in to WordPress:
- Visit your WordPress admin login page.
- Use the new admin username and password you created.
- You should now have full access to the WordPress admin panel.
- In the SQL editor, enter the following code to create a new admin account:
By following these steps, you can quickly restore admin access to your WordPress site through MySQL. Ensure you delete or secure old admin accounts that are no longer needed for improved security.