Home > Database > Mysql Tutorial > body text

How to delete a user in mysql

(*-*)浩
Release: 2020-09-15 13:36:09
Original
6236 people have browsed it

The DROP USER statement can be used in the MySQL database to delete one or more user accounts and related permissions.

Recommended courses: MySQL Tutorial.

How to delete a user in mysql

MySQL method of deleting users:

Grammar format:

DROP USER <用户名1> [ , <用户名2> ]…
Copy after login

When using the DROP USER statement, you should pay attention to the following A few points:

The DROP USER statement can be used to delete one or more MySQL accounts and revoke their original permissions.

To use the DROP USER statement, you must have the DELETE permission of the MySQL database in MySQL or the global CREATE USER permission.

In the use of the DROP USER statement, if the host name of the account is not explicitly given, the host name defaults to "%".

Note: A user's deletion will not affect tables, indexes, or other database objects they previously created, because MySQL does not record who created these objects.

[Example] Use the DROP USER statement to delete user 'jack'@'localhost'. The input SQL statement and execution process are as follows.

mysql> DROP USER 'jack'@'localhost';
Copy after login

In the Windows command line tool, use jack and password lion to log in to the database server. It is found that the login fails, indicating that the user has been deleted, as shown below.

C:\Users\USER>mysql -h localhost -u jack -p
Enter password: ****
ERROR 1045 (28000): Access denied for user 'jack'@'localhost' (using  password: YES)
Copy after login

Extension:

drop

drop user XXX;
Copy after login

Delete an existing user. The user 'XXX'@'%' is deleted by default. If There are other users such as 'XXX'@'localhost', etc., which will not be deleted together. If you want to delete 'XXX'@'localhost', you need to add host when using drop to delete, that is, drop user 'XXX'@'localhost'.

delete

delete from user where user='XXX' and host='localhost';
Copy after login

where XXX is the user name and localhost is the host name.

Difference:

drop will not only delete the data in the user table, but also delete the contents of other permission tables. Delete only deletes the content in the user table, so after using delete to delete a user, you need to execute FLUSH PRIVILEGES; to refresh the permissions, otherwise an error will be reported the next time you use the create statement to create a user.

The above is the detailed content of How to delete a user in mysql. 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