WordPress Admin Login

I cannot think of that many reasons as to why you would want to change your WordPress login name, but I have done it before myself and I know that the first time doing it can be painful as you cannot figure out where to start. It’s a fairly common issue that cannot be solved through the WordPress admin dashboard, and instead you will need to poses some basic skills on how-to edit a MySQL table.

In this example I am going to use the cPanel control panel as the core of the solution. We’re going to access phpMyAdmin through our hosting panel and change the WordPress login through there. The other way around would be by executing a MySQL query directly from a PHP file – which can be more difficult to beginners.

Change WordPress Login With PHP Script

However, here is the PHP code you can save as change-login.php,

< ?php

// localhost = database hostname
// alex = mysql login name
// 1337 = mysql password
// DATABASE_NAME = the name of your WordPress database

// establishes connection
$estcon = mysqli_connect("localhost","alex","1337","DATABASE_NAME");

// checks if the connection is working
if (mysqli_connect_errno())
  {
  echo "Unable to connect to MySQL: " . mysqli_connect_error(); 
// prints the error if failed to connect
  }
 
// updates the table wp_users and the row user_nicename which accounts for the login name
// the ID = admin id, which is usually going to be 1 for admin
mysqli_query($estcon,"UPDATE wp_users SET user_nicename = 'New-Login' WHERE ID = '1'");

// close the connection
mysqli_close($estcon);
?>

This will do it for you without the need to go through phpMyAdmin, however I feel that some people might prefer to use that method. All you need for the above script is the database details and the new username you want. Always remember to use the ‘-‘ if you want to have a username like ‘Name Surname’, otherwise it won’t work.

Changed WordPress Login With phpMyAdmin

Login to your cPanel and scroll down to find the following tab and then click on the phpMyAdmin icon.

cPanel phpMyAdmin

Next you need to select the main database your WordPress installation is using and then the table wp_users

phpMyAdmin Selecting Table

After that you will be presented with all of the available usernames and user logins. You need to select your own (admin in this case) and click the ‘Edit’ button which will be presented right in front of you. After that, you will see a panel like this:

phpMyAdmin Change WordPress Login

At this point you want to figure out what your new username is going to look like and then change the according values. You only need to change the row user_nicename in order to change the login itself. Play around with it and see how it works. After you update the row, you can close the panel and login with your new username.

If you need help with it, please let me know and I’ll sort it out for you.