MySQL command to create an admin user in WordPress

Share this post to your friends !
  • 20

DanieBlog - 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', '', '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.
  • 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
MySQL command to create an admin user in WordPress.

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.

If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
  • 20
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.