Create admin user in WordPress

Create admin user in WordPress

WordPress is not my favorite. But it is useful. If you get locked out, or find yourself in charge of a new site with no one to grant you access, creating a new admin user directly in the database is surprisingly easy. I created this script to make it easy to get setup on new sites that I need to manage.

START TRANSACTION;
SET @user_login = 'ryandial';
SET @user_nicename = 'Ryan Dial';
SET @user_email = 'ryan@example.com';
INSERT INTO `wp_users` (`user_login`,
`user_pass`,
`user_nicename`,
`user_email`,
`user_url`,
`user_registered`,
`user_activation_key`,
`user_status`,
`display_name`)
VALUES (@user_login,
MD5(uuid()),
@user_nicename,
@user_email,
'',
now(),
'',
'0',
@user_nicename);
SET @user_id = (SELECT `ID` FROM `wp_users` WHERE `user_login` = @user_login);
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, @user_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, @user_id, 'wp_user_level', '10');
COMMIT;
view raw create.sql hosted with ❤ by GitHub
Comments are closed.