Manually add a user to your WordPress Database

Posted by Andrei on October 25, 2013 in WordPress

Normally you should never need to do this unless you have somehow removed your Admin user from your WordPress database, usually you will need to just reset your Admin user’s password if you cannot login. But if you ever do need to re-add an Admin user to WordPress through phpMyAdmin this is how you would do it.

The first thing you will need is access to the database so you will need to log into your websites cPanel control panel, then navigate to phpMyAdmin and locate the database for the WordPress installation. If you have forgotten the username, password, or even the name of the database you can find these details in your wp-config.php file which is in the root of your WordPress install.

This information is found between lines 18 and 26 of the wp-config.php file, they will look like this:

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘cpuser_yourwpdb’);
/** MySQL database username */
define(‘DB_USER’, ‘cpuser_yourdbuser’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘yourpassword’);

Select your database from the database select menu in phpMyAdmin. Your database will be loaded and you will now see a list of your database tables. You will need to change the wp_users and the wp_usermeta table. Click on the wp_users table to bring up the data for that table. You should see a list of the current users come up – or if you do not have any users you will see the list of database fields available.

 

Editing the wp_users table

We will need to insert a row into the database with our admin users’ information. Click on the “Insert” tab in order to bring up the phpMyAdmin insert form. Insert the following information:

 

  1. user_login – this is the username you want to use to access WordPress
  2. user_pass – this is the password you want to use to access WordPress (be sure to select MD5 from the phpMyAdmin Function menu – WordPress stores passwords with MD5 encryption)
  3. user_nicename – put whatever you would like to refer to yourself as in here (not your username)
  4. user_email – this is the email account associated with this user
  5. user_url – the url to your website
  6. user_registered – when was this user registered – just select a date with the date selector
  7. user_activation_key – you can leave this blank
  8. user_status – leave this set to 0
  9. display_name – usually this is set this to whatever the user_nicename is

 

Now that you have that information entered you will need to hit the “Go” button at the bottom of the phpMyAdmin window. You should be redirected to a page that shows the results of your query, if there are no errors then continue with editing the wp_usermeta table.

 

Editing the wp_usermeta table

So now that we have inserted our user, we will need to give it the privileges that it needs to access the WordPress Admin section. This is done through the wp_usermeta table. You will need to know the id of the user you just created. If you don’t know the id now would be a good time to check the wp_users table for it. We will need to insert two rows into the wp_usermeta table, wp_capabilities and wp_user_level.

 

Here are the steps you will need to follow to give your user privileges:

 

  1. Click on the wp_usermeta table to bring up the entries.
  2. Click on the “Insert” tab to insert a new row.
  3. Fill in the following information
    1. umeta_id – leave this blank it is automatically generated
    2. user_id – this is the id of the user you created in the previous steps
    3. meta_key – for this step insert wp_capabilities
    4. meta_value – insert exactly this – a:1:{s:13:”administrator”;b:1;}
  4. Insert another row with this information
    1. umeta_id – leave this blank it is automatically generated
    2. user_id – this is the id of the user you created in the previous steps
    3. meta_key – for this step insert wp_user_level
    4. meta_value – insert 10
  5. Click the “Go” button in phpMyAdmin to insert the row.

Now you should be able to login to your wp-admin page with the username and password you specified for this user. After logged in I would visit the Users section within WordPress, click edit on the user I just added, and click the Update Profile button at the bottom of the screen. This will allow WordPress to go through and add some more information and “clean up” the user we just added.

Tags :  ,  ,  ,