Home  >  Article  >  Database  >  How to modify username in MySQL

How to modify username in MySQL

PHPz
PHPzOriginal
2023-04-17 16:41:463101browse

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.

  1. Log in to 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.

  1. Create a new user

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 '%'

  1. Give permissions

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';
  1. Delete the original user name

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';
  1. Exit MySQL

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!

Statement:
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