How to add an admin user to the WordPress database via MySQL

Published By: White Hunter

Published On: August 3, 2021

Published In: WordPress

Do you want to add an admin user to the WordPress database via MySQL? Here in this article, we will guide you to add an admin user using MySQL.

Sometimes you may lose admin access to your website and can’t log in to your WordPress website. When your WordPress locks you out then you won’t be able to access your website in the normal way. If your website is being hacked and remove your admin access then you need to create an admin user via MySQL to get access to your website.

How to add an admin user to the WordPress database via MySQL

Before doing anything using MySQL please make a backup of your website. There are many backup plugins available. Use any of the backup plugins so that if anything goes wrong you won’t lose your data.

Now in the first step login to your website PHPMyAdmin account. After login into PHPMyAdmin, find out your WordPress website database.

add an admin user to the WordPress database via MySQL

The interface may look different based on your hosting provider.

When you have access to your WordPress database search for the wp_users data table. From here you need to insert admin user information. So click on the insert button to add info.

add an admin user to the WordPress database via MySQL

You need to add the following info.

  • ID – Add a unique id for the user
  • user_login – Add a user name for the user
  • user_pass – Add a password
  • user_nicename – Add a nickname for the user
  • user_email –  Add user email
  • user_url – Add your website url
  • user_registered – Select user registration time
  • user_activation_key  –  Add an activation key for the user
  • user_status
  • display_name – Add a name to display for the user

After adding all the information properly click on the go button to save the info.

Now look for the wp_usermeta table and click on the insert option to add the following info.

  • unmeta_id – leave it blank, don’t need to add anything here
  • user_id – Add the same user id you just added in the wp_user table
  • meta_key – wp_capabilities
  • meta_value – add this value : a:1:{s:13:”administrator”;s:1:”1″;}

Again add another raw and add the following info

  • unmeta_id – leave it blank, don’t need to add anything here
  • user_id – Add the same user id you just added in the wp_user table
  • meta_key –  wp_user_level
  • meta_value – add 10 here

After adding these two rows click on the go button. It will create a new admin user with the following information you added.

SQL Query

If you don’t want to follow this long process then you can add an SQL command to create a new admin user. Add this SQL command to your database.

INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`)

VALUES ('3', 'example', MD5('esample'), 'Your Name', '[email protected]', 'http://www.example.com/', '2021-08-07 00:00:00', '', '0', 'Your Name');

INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '3', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');

Wrapping Up

Following the process, you will be able to add an admin user using MySQL. You can see our other articles to learn Why WordPress Breadcrumbs are important for SEO?

Best tools to run a website speed test

What new features are coming in WordPress 5.8?