1. Home
  2. CMS
  3. WordPress
  4. How to Create an Admin Account in WordPress via MySQL

How to Create an Admin Account in WordPress via MySQL

How to Create an Admin Account in WordPress via MySQL
How to Create an Admin Account in WordPress via MySQL

When working with programs which require you to log in, you may find a situation where you get locked out of your account; this can happen with    WordPress among others.
Often, getting locked out can occur due to a code error, a hack, accidental admin account deletion, or a malicious site partner who changes information without your knowledge. If it happens, you may have to make a new admin account in order to regain access to the administration interface. This is done by interacting directly with the database and we will teach you how to do that in this article.

Creating a new admin account via MySQL

In the next tutorial, we will assume that your database table prefix is set to ‘wp_’. If you happen have something different, you will have to ensure that you adjust the code accordingly. For example: If you use ‘wptables_’ instead of ‘wp_’, then the code “INSERT INTO `wp_users`” will be “INSERT INTO `wptables_users`”.
To start, log into your cPanel interface.

Once at the main cPanel screen, navigate to the ‘Databases’ category and click on the icon entitled ‘phpMyAdmin’.

After the first screen appears, click on the database for your particular WordPress installation on the left-hand side. In the case that you don’t know which database is the correct one, you can find out by following these instructions.
Once the database information loads, find the tab called ‘SQL’ and click on it.
This should lead you to an SQL editor; in this, you have to enter a certain code before it will create a new admin account for you.
Here is the code you will need to create a new admin account named ‘newadmin’ with the password ‘pass123’. You may feel free to change any of the content below that is in red to fit your needs, leave the rest as is.

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
 VALUES ('demo', MD5('password324'), 'firstname lastname', 'email@example.com', '0');
 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');

After this, click on the ‘Go’ button to proceed with the insertion.
This will refresh the screen and present you with the message ‘1 row affected’ after each of the three SQL statements; this means that the insertion ran correctly. From here, visit your WordPress Admin Login area as normal and use the new admin login information.
You should now be able to get to the admin interface without a problem.

Updated on December 23, 2018

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']