This article will show you how to use the mysql command to create an admin user in Wordpress.
I have worked with a lot of Wordpress websites. There are times when I receive some websites without the administrator account information.
But while setting up the website on the system (mostly related to SSL), I need to login to the website to update the URL.
Mysql command to create an admin user
Table of Contents
There are 2 tables in Wordpress database that we need to add records. That is the table wp_users
and wp_usermeta
.
First, you use the following command to create new admin account information.
INSERT INTO `database_name`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('2', 'youruser', MD5('yourpass'), 'Admin', '[email protected]', 'NULL', '2019-03-20 00:00:00', '', '0', 'Admin Test');
You change some information that suits you.
- database_name: database name of your website.
- wp_ (in wp_users): database table prefix.
- 2: the ID you set for this user. If you have a duplicate ID, you can change the number for example 10 or 100 so that it doesn’t overlap.
- youruser: change to your username.
- yourpass: change to your password, just type as plain text.
- Admin: this is user nicename, you can change it after login the website.
- [email protected]: set email address for this account.
- 2019-03-20 00:00:00: replace with your current time.
- Admin Test: this is display name of this account in Wordpress, you can set it to any word you like.
Recommended Reading: How to add rel nofollow to WordPress menu
Then, use this command to grant administrator permissions to the user just created above.
INSERT INTO `database_name`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `database_name`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_user_level', '10');
In the above two commands, you just need to change the ID (number 2
) to match the ID number you set above.
Note:change number 2
matches the ID number when you create an account.
Now that you have created a new administrator user in the Wordpress website, you can now try login.
Mysql command to delete user administrator
For example, after you’ve finished using the admin account, have the ID (2)
just created above.
Now you want to delete that account.
Warning: Be careful when deleting accounts in Wordpress. If the account owns some posts, it may be deleted.
You use the following 2 commands to delete the admin user.
DELETE FROM wp_users WHERE ID = '2';
DELETE FROM wp_usermeta WHERE user_id = '2';
Conclusion
The article showed you how to use the mysql command to add and delete the user administrator in the Wordpress website. When working directly on the database, you need to be very careful. Look closely at the command before executing it.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).