Modifying the user name in MySQL is a relatively simple operation and can be completed in just a few steps. The following will introduce how to modify the user name in MySQL.
First, enter the following command in the terminal to log in to MySQL as the root user.
$ mysql -u root -p
Then enter the password and log in to MySQL.
In MySQL, we need to create a new user. The specific operation is as follows:
mysql> CREATE USER 'new_username'@'localhost' IDENTIFIED BY 'password';
Among them, 'new_username' represents the new username, 'localhost' represents the host where the user is located, and 'password' represents the password. If it is a remote host that needs to be accessed, change 'localhost' to '%'
After the new user is created, there is no permission by default and you need to give it accordingly Only with the required permissions can you operate MySQL.
For example, if you want to give a new user read and write permissions on all databases, you can execute the following command:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'new_username'@'localhost';
If If you need to delete the original username, you need to first delete the permissions of the original username, and then delete the original username.
Permission to delete the original user name:
mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'old_username'@'localhost';
Delete the original user name:
mysql> DROP USER 'old_username'@'localhost';
Finally, execute The following command exits MySQL.
mysql> exit;
Summary:
Through the above steps, we can complete the user name modification in MySQL. It should be noted that when performing these operations, you must be careful and operate with caution to avoid unnecessary losses.
The above is the detailed content of How to modify username in MySQL. For more information, please follow other related articles on the PHP Chinese website!