Generating a new administrator user in WordPress through SQL

If you need access to a website, built on WordPress, but you have SSH access only, you could still cope with the situation with a few line in the command line.

Here are the steps you need to follow:

  1. Find the database credentials. They are usually in wp-config.php file under the web-root directory of your WordPress based website.
  2. Connect to the database, using the credentials from the configuration file, using the following command
    mysql -u <username> -h <hostname> -p
  3.  Switch to your database:
    use <databasename>;
  4. Create your user:
    INSERT INTO `users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ( 'your-username', MD5('your-password'), 'Your Name', '', '2018-07-18 14:10:00', '', '0', 'Your Name');
  5. Check the id of the newly created user. Try to guess the right SELECT, and if you can’t, go standing face to the wall and repeat a hundred times “I should not mess with the database if I don’t understand basic SQL.”. Seriously.
  6. Make your user an administator with this:
    INSERT INTO `usermeta` (`user_id`, `meta_key`, `meta_value`) VALUES ( '<user_id>', 'capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

    Now you should be able to login with your username and password.


Leave a Reply

Your email address will not be published. Required fields are marked *