Learn how to fix WP – Beginner’s Guide for WordPress

Learn How to Use MySQL to Add an Admin User to the WordPress Database

Learn How to Use MySQL to Add an Admin User to the WordPress Database

Has your WordPress website been blocked out?

Learn How to Use MySQL to Add an Admin User to the WordPress Database – Hackers may sometimes remove your admin account from the database, making it impossible for you to access your own site.

This post will show you how to use MySQL to create an admin account for the WordPress database, giving you back access.

Learn How to Use MySQL to Add an Admin User to the WordPress Database

Why Use MySQL to Add an Admin User to the WordPress Database?

A user’s website was once hacked, and the administrator account for that person was removed from the database. Without any additional input, this shut them out of their WordPress website.

By creating a new admin account directly on the WordPress website, we were able to assist them in gaining access to their website. phpMyAdmin, a web-based program that enables you to administer MySQL databases using your web browser, was used to do that.

You may use the same procedure whether hackers have locked you out of your WordPress admin area or you have just lost your password.

However, before making any MySQL updates, you must always create a backup of your database. Following that, you may need to use our beginner’s approach to repair your hacked WordPress site once you can log back into it.

Then, let’s look at how to add an admin account to the WordPress database using MySQL.

Using phpMyAdmin, one may add an admin user to the WordPress database.

PhpMyAdmin is usually included by default with the best WordPress hosting providers. It is in the Databases section of your hosting account’s cPanel dashboard.

An image of the Cpanel control panel is shown below:

comments closed cpanel phpmyadmin

The phpMyAdmin interface will appear when you click on the icon. Your WordPress database must be chosen in the left column.

phpMyAdmin will then show all of the tables in your WordPress database. The wp_users and wp_usermeta databases will be modified.

admin user php tables

in addition to the wp_users table.

The wp_users table must first be located and clicked. The users who are presently listed in the table will be shown.

You’ll see in the picture below that the table on our example website has two user IDs, 1 and 2. We’ll issue ID 3 to any new users we create for our test site.

Before you can create a new admin user, select the “Insert” tab at the top of the screen.

admin user wp users insert

Fill in the fields on the Insert form with the following details:

  1. ID: Choose a unique number (we’ll use 3 as an example).
  2. user_login: The user name that will be entered to log in with
  3. user_pass: Make sure to add a password and choose MD5 from the function menu (see the screenshot below).
  4. user_nicename: Full name or nickname of the user
  5. user_email: an individual’s email address
  6. user_url: your website’s URL
  7. user_registered: With the calendar, choose the day and time the user registered.
  8. user_activation_key: leave empty
  9. user_status: set this to 0
  10. display_name: complete name or display name of the user

admin user wp users add new user

Once you’re done, be sure to click the “Go” button so that the new user may be saved.

wp_usermeta table users’ addition

The next step is to locate and choose the wp_usermeta table. Then, like in the preceding step, you should click on the “Insert” tab.

The next step is to provide the following details in the insert form:

  1. unmeta_id: Leave this empty (it will be auto-generated)
  2. user_id: The user ID that you entered in the earlier step is
  3. meta_key: This must be wp_capabilities
  4. meta_value: insert this: a:1:{s:13:"administrator";s:1:"1";}

admin user wp user meta

After that, fields for a second row should appear as you scroll down. You must provide the following details:

  1. unmeta_id: Leave this empty (it will be auto-generated)
  2. user_id: the username you entered in the earlier stages.
  3. meta_key: You must go in wp_user_level
  4. meta_value: 10

admin user wp user meta

Now you must click the “Go” button once you have finished filling out all of the fields. You have successfully established a new admin username.

You should now be able to use the username and password you created for this user to get into the WordPress admin area.

Now you must go to Users. all users after logging in. Then click on the newly generated username.

admin user all users

Now scroll to the bottom of the page and press the “Save” button without making any changes.

By doing this, WordPress will be able to add some important information to the user you just set up.

Using a SQL query, adding an admin user to the WordPress database

If you are a developer, utilizing code will enable you to expedite the procedure.

Just insert the following SQL query into 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', 'demo', MD5('demo'), 'Your Name', 'test@example.com', 'http://www.example.com/', '2022-09-01 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, '3', 'wp_user_level', '10');

Make sure you replace “databasename” with the name of the database you are using. As we discussed in a first way, don’t forget to adjust the other settings to what you want for the new user.

admin user sql query

We trust that this guide has shown you how to use MySQL to add an admin user to the WordPress database. You can also look at our tutorial, “How to easily add custom CSS to any WordPress site“.

If you are still not able to fix this issue, then hire our expert WordPress developer to fix this issue.

Learn How to Use MySQL to Add an Admin User to the WordPress Database

Previous Post
Next Post