Few days ago, we ran into an issue where a user’s site got hacked and their admin account was deleted from the database. This locked them out of their site without any other entry. We went in to the phpMyAdmin and created a new admin user to grant them access. In this article, we will show you a step by step guide on how to create an admin user in WordPress Database via MySQL.
Note: You should always make a backup of your database before performing any MySQL edits. This tutorial requires basic understanding of how phpMyAdmin works.
First, you need to login to phpMyAdmin and locate your WordPress database. (Below is a screenshot of a HostGator cPanel)
cPanel phpMyAdminhttp://cdn4.wpbeginner.com/blogposts/wpusersinsert.gif
Once you are in, we will be making changes to the wp_users and wp_usermeta tables. Lets go ahead and click on wp_users table.
phpMyAdmin wp_users table
We need to insert our new admin user’s information, so click on the Insert tab like it shows in the image above. In the insert form, add the following:
ID – pick a number (in our example, we will use the number 4).
user_login – insert the username you want to use to access the WordPress Dashboard.
user_pass – add a password for this username. Make sure to select MD5 in the functions menu (Refer to the screenshot below).
user_nicename – put a nickname or something else that you would like to refer yourself as.
user_email – add the email you want to associate with this account.
user_url – this would be the url to your website.
user_registered – select the date/time for when this user is registered.
user_status – set this to 0.
display_name – put the name you like to display for this user on the site (it can be your user_nicename value as well).
Click on the Go Button
phpMyAdmin Insert values in wp_users table
Next we are going to have to add the values to wp_usermeta table. Click on the wp_usermeta table and then click on the Insert tab just like the previous step. Then add the following information to the insert form:
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. Remember we picked 4.
meta_key – this should be wp_capabilities
meta_value – insert this: a:1:{s:13:”administrator”;s:1:”1″;}
Insert another row with the following information:
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. Remember we picked 4.
meta_key – this should be wp_user_level
meta_value – 10
Then click on the Go button, and you have created yourself a new username. Now you should be able to login to your wp-admin with the username and password you specified for this user. Once logged in, click on Users and edit the username you just created. Go down and click on the Save button (you don’t have to change anything). This will allow WordPress to go through and add some more information and clean-up the user we just added.
SQL query
For developers who want to speed this process up, you can simply drop this SQL query in your database.
in soldoni:
2
3
4
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, ‘4’, ‘wp_capabilities’, ‘a:1:{s:13:”administrator”;s:1:”1″;}’);
5
6
7
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, ‘4’, ‘wp_user_level’, ’10’);
dove databasename va sostituito con il nome del vostro DB.
attenzione a NON razzare un utente con stesso ID (in questo caso 4)
Remember to change the databasename to the database you are working with. Also don’t forget to change the appropriate values.
[via http://www.wpbeginner.com/]