Have you ever been banned from your WordPress site? Since anything can happen and you get locked out of your page, below we will see how you can add a user (administrator) to the WordPress database via MySQL so that you can regain your access.

One possible lockout scenario is a hacker deleting your admin account from the database, and another is you forgetting your password.
Of course, before we start, we should mention once again the importance of having them
backups of your database. If there are, with a restore the problem is temporarily solved for the first scenario.
I mention temporarily because in the event of an attack you should find the security gap.
How to add an admin to your WordPress database via MySQL
phpMyAdmin is a web tool and allows you to manage MySQL databases using your browser.
So if you are locked out of the WordPress admin panel for any reason, follow the steps below:
simply run the 3 commands in the SQL context of your database as you see it through the phpMyAdmin tool

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@iguru.gr','https://iguru.gr/','2022-09-11 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 change it databasename
with the name of the database you are messing with. Also, don't forget to change all other VALUES to the ones you want for the new user.
Also check if the tables prefix (wp_) is different in your database. If it is you should change it.
In the above code they are marked in yellow.
