MySQL is a commonly used relational database management system, which is widely used in various application scenarios. In the process of using MySQL, in order to ensure data security, we need to modify the MySQL user name. This article will introduce how to modify the MySQL user name.
First, we need to log in to MySQL. You can log in through the following command:
mysql -u 原用户名 -p
where the original username is your current MySQL username. After executing the above command, you will be prompted to enter the password of the MySQL user. After entering the correct password, you can successfully log in to MySQL.
After successful login, we need to create a new MySQL username, the command is as follows:
CREATE USER '新用户名'@'localhost' IDENTIFIED BY '密码';
Among them, new The user name is the MySQL user name you want to create, and the password is the password corresponding to the user name. After executing the above command, the system will prompt you that the new MySQL username has been successfully created.
Next, we need to authorize the permissions owned by the original MySQL username to the new username. The command is as follows:
GRANT ALL PRIVILEGES ON *.* TO '新用户名'@'localhost';
After executing the above command, the system will prompt you that the permissions owned by the original MySQL username have been successfully authorized to the new username.
Finally, we need to delete the original MySQL username. This operation can be achieved through the following command:
DROP USER '原用户名'@'localhost';
After executing the above command, the system will prompt you that the original MySQL user name has been successfully deleted.
Summary
Through the above steps, we can modify the user name in MySQL. It should be noted that the data in MySQL should be backed up before modifying the user name to avoid data loss. At the same time, modification of user names should be done with caution to ensure that it does not affect the normal use of MySQL.
The above is the detailed content of Modify mysql username. For more information, please follow other related articles on the PHP Chinese website!