Adding a new user directly in database

I've been given the files to a Drupal site so I can create a new theme. I haven't, however, been given the Drupal admin user/password date so I can't sign in to the admin area. Is there a way I can create a new user directly in the database or some other way?

asked Sep 6, 2011 at 4:50 1,805 2 2 gold badges 25 25 silver badges 45 45 bronze badges

7 Answers 7

You can create a new user by added a row to the users table. The password field must contain an MD5 hashed password. You can use online MD5 generators or, if you are using PHPMyAdmin, select the MD5 function next to the textbox where you enter your plain password. Take note of the user id (uid) of your newly created user. After that, you need to find a role that has sufficient permissions in the role table. Find the role id (rid) and enter the uid and rid in a new row in the users_roles table.

If there is no role that gives administrator access, because the client does everything with user 1, you need to perform a slightly dirtier trick. Save the password hash of user 1 somewhere and temporarily add a new password for user 1. Then log in with user 1, create a new account for yourself, a new role with sufficient permissions and add yourself to that role. After that, edit user 1 in the database and restore the password. I can recommend admin role to force a role to have all permissions at all times.

answered Sep 6, 2011 at 5:38 Jorrit Schippers Jorrit Schippers 623 5 5 silver badges 10 10 bronze badges

There's a much easier way.

  1. Go into the DB and change the email address field of the user with id 1 and set it to your email address.
  2. Go to http://mysite/user and click on the password recovery link.
  3. Enter your email address and you'll get a password recovery link.

Of course this assumes that your dev systems allows drupal to send mails out of the box. This is true for most linux and osx boxes but not for Windows.

answered Jun 26, 2012 at 11:26 5,378 22 22 silver badges 32 32 bronze badges

This is really easier. Once done this, the OP can create a new user, and set back the email for the user #1 as it was before, if it is really necessary.