While developing a blog or website on WordPress, it happens sometimes that I have been locked out of my WordPress Dashboard.
This could happen due to any code error, any accidental deletion of admin account or because of website malicious attack.
In such case, how can you create another new admin account if you are unable to login to your existing WordPress admin account?
Well, I have found an easy to handle method for such situation where you can create a new WordPress admin account and regain access to all administration interface.
You just need to add few lines of code in your MySQL database.
Relax! Do not worry, it’s too easy.
Below is a step by step guide to creating WordPress admin user via MySQL through cPanel. I have also written a complete guide on How to create a user in WordPress Dashboard.
Create WordPress Admin User
Note: It is important for you to understand the prefix of your WordPress Database Tables. Check in your MySQL database where your DB tables would be having such prefixes like “wp_” or “wptable_” etc.
The code that I am providing below should be adjusted as per your DB tables prefixes. For example, if your database tables are using “wptables_” prefix instead of “wp_”, then the code “INSERT INTO `wp_users`” would be “INSERT INTO `wptables_users`”.
Step 1: Login into your hosting cPanel and click on phpMyAdmin.
Step 2: Here you will see a list of your available databases. Click on the “+” symbol to expand your database tables and then hit your “wp_users” table. In my case, it is “wpzm_users“.
Step 3: Now, click on the top “SQL” tab and paste this code inside the query box.
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES (‘newadmin’, MD5(‘pass123’), ‘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’);
Step 4: Replace the following in order to create the admin account in WordPress successfully:
- Replace “newadmin” with your desired new username. Example “newadmin“.
- Replace “pass123” with your desired new secure password.
- Replace “wp_users” with your exact users table name. For example “wpzm_users” in my case. (For reference check snapshot in step 2)
- Hit the “Go” button at the bottom right corner. That’s all.
You have successfully created a new admin user for your WordPress website via cPanel. Your screen will refreshed for a second and a message will appear “1 row affected” after each three SQL statements.
This means that the insertion of your new SQL query ran successfully and now you can visit your WordPress login URL and try to login with your new admin account details.
Hope this was easy for you to create admin account in WordPress via cPanel.
I think these articles are useful too:
Top 8 useful plugins for WordPress blog
Monetize your WordPress blog with Google Adsense
Create a money making blog in few steps
Create a Contact form with WPForms plugin
14 best blogging platforms (@creativebloq.com)