MySQL command to create an admin user in Wordpress

by Daniel Pham
Published: Updated:

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

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.
mysql command to create an admin user in wordpress
MySQL command to create an admin user in Wordpress.

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';


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

0 0 votes
Article Rating

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.