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:
- Find the database credentials. They are usually in wp-config.php file under the web-root directory of your WordPress based website.
- Connect to the database, using the credentials from the configuration file, using the following command
1mysql –u <username> –h <hostname> –p - Switch to your database:
1use <databasename>; - Create your user:
1INSERT 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’, ‘your@email.com’, ‘2018-07-18 14:10:00’, ”, ‘0’, ‘Your Name’); - 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.
- Make your user an administator with this:
1INSERT 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.