How to create a new admin account in WordPress via mysql

February 1, 2023 / MySQL

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:

  1. Log in to cPanel:
    1. Access your cPanel account using your credentials.
    2. Navigate to the “Databases” section.
  2. Open phpMyAdmin:
    1. Click on the “phpMyAdmin” icon in the Databases section.database>phpmyadmin
    2. This will open the database management interface.
  3. Select the WordPress Database:
    1. In phpMyAdmin, locate the left-hand sidebar.
      phpmyadmin
    2. Click on the database associated with your WordPress installation.
  4. Open the SQL Tab:
    1. Once the database information loads, click on the SQL tab at the top.
      SQL
  5. Add a New Admin User:
    1. 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’);
    2. 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.
    3. Execute the Query:
      1. After making the necessary changes, click the Go button to execute the code.
        go
      2. If successful, you’ll see the message 1 row affected for each of the three SQL statements.
    4. Log in to WordPress:
      1. Visit your WordPress admin login page.
      2. Use the new admin username and password you created.
      3. You should now have full access to the WordPress admin panel.

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.

Spread the love