How to Create a WordPress Admin Account with MySQL

WordPress

For security purposes, WordPress will require you to log in after every session. By default, WordPress will log you out after a web-browser is closed or after 48 hours. Logging in for every new browsing session will become second nature, but what happens if you attempt to access your site to find you are locked out, even though you have entered the password correctly? This can happen for a number of reasons: code error, accidental admin deletion, or a hack attempt are the most common. However, all is not lost. It is possible to regain access to a WordPress dashboard by creating a new admin account via MySQL. This tutorial will guide you through the process.

Accessing MySQL

MySQL is your WordPress database and something you will rarely need to access. However, for this task we are going to need to login to the cPanel of your hosting provider. Each hosting provider will have their own method on how this is done, but it is generally a simple case of entering your username and password in the “cPanel Login” fields.

Locate phpMyAdmin

Once again, every hosting provider will have different menus in terms of set-up, but options will be the same. To locate “phpMyAdmin” you will need to click on the category named “Databases” in your cPanel. “phpMyAdmin” will be one of the options within this category and can generally be found alongside “MySQL Databases”, “MySQL Database Wizard”, and “Remote MySQL”.

Creating a new account

In “phpMyAdmin” you will need to click on the database for you WordPress installation select the option for “SQL”. You will then be taken to a SQL editor, which is where you will need to enter some code to create a new account:

INSERT INTO 'wp_users' ('user_login', 'user_pass', 'user_nicename', 'user_email', 'user_status')
VALUES ('newadmin', MD5('mypassword1'), 'myfirstname mylastname', 'email@mywebsite.com', '0');

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');

Copy and paste the above code into the SQL editor file. As you can see, each of the account details marked in bold are examples. ‘newadmin’ is the new account username, the rest of the text is pretty self-explanatory. Change all bold text as required and remember to create a strong password.

With the details changed as required, click on “Go” or “Save” (depending on your hosting SQL editor). If the code is correct, the screen should display a message next to each statement saying, “1 row affected”. You can now visit your WordPress website (mywebsite.com/wp-admin) and log in using the new credentials.

In your dashboard, you should delete your previous account so that it cannot be used to log in to your website maliciously.

Share it!Share on FacebookTweet about this on TwitterShare on Google+Email this to someone

Our Recommended Wordpress Web Hosting Provider

WordPress

WHC.CA
Get a 50% Discount by using our link.

WHC.ca

Reliable host, with excellent customer service and an easy one-click Wordpress installation. Our recommendation to host a Wordpress blog.

Leave a Reply

Your email address will not be published. Required fields are marked *