Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Last active August 16, 2023 18:00
Show Gist options
  • Save cesarmiquel/7299d1ce27b5ef9ac7cd4c20afb1a67b to your computer and use it in GitHub Desktop.
Save cesarmiquel/7299d1ce27b5ef9ac7cd4c20afb1a67b to your computer and use it in GitHub Desktop.
Restore uid = 1 (admin) in Drupal 9.x

Restore uid = 1 (admin user) in Drupal 9.x

I accidentally deleted the admin (uid = 1) user in Drupal 9.x. Here's how you can re-create it:

  1. Generate new user:
drush user:create admin  --password="qwerty" --mail="[email protected]"
drush user:role:add "administrator" admin
  1. Retrieve the UID of the user:
drush user:information admin
  1. Change the information in the database to using drush sqlc and executing the following commands (replacing XXX with the uid of the newly created user)
-- Change UID 184027 -> 1 in  users table
 
update users_field_data set uid = 1 where uid = XXX;
update users set uid = 1 where uid = XXX;
update users_data set uid = 1 where uid = XXX;

-- Change role
update user__roles set entity_id = 1 where entity_id = XXX;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment