How to Create a New WordPress Admin User in the Database

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

There are legitimate reasons why you might need to create a new wordpress admin via the database.  Suppose you were hired to work on a client WordPress site.  The client do not want to give out their WordPress admin password (because it is probably the same password they use for their bank account or something).  As long as you have webhost access to cPanel, you can create a new wordpress admin user to work on the site.  Remember to delete this user after you are done.

The instructions that follows are for WordPress 3.5 and the table names and field names shown are not prefixed with the database prefix (because yours will be different).  But you know what I mean.

1.  Using phpMyAdmin go into the users table of the database.  You can find the database name, database user, and database user password from wp-config.php at the wordpress root.

2. Create a new record in the _users table

insert-new-admin

Leave the ID value blank, the database will fill that in for you.

Enter user_login and user_email of your choosing.  Let user_nicename and display_name be same as user_login.

Enter password for user_pass as the straight password.  But choose the MD5 function (as shown above).  phpMyAdmin will encrypt your password using MD5 hash for you.  Leave the rest of the fields blank.

If you are using database browser (such as SQLBuddy) which don’t have the MD5 function, you can input the value: $P$BHBocs/wnpWmJeQvknw5ASsng5I4iw/

This corresponds to the hash of the value “ChangeMe”.   Remember after logging in with the password “ChangeMe”, that you change the password.

Click “go” to create new record.

Browse the table and note what ID was assigned to this new admin user.

3.  Next you have to give this new admin user administrator privileges.  You do that by creating a new records in usermeta table.  An admin created by wordpress will have 16 records in this table that looks like the following with values for meta_key column and meta_value columns …

admin-meta-data1

You may want to create each of these new records for the new admin user.  But as of the time of this writing, you can get by with just creating the nickname, wp_capabilities, and wp_user_level

The user_id column should be the id noted when you created the new admin in the previous table.  And the nickname should match the username created for the new admin in the previous steps.  Note that the wp_capabilities, wp_user_level, and others values have the database prefix that may be different from yours.   Leave the umeta_id column blank when creating the new records as they will be autoincremented.  If you don’t want to add all these, at the minimum, you have to add wp_capabilities and wp_user_level in order for it to work.

4.  You should now be able to login with the new admin.

5.  When done using the admin user, delete the admin by deleting those same records that you had created.  Because you can not delete yourself via the User Manager in the dashboard.