Tag Archives: mysql

How to Add a WordPress Administrator to the Database using SQL Queries

Manually Add a WordPress User with Administrator Role to the MySQL Database using SQL Quries or phpMyAdmin

In a recent WordPress hack attack which we worked on and recovered, the owner’s WordPress administrator account was demoted to a user role, therefore the owner did not have any control over the WordPress installation. To regain back access to WordPress, we manually created a new WordPress user with an Administrator role directly in the database.

In this tutorial we will show you how to manually create a WordPress administrator in the WordPress database by using any  MySQL command line (SQL queries).

Create a WordPress User using SQL Queries

Or as frequently referred to, MySQL Command Line

If you have access to your MySQL database server via command line, you can use the below SQL queries to create a new WordPress administrator in the database.

1 INSERT INTO `wordpressdatabase`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `display_name`) VALUES ('1000', 'tempuser', MD5('Str0ngPa55!'), 'tempuser', 'support@yoursite.com', '0', 'Temp User');

 

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

 

1 INSERT INTO ` wordpressdatabase`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '1000', 'wp_user_level', '10');

The above SQL SQL queries will create a new WordPress administrators with the following details:

Before using the above MySQL queries do not forget to:

  • change the wordpressdatabase to the WordPress database you are working with
  • change the default table prefix (wp_) if the WordPress database you are working with have non default prefixes
  • change the user Id to a bigger number if you have created more than 1000 WordPress users (If you do not specify a user ID it will be automatically generated. Then retrieve the record using an SELECT SQL statement).

Once the above SQL queries are executed, you can login to your WordPress blog or website with the newly created WordPress administrator account.