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

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

PRO WordPress Developers:

If you are writing SQL directly, here are the queries to the database you can use . make sure to review the correct ID and update (currently set to 11 below)

				
					INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('11', 'admin', MD5('passwordyouwanttouse'), 'admin', 'email@domain.net', '', '2015-03-26 02:04:06', '', '0', 'admin');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '11', 'wp_capabilities', 'a:1:{s:13:\"administrator\";s:1:\"1\";}');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '11', 'wp_user_level', '10');
				
			

1. Access the database

Access to your database is typically provided by your web host. if you are using a control panel, look for MySQL or PHPMyAdmin.

Once in your database, you will see a list of your database tables, the two we will edit are wp_users and wp_usermeta. Start by clicking on the wp_users table.

2. Edit the wp_users Table

USER ID: In your wp_users table, you most likely will already have users. We need to review the current users so we can add a unique new user. Look at the ID column, and take note of which ID numbers are already used, our new user will have to use a different ID. In the case of the screenshot below, user IDs 3,4 and 5 are in use. So we can safely use ID 1 or 2 or 6,7,8…

INSERT NEW USER: We need to insert our new admin user’s information.

Click on the Insert tab as it shows in the image above, then in the insert form, add the following:

  • ID: insert any unused ID not currently used, we will use 1
  • user_login: insert any unused username you want to use to access the WordPress Dashboard, we will use the username admin (NOTE: admin is NOT recommended as a user because many hackers will try and use this username to brute force a login, in our case since we will be using a very long password, we have less a concern for type of attack).
  • user_pass: add a password for this user. Make sure to select MD5 in the functions menu (Refer to the screenshot below).
  • user_nicename: pick any nicename you want, we will use the same as our user_login.
  • user_email: enter in the email address of this user.
  • user_url: we will leave this blank, feel free to enter any url you want here.
  • user_registered: use the date/time picker to set a datetime.
  • user_status: set this to 0.
  • display_name: we make this the same as the user_login.

Click on the Go Button

If you did everything correctly you new user should be added to the wp_users table.

3. Edit the wp_usermeta Table

We are now going to add the values to our wp_usermeta table. Click on the wp_usermeta table and then click on the Insert tab just like you did in the previous step. Then add two new rows of data to the table, using the following information in the insert form:

  • unmeta_id: leave this blank, as the field will be auto-generated.
  • user_id: insert the same ID you used when creating your new user (previous step). For us that will be id 1.
  • meta_key: this should be wp_capabilities
  • meta_value: insert this: a:1:{s:13:"administrator";s:1:"1";}

Click on the Go Button

  • unmeta_id: leave this blank (it will be auto-generated)
  • user_id: this will be the id of the user you created in the previous step.
  • meta_key: this should be wp_user_level
  • meta_value: 10


Click on the Go Button