#Article #Project #Snippets
1 mins reading time

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', 'admin@example.com', '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.

#Article #Project #Snippets

Join the newsletter.

I'm kind of experimenting with this whole "building a mailing list" thing.
I mean, I heard it's a good practice, so why not give it a shot?
If you're up for it, feel free to drop your email address and who knows, you might possibly receive an update from me someday. Maybe. Or maybe not.
But hey, there's only one way to find out, right?