fbpx

How Can I Add a User Through SQL

Adding a user through SQL involves two parts. First, adding a record into the WorPress users table and then second adding a record into the WordPress usermeta table.

The table prefix will likely be different for different WordPress installations. In the code snippets below wp_ is the table prefix, however for your installation it may be wp_sdf235_, so make sure you are updating references in the code below accordingly.

Insert Record Into WordPress Users Table

Make sure to replace wp_ with the table prefix used in your database.

INSERT INTO `wp_users` ( `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ( 'wplauncher_admin', MD5('password'), 'wplauncher', 'wplauncher@wplauncher.com', '', '2020-01-04 00:00:00', '', '0', 'wplauncher')

Make sure to save the user id after this SQL query is run as it will be used below. You can get the user id by running the query below:

SELECT ID FROM wp_users WHERE user_email = 'wplauncher@wplauncher.com';

Insert Record Into WordPress Usermeta Table

Make sure to replace the number 4 in the code snippet below with the user id that you get above. And, make sure to replace wp_ with the table prefix used in your database. The table prefix is present in wp_usermeta, wp_capabilities, wp_user_level.

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'), (NULL, '4', 'wp_user_level', '10')

Leave a Reply

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