Silva Web Designs - Web Design / Web Development Specialists
  • Home
  • About
  • Services
  • Portfolio
  • Team
  • Blog
  • Contact
Scroll

Tag: hacked

How to Add Admin User to WordPress with MySQL

Posted on 27th July 201628th March 2020

Today I had to do a change on a clients Admin panel in WordPress only to find that my username had been deleted from the database through the WordPress Admin by one of the other administrators.

Instead of wasting time and asking the client to create me another admin user, I decided to go for the quick approach and simply add another user in the database since we host there web files and database. This technique would work as well if your WordPress website has been hacked or you can’t use the request password reset feature because you no longer have access to the email address that is saved against your username.

Before we start: You should always make a backup of your database before performing any MySQL edits. This tutorial requires a basic understanding of how phpMyAdmin works.

Firstly, you need to login to phpMyAdmin and locate your WordPress database.

Now you will be making changes to the wp_users and wp_usermeta tables. Let’s go ahead and click on wp_users table.

We need to insert our new admin user’s information, so click on the Insert tab as it shows in the image above. In the insert form, add the following:

  • ID – pick a number (in our example, we will use the number 99).
  • user_login – insert the username you want to use to access the WordPress Dashboard.
  • user_pass – add a password for this username. Make sure to select MD5 in the functions menu (Refer to the screenshot below).
  • user_nicename – put a nickname or something else that you would like to refer yourself as.
  • user_email – add the email you want to associate with this account.
  • user_url – this would be the url to your website.
  • user_registered – select the date/time for when this user is registered.
  • user_status – set this to 0.
  • display_name – put the name you like to display for this user on the site (it can be your user_nicename value as well).
  • Click on the Go Button

Next, we are going to have to add the values to wp_usermeta table. Click on the wp_usermeta table and then click on the Insert tab just like the previous step. Then add the following information to the insert form:

  • unmeta_id – leave this blank (it will be auto-generated)
  • user_id – this will be the id of the user you created in the previous step. Remember we picked 99.
  • meta_key – this should be wp_capabilities
  • meta_value – insert this: a:1:{s:13:”administrator”;s:1:”1″;}

Insert another row with the following information:

  • unmeta_id – leave this blank (it will be auto-generated)
  • user_id – this will be the id of the user you created in the previous step. Remember we picked 99.
  • meta_key – this should be wp_user_level
  • meta_value – 10

Then click on the Go button, and you have created yourself a new username. Now you should be able to login to your wp-admin with the username and password you specified for this user. Once logged in, click on Users and edit the username you just created. Go down and click on the Save button (you don’t have to change anything). This will allow WordPress to go through and add some more information and clean-up the user we just added.

SQL Query Method

For developers who want to speed this process up, you can simply drop this SQL query in your database.


INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('99', 'nathan', MD5('demo'), 'Your Name', '[email protected]', 'http://www.test.com/', '2011-06-07 00:00:00', '', '0', 'Your Name');


INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '99', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');


INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '99', 'wp_user_level', '10');

Remember to change the databasename value to the database you are working with. Also, don’t forget to change the appropriate values. (remember: if the ID 99 is already in use, change 99 to available ID value)

Any questions, drop me a comment and I’ll be glad to help!

 

Silva Web Designs - Profile

Posted by: Silva Web Designs

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital related. His main expertise is with WordPress, Magento, Shopify as well as many other frameworks. Whether you need responsive design, SEO, speed optimisation or anything else in the world of digital then get in touch. If you would like to work with Nathan, simply drop him an email at [email protected]

It’s good to share

Posted in MySQL, WordpressTagged add, hacked, login, MySQL, user, WordpressLeave a Comment on How to Add Admin User to WordPress with MySQL




Get in touch

Do you need a professional designer/developer for your next project? Get in touch using the form below.


    Categories

    • CSS
    • HTML
    • JavaScript
    • jQuery
    • MSSQL
    • MySQL
    • PHP
    • Technologies
    • Wordpress



    Recent Posts

    • Top 5 VPN Services in 2022
    • Is Angular used for Frontend or Backend Development?
    • 10 Most Important Reasons Why Your Startup Needs A Mobile App
    • How Are AI And Machine Learning Revolutionizing Software Development?
    • Website Security Checklist – How to Secure Your Site in 2022

    Get best VPN service with secure access and high speeds at IPVanish.com!


    Love our blog?

    Why not sign up to our newsletter for the latest tutorials and web related gossip.

    • Home
    • About
    • Services
    • Portfolio
    • Team
    • Blog
    • Contact

    © Copyright SILVA - 2022 - Cookie Policy | T&C

    We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
    SettingsAccept All
    Privacy & Cookies Policy

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
    Necessary
    Always Enabled
    Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
    Non-necessary
    Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
    SAVE & ACCEPT