1

My WordPress site got hacked and the WP Admin user account password was changed by the hacker. This essentially locked the user out of his admin dashboard. It is best (for situations like this) to just create a new admin user account to gain access to WP admin dashboard and fix things as needed.

Is it possible to create a new WordPress admin user account via MySQL database (without having access to your WordPress admin dashboard).

N.B: I am site owner and I have access to cPanel/Control Panel of my server.

5
  • why don't you change current pass with wp_users table? Commented Feb 15, 2017 at 16:54
  • I already changed the current password but it's not working. That's why I want to create another one as an administrator role
    – Faisal
    Commented Feb 15, 2017 at 16:57
  • why not working? did you encrypted your pass? or just simply changed it like admin123? Commented Feb 15, 2017 at 16:58
  • yes password encrypted using md5
    – Faisal
    Commented Feb 15, 2017 at 16:59
  • If WordPress is still running properly, you could add a new user with wp_insert_user, rather than doing it directly via the database. The reason your hashing is not working is that WordPress adds a salt to it before it hashes (see codex.wordpress.org/Function_Reference/wp_hash_password).
    – engelen
    Commented Feb 15, 2017 at 20:47

2 Answers 2

4

You need to run those below queries-

INSERT INTO `your-wp-database`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `display_name`) VALUES ('1000', 'your_username', MD5('Str0ngPa55!'), 'your_username', '[email protected]', '0', 'User Display Name');

INSERT INTO `your-wp-database`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '1000', 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');

INSERT INTO `your-wp-database`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '1000', 'wp_user_level', '10');

But notice here your-wp-database is the name of your WordPress database, 1000 is your newly created user's ID, [email protected] is the user email, the your_username is your user's username, User Display Name is your newly created user's display name and lastly Str0ngPa55! is the password of your newly created user.

1
  • Nice its working fine
    – Faisal
    Commented Feb 17, 2017 at 14:21
0

Add an Admin User to the WordPress Database via MySQL

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..)

First, you need to login to phpMyAdmin and locate your WordPress database. phpmyadmin

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.

insert_user

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.

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.

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

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.

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.