To create a new administrator user in WordPress from the database, you can follow these detailed steps. This method is useful when you don't have access to the WordPress admin panel but do have access to the database, either through the command line or tools like phpMyAdmin.
First, connect to the database server using the appropriate credentials. If you are in an environment with SSH access, the root command would be:
# mysql -u root
If you need remote access or are using a graphical tool like phpMyAdmin, make sure you have the correct user credentials and server address. You can use the credentials from WordPress's "wp-config.php" file.
Once connected to the database server, select the database used by your WordPress installation. Be sure to replace "database_name" with the actual name of your database:
use database_name;
You can verify which database WordPress uses by checking the "wp-config.php" file in your installation. Look for the line that says:
define('DB_NAME', 'database_name');
Also in the "wp-config.php" file, you'll find the table prefix. Look for the line that contains:
\$table_prefix = 'wp_';
This prefix is important because you need to use it instead of the default value ("wp_") in the following SQL queries.
To insert a new user into the wp_users table:
INSERT INTO wp_users (user_login, user_pass, user_nicename, user_email, user_registered, user_status, display_name)
VALUES ('clouding', MD5('password_changeme'), 'clouding', 'changeme@clouding.io', NOW(), 0, 'clouding');
In this example, the username for logging in will be "new_admin" with an encrypted password (in this case, using MD5). You can replace the INSERT data to customize the user.
Next, retrieve the ID of the newly created user:
SELECT ID FROM wp_users WHERE user_login = 'clouding';
Example result:
+-----+
| ID |
+-----+
| 331 |
+-----+
1 row in set (0.000 sec)
Finally, assign administrator privileges to the user in the "wp_usermeta" table, remembering to replace ID with the corresponding user ID:
INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES (331, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}'), (331, 'wp_user_level', '10');
The new user with administrator permissions will now be created, and you can log in with:
Username: clouding
Password: password_changeme
Note: It is important to change the password after logging in or assign a strong password during user creation.
We hope this tutorial has helped you 🙂. Remember, if you have any questions about this or other issues related to your servers at Clouding, don't hesitate to write to soporte@clouding.io We are here to help you with anything you need!