Creating a WordPress Administrator with phpMyAdmin and mySQL.
A tutorial on creating a WordPress Administrator with phpMyAdmin and mySQL.
There are many situations when your WordPress Dashboard might not be available to you:
- You’ve simply lost your WordPress Administrator login or password.
- Your website has been hacked.
- You’ve taken over an existing website but the previous developer won’t part with the password.
- There are a few more, but at this point you probably want some help creating a WordPressAdministrator with phpMyAdmin and mySQL.
This processes discussed in the creating a WordPress Administrator with phpMyAdmin and mySQL tutorial are reliant on:
- Either you having CPanel (or similar) access to your website.
- Or direct access to your WordPress database.
Here are the steps for creating a WordPressAdministrator with phpMyAdmin and mySQL:
- Log in to your database, either via the phpMyAdmin link in your server control panel, or via a direct link.
- Select your database.
- Edit SQL statement in code editor.
- Paste code into SQL tab & run the query.
- Refresh the wp-admin page in your browser and log in with your new credentials.
Step 1: Log in to phpMyAdmin
You should see the complete list of databases on your webserver account in the column on the left hand side.
Remember that for a WordPress website, the name of the database, database user and database password is stored in wp-config.php at the root level of the website.
If you’ve had problems connecting to the database beforehand (ie: an error message when you try and access the website that reads “Error Connecting To Database” or similar), you might want to check that the database name, user and password that you have defined in wp-config.php are actually the ones used on the live webserver.
I make mention of this because sometimes when you’re moving a website from one location to another (perhaps moving from local development to a test server or production server environment), it’s not guaranteed that all these values will be exactly the same.
So it pays to check the name of your database on the server and make sure that the name is exactly the same in wp-config.php. The same goes for the username and password.
Doublecheck…
Just before we run the SQL statement, let’s have a quick look at where the current users of this website are defined, so that when we’re done with the exercise, you can come back and check that you’ve done the job correctly.
Make sure the database has been selected. Now expand the database table view by clicking on the ‘+’ symbol to the left of the database name. All the tables that belong to the database will drop down.
Click on the image to view it in more detail.
Doublecheck…
Now click on the wp_users table, which will usually open to the table structure. You should now see all the fields associated with this table (including the user_login, user_pass and user_email fields which we’re going to be editing.
Click the ‘Browse’ tab to see the actual contents of the table. Note that there is one user.
Click on the image to view it in more detail.
Step 3: Edit SQL statement in code editor.
Copy the SQL statement supplied in the code block below. Paste the code into your preferred code editor, or even something as simple as Notepad or TextEdit.
Making sure that you take note of the location of all single and double quotes, change the user_login, user_pass and user_email values to your preferred values.
Click on the image to view it in more detail.
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `user_registered`) VALUES ('newname', MD5('newpassword'), 'yourfirstname yourlastname', 'youremail@yoursite.com', '0', '2018-06-18 06:52:28'); INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'); INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
Step 4: Paste code into SQL tab & run the query.
Select the SQL tab at the top of the phpMyAdmin window and paste the code into the editing window.
Click the ‘Go’ button.
Where could this go wrong?
In this example, I have used a database called ‘wordpress’, and the tables that are being edited have a ‘wp_’ prefix.
If your table prefix name is different, then you will have to change the ‘wp_users’, ‘wp_user_meta’, ‘wp_capabilities’ and ‘wp_user_level’ variable names to ‘yourprefix_users’, ‘yourprefix_usermeta’, ‘yourprefix_capabilities’ and ‘yourprefix_user_level’ .
Click on the image to view it in more detail.
Doublecheck…
Now click on the wp_users table, which will usually open to the table structure. You should now see all the fields associated with this table (including the user_login, user_pass and user_email fields which we’re going to be editing.
Click the ‘Browse’ tab to see the actual contents of the table. Note that there is one new user.
The actual values I’ve used for the user_login, user_nicename, user_email and user_registered are irrelevant (although the user_registered value needs to be correctly formatted.
Click on the image to view it in more detail.
Doublecheck…
After you have logged in, navigate to the Users tab and see the new WordPress user.
If you wanted to remove the old one, (and do this with extreme caution), delete the user and attribute all content to your new user when asked.
And that’s the end of the creating a WordPress Administrator with phpMyAdmin and mySQL tutorial. Hope it helps!
Click on the image to view it in more detail.