Home > Database > Mysql Tutorial > body text

How to modify username in MySQL? (code example)

藏色散人
Release: 2019-03-14 17:36:07
Original
5046 people have browsed it

If a MySQL administrator wishes to change the username or host of an existing MySQL user account without changing the user account's privileges, the RENAME USER statement can be used in MySQL.

How to modify username in MySQL? (code example)

RENAME USER statement syntax:

RENAME USER 'username'@'host' TO 'new_username'@'host';
Copy after login

Parameters:

username: this is the username of the user account you want to rename.

new_username: This is the new name you want to assign to the user.

Suppose there are 4 users in the MySQL database server as follows:

How to modify username in MySQL? (code example)

Now let us understand how to use the RENAME USER statement Rename a user:

Rename a single user using the RENAME USER statement:

To rename a user account with the username "gfguser1", execute RENAME USER as follows Statement:

Syntax:

How to modify username in MySQL? (code example)

Output:
The table after executing the rename user statement is as follows:

How to modify username in MySQL? (code example)

Use the RENAME USER statement to rename multiple users:

The RENAME USER statement can be used to rename multiple user accounts at once. To rename the two user accounts "gfguser2" and "gfguser1" in the above table, the RENAME USER statement should be executed as follows:

Syntax:

How to modify username in MySQL? (code example)

Output:

The table after executing the above rename user statement is as follows:

How to modify username in MySQL? (code example)

## Recommended related mysql video tutorials: "

mysql tutorial

This article is about the method of changing the user name in MySQL. I hope it will be helpful to friends in need!

The above is the detailed content of How to modify username in MySQL? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!