How to Add an Admin User to WordPress Database via MySQL?


To add an admin user to WordPress database via MySQL, you can follow these steps:

Method 1: Using phpMyAdmin

  • Log in to your hosting account and open phpMyAdmin.
  • Select the WordPress database from the left-hand side menu.
  • Click on the SQL tab at the top of the page.
  • Enter the following SQL query:
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('newadmin', MD5('password'), 'firstname lastname', '[email protected]', '0');

Note: Replace wp_ with your WordPress database prefix, and change the values for newadmin, password, firstname lastname, and [email protected] to your desired values.

  • Click on the Go button to execute the query.
  • Note the ID number of the newly created user from the ID column in the wp_users table.
  • Enter the following SQL query to add the user to the wp_usermeta table:
INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES (ID, 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

Note: Replace ID with the ID number of the newly created user.

  • Click on the Go button to execute the query.
  • Enter the following SQL query to add the user to the wp_usermeta table again:
INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES (ID, 'wp_user_level', '10');

Note: Replace ID with the ID number of the newly created user.

  • Click on the Go button to execute the query.
  • You can now log in to your WordPress site with the new admin user credentials.

Method 2: Using MySQL Command Line

  • Log in to your hosting account and open the command line interface.
  • Connect to your MySQL database using the following command:
mysql -u username -p

Note: Replace username with your MySQL username.

  • Enter your MySQL password when prompted.
  • Select the WordPress database using the following command:
use database_name;

Note: Replace database_name with your WordPress database name.

  • Enter the following SQL query to add the new admin user:
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('newadmin', MD5('password'), 'firstname lastname', '[email protected]', '0');

Note: Replace wp_ with your WordPress database prefix, and change the values for newadmin, password, firstname lastname, and [email protected] to your desired values.

  • Enter the following SQL query to get the ID number of the newly created user:
SELECT ID FROM `wp_users` WHERE `user_login` = 'newadmin';

Note: Replace newadmin with the username of the newly created user.

  • Note the ID number of the newly created user from the ID column in the output.
  • Enter the following SQL query to add the user to the wp_usermeta table:
INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES (ID, 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

Note: Replace ID with the ID number of the newly created user.

  • Enter the following SQL query to add the user to the wp_usermeta table again:
INSERT INTO `wp_usermeta` (`user_id`, `meta_key`, `meta_value`)
VALUES (ID, 'wp_user_level', '10');

Note: Replace ID with the ID number of the newly created user.

  • You can now log in to your WordPress site with the new admin user credentials.


About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.