SQL to Change User Login (WordPress Username)

Published: 3 Mar 2023

This page explains how to change WordPress username (login) with a SQL query directly in the database.

General user login change SQL query

Usernames are stored in the wp_users table, in a column named user_login (not username, not user_name, not login – common mistakes).

You can easily change a particular user's login by running an UPDATE SQL query, which has the following structure:

UPDATE `wp_users` 
SET `user_login` = '...'  -- new username
WHERE ...  -- something to identify the user
;

Make sure to include the WHERE clause in your SQL query, otherwise you assign the new login to all your WordPress users!

The WHERE clause has several variants, depending on how you want to identify the user – by ID number, email, or old username.

Changing username when knowing the old one

If you know the existing username for the user, you can use it in the WHERE clause.

The SQL query in the example below changes the username from "admin" to "wpdir".

UPDATE `wp_users` 
SET `user_login` = 'wpdir' 
WHERE `user_login` = 'admin';

Note: For security, it is recommended to never use "admin" as WordPress username (which is default in a new WordPress installation and everyone knows it, including potential attackers). That said, using the website's name is not much better.

Changing username for user with given email address

Often you don't remember the old username, but you know the user's email address. You can use it in the WHERE clause as well:

UPDATE `wp_users` 
SET `user_login` = 'wpdir' 
WHERE `user_email` = 'admin@wpdir.com';

Changing username when knowing user ID number

If you know the WordPress ID number for the user, you can also use it in the WHERE clause. Note the column name is ID (capitalized).

The example below changes username for the user with ID = 1 to "wpdir".

UPDATE `wp_users` 
SET `user_login` = 'wpdir' 
WHERE `ID` = 1;

By remaining on this website or using its content, you confirm that you have read and agree with the Terms of Use Agreement.

We are not liable for any damages resulting from using this website. Any information may be inaccurate or incomplete. See full Limitation of Liability.

Content may include affiliate links, which means we may earn commission if you buy on the linked website. See full Affiliate and Referral Disclosure.

We use cookies and similar technology to improve user experience and analyze traffic. See full Cookie Policy.

See also Privacy Policy on how we collect and handle user data.

© 2024 WPDir