Drupal - Adding a new user directly in database

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.


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.


You can also create users and assign roles with Drush, as well as change passwords for existing users.

Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.

Tags:

Database

Users

6