Home >Database >Mysql Tutorial >How to delete a user in mysql
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.
MySQL method of deleting users:
Grammar format:
DROP USER <用户名1> [ , <用户名2> ]…
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';
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)
Extension:
drop
drop user XXX;
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';
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!