How to add a WordPress user directly to the database

- by

wordpress-iconSometimes you may want to add a new user to your WordPress site without accessing the admin interface. Here’s how we do that.

We need the following ingredients:

  • MySQL access details (host, username, password, database name – you can extract this from wp-config.php)
  • phpMyAdmin (or equivalent database management tool, such as Sequel Pro)

Let’s get started!

wp_users

The first thing we need to do is insert a new row into the wp_users table of your database. You should see a list of existing users with some funky looking hash values next to them, a bit lille this:

Screen Shot 2013-11-12 at 10.10.45

The next screen will let you enter values for each column. We don’t need all of them, just the following:

  • user_login (the new username, such as “newuser” – so spaces or funky characters)
  • user_pass (the password for said user; once selected, pick MD5 from the very long drop down)
  • user_registered (pick a date from the date picker, such as today)

You don’t need to set the ID as it will be created automatically. No other values are necessary here, they will be blank when you later have a look at this user’s profile in WordPress where you can add them at your own leisure.

Once inserted, take a look at the numeric user ID the database has given your new user. Mine is 3, but yours will be different. Remember it before moving on to the next step.

Screen Shot 2013-11-12 at 10.22.57

wp_usermeta

Next we need to add two rows to the wp_usermeta table. Select it and hit insert. Here’s what to enter the first time round:

  • user_id (the numeric user ID of what you’ve just created)
  • meta_key (needs to be “wp_capabilities”)
  • meta_value (needs to be exactly “a:1:{s:13:”administrator”;b:1;}”)

For the second row, repeat the above with the following values:

  • user_id (same user ID as above, from the user you created earlier)
  • meta_key (needs to be exactly “wp_user_level”)
  • meta_value (needs to be 10)

Leave the umeta_id blank as it will be created automatically. The exact values above are the ones within the double quotes, but without the double quotes.

Once inserted you should be able to login with your new user and password.

Have fun 😉



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.