How can I add a user through SQL?

This will create a new admin user called username with password: password in a database called DATABASE with table prefix wp_

Change the two accordingly to your own database name and table prefix.

Try this:

First create a row in wp_users. Replace DATABASE with your database name, username with your choosen username, password with your password of choice.

INSERT INTO `DATABASE`.`wp_users` (`ID`, `user_login`, `user_pass`, 
`user_nicename`, `user_email`, `user_url`, `user_registered`,
`user_activation_key`, `user_status`, `display_name`) VALUES ('9999', 
'username', MD5('password'), 'nickname', '[email protected]', '', 
'2014-11-04 00:00:00', '', '0', 'username');

Next insert two rows into wp_usermeta. Replace DATABASE with your database.

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

The key 9999 is a unique ID number so choose something that is not used.

Leave a Comment