Perlat Kociaj

Web Developer

Create WordPress admin account via SQL command

There might be a time where you might bee locked out of your admin account because you either forgot the password and and reseting the is not an option because you no longer have access to that email. Or the website has been hacked and you have to create an admin account.

The only option is to create a user via the MySQL. But remembering the long sql query is difficult.

An exaple query would be like the following example:

Create User account

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`,`user_registered`)
VALUES ('admin', MD5('changeme'), 'Mr Admin', '', '0','2019-12-27');

Add user permissions

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');

That is the reason I created WPAdmin (I know it is an original name) a tool to help that will generate the SQL query for you.