Need to create a WordPress admin 'user' when you only have database (mysql) access?
Recently we had a client contact us because they couldn't access the dashboard of their WordPress site. Sometimes this happens because of lost credentials, database corruption, or maybe due to a website hack. In this case it was a simple case of lost credentials. The good news was that they still had their hosting & database credentials which allowed us to help them create a new administrative WordPress user. Below is a simple way to create a WordPress admin 'user' when you only have access to the database's mysql.
- Login to the site's database
- Click on the wp_users table (Prefix may be different based on preferences)
- Click Insert to add new user
- ID – Select a number that has not already been used for another user. You may need to reference the other users in this table.
- user_login – This will be the username that you will use to login to the dashboard
- user_pass – This will be the password you will use along with the above username to access the dashboard. Once you have inserted this make sure that you select the function MD5 as an encryption type otherwise this will not work
- user_nicename – This could be a nickname or another reference to the login username
- user_email – This is optional
- user_url – This is optional
- user_registered – This should be the date that you are adding the new user
- user_activation_key – Leave blank
- user_status – This needs to be '0'
- display_name – This will be the name that will be displayed on the dashboard after you are logged in
- Click 'Go' button to add the above to the wp_users table
- Click on the wp_usermeta table (Prefix may be different based on preferences)
- Click Insert to add new usermeta
- unmeta_id – This should be left blank
- user_id – This needs to be the ID number that you used in the wp_users table
- meta_key – This needs to be wp_capabilities
- meta_value – for an admin this needs to be:
a:1:{s:13:"administrator";s:1:"1";}
- Insert another row and add the following...
- unmeta_id – This should be left blank
- user_id – This needs to be the ID number that you used in the wp_user table
- meta_key – This needs to be wp_user_level
- meta_value – Make this 10
- Click 'Go' button to add the above to the wp_usermeta table
- Now you should be able to access the dashboard of your site with the username and password you provided above. Once you are able to access the dashboard make sure that you go to 'Users' and then find the new user that you just created. Click on that user and then save that user without making any changes. This will allow WordPress to fill in all of the remaining meta data usually automatically filled out when a new user is normally created in the dashboard.
Reference here