Home > Database > Mysql Tutorial > How to modify username in MySQL

How to modify username in MySQL

PHPz
Release: 2023-04-17 17:03:37
Original
3128 people have browsed it

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
Copy after login

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';
Copy after login

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';
Copy after login
  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';
Copy after login

Delete the original user name:

mysql> DROP USER 'old_username'@'localhost';
Copy after login
  1. Exit MySQL

Finally, execute The following command exits MySQL.

mysql> exit;
Copy after login

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!

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