A guide for creating wordpress administrator user directly from mysql database without logging into a wordpress admin.
Creating a User Directly from the Database
-
SSH into the site’s host server.
-
Type
$ su
to enable super user access, then type the super user’s root password. - Enter the mysql shell, and use the project’s database:
1 2 3
$ mysql mysql> SHOW DATABASES; # to check the project's database name mysql> USE <project_database>; # do not forget the semicolon
- Show the database tables to determine the table prefix. The default will be “wp_”
1
mysql> SHOW TABLES;
- Insert your user information through the command:
1
mysql> INSERT INTO <table_prefix>_users (user_login, user_pass, user_email, user_registered, user_status) VALUES ('<your_username>', '<your_password>', '<your_email>', '<date_time_today>', 0);
The date time today format should be: yyyy-mm-dd hh:mm:ss
- Search for your username in the Users tables, and take a note of your ID. Then, add your user meta data.
1 2
mysql> SELECT * FROM <table_prefix>_users; mysql> INSERT INTO <table_prefix>_usermeta (user_id, meta_key, meta_value) VALUES ('<your_user_id>', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
-
Use online tools for wordpress password hashers (such as: https://www.useotools.com/wordpress-password-hash-generator) to generate a hash for your password.
- Copy the hashed password, and run the command:
1
mysql> UPDATE `<table_prefix>_users` SET `user_pass` = '<your_password_hash>' WHERE user_login = '<your_username>';