• Web Designing
  • How to’s

How to create an admin user via ftp and mysql in wordpress.

There are lots of reasons when we want to create an admin id in WordPress site to get into the backend. We require to do this when we lock ourselves out of the admin dashboard or maybe you have forgotten the admin password, reasons may be many. What will you do in such situations? In this kind of total lockdown situations, one can get back to the WordPress dashboard, it’s very easy. I have known two methods to achieve this. The first method is to create a new admin user via MySQL database and the second one is using the FTP or file manager to create a new admin id in your site.

1. Creating the admin Id via FTP.

For creating an admin id in your WordPress website you will have to connect to your websites FTP using FileZilla or any other FTP client. or via login into your Cpanel and open file manager. Just got to your WordPress websites root directory, it must be in public HTML folder if you have installed your site on your root domain. And go to your active themes root directory at /yoursite.com/wp-content/themes/YOUR_THEME_ROOT/functions.php directory.

Open the function.php file, if it’s not there then create one for this purpose. Open it in code editor mode if you are accessing it via Cpanel file manager or use notepad ++ if using FileZilla for FTP. After opening this you will have to add these lines to your function.php file to gain access to your admin dashboard.

function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
if ( !username_exists( $user )  && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }

Do not forget to change your username, password, and email with your own values, so that you can remember it for login. After adding this code you will have to save it. This code will create an admin id for you to login. After getting access to your admin dashboard you can create another admin id and don’t forget to remove this code from your function.php file. Remember deleting this code won’t delete this id and password from the database.

2. Creating an admin id via Mysql.

For this method, you will have to log in to your Cpanel and access to PHPMyAdmin of your server. After you open the PHPMyAdmin click on the WordPress database you are using.

After that go to the wp_user table of your database and click on the insert tab. Remember the table prefix wp_ maybe different in your database. you just have to look for a YOURPREFIX_users table. When you click on insert tab it will open a form for you to add a new user. There you will have to insert the new admin user details like this.

  • user_login: The user id you want to log in with
  • user_pass: The password for this user to login with
  • user_email: User email address, so that you can recover your password later.
  • user_registered: Date and time for this user when it’s registered.
  • user_status: Set this to 0.

Leave all other fields empty for now we can add other details later on from Admin dashboard. And don’t forget to select MD5 character coding for the password field, so that database can read it. After entering these values click on the go button and you will see a success message. You can go back to the wp_users table and browser the entries to verify that the user record has been inserted correctly (see screenshot below).

Take note of the value if the “ID” field for this newly created user (we will need this ID field’s value for the next step). In this case, the ID is 2.

At this point, you have successfully created an admin id in your WordPress database. But you will have to give admin rights to this user so that it can allow you to do the things only an admin can do.  Now go to the wp_usermeta table and click on the Insert tab to add admin capabilities to the user we have just created.

Add these details in the tables and click the “Go” button to insert the usermeta data.

  • unmeta_id – Leave it blank (it will be generated for you)
  • user_id – This is the ID of the user we created in the previous step. For our case, it is 2.
  • meta_key – Use wp_capabilities
  • meta_value – Use the following value for this field:

That’s all done here, Now you can go back to your admin dashboard login URL at https://yoursite.co/wp-admin and log in with your newly created admin user id and password.

For keeping my website clean and tidy I use only the user id which has editor capabilities instead of admin user id. Because I think when you finish the design part of the WordPress website, one should not go messing things with admin user id for lots of reasons. Like very often I distract myself from writing to designing and adding more and more short of functions in my website, and keep on designing and perfecting it. And when you are a designer you always try to make your website beautiful and smooth. This never ends I must say. Also using admin id for writing your articles can leave an easy target for hackers and spammers. So, that’s why I prefer to use editor id for myself. And when I don’t log in for so long via admin id I forget the id and password. At least that’s the reasone for creating an admin user following this way. What’s your reason for this kind of lockdown situation. So here I am completing my 3rd article on Tactis Digital, do leave your comment. Happy blogging for now.

Stay in Touch

To follow the best weight loss journeys, success stories and inspirational interviews with the industry's top coaches and specialists. Start changing your life today!

Related Articles