Skip to content

Instantly share code, notes, and snippets.

@rrdial
Last active June 17, 2021 18:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrdial/2479053e0669f9a15d4298d0d626b0d2 to your computer and use it in GitHub Desktop.
Save rrdial/2479053e0669f9a15d4298d0d626b0d2 to your computer and use it in GitHub Desktop.
Create WordPress admin user directly in the database
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment