How to Add a WordPress User via phpMyAdmin

As a web developer, I often encounter situations where I have hosting access to a website but not added to […]

As a web developer, I often encounter situations where I have hosting access to a website but not added to the wp-admin (client forgot to add or someone from dev team uploaded a backup, urgh!!).

The quickest way, without pinging the client or anyone else, is to manually add your user to the WordPress website through phpMyAdmin, since you can’t access WordPress Dashboard to access users. In this post, I’ll guide you through the steps to add a WordPress user via phpMyAdmin.

Option #1 (The Easy Way)

As I said, I often encountered such situations and had to manually add user via phpMyAdmin. To streamline this process, I developed a tool that automatically generates the SQL queries needed to add a new WordPress user. You can find this tool at Generate SQL to Create a New WordPress User via phpMyAdmin. It’s a simple interface where you input the user details, and it provides you with ready-to-execute SQL commands.

Once you have the generated SQL, all you need to do is run it in phpMyAdmin and you’re done!

PS: The tool asks for password that you want to set, that password is never stored nor sent to the server. Everything you type in the tool never leaves your browser.

Option #2 (The Hard Way)

Step 1: Access phpMyAdmin First, log in to your hosting control panel and open phpMyAdmin. Select the database associated with your WordPress site.

Step 2: Insert User Data Navigate to the wp_users table. You’ll need to insert a new record with the following details:

  • user_login: The username for the new account.
  • user_pass: A hashed version of the password. WordPress uses the MD5 hash (though I recommend using a stronger hash if possible).
  • user_nicename: A URL-friendly version of the username.
  • user_email: The user’s email address.
  • user_registered: The date and time when the user is registered.
  • user_status: Set this to 0.
  • display_name: The user’s full name or preferred display name.

Step 3: Assign User Role WordPress roles and capabilities are stored in the wp_usermeta table. You need to add a new entry associated with the user’s ID:

  • umeta_id: Leave this blank as it auto-increments.
  • user_id: The ID of the user you just added.
  • meta_key: Set this to wp_capabilities.
  • meta_value: Insert the role within a serialized PHP string. For an administrator, use: a:1:{s:13:"administrator";s:1:"1";}

Step 4: Set User Level Still in the wp_usermeta table, add another record:

  • meta_key: This time, it’s wp_user_level.
  • meta_value: Set the user level, e.g., 10 for an administrator.

Final Thoughts Adding a WordPress user directly via phpMyAdmin is a powerful method, particularly useful in emergencies or when working on client sites without admin credentials. Always ensure you have the correct permissions to modify the database and remember that handling raw SQL queries can be risky if not done carefully.

This method and tool are parts of the essential toolkit for any WordPress developer looking to work efficiently with database management. Whether you are setting up a new user for testing or managing user roles without accessing the admin panel, these steps will get the job done effectively.