Get the App
SLTechnology News&Howtos  ›  Database  › 

How mysql deletes users

Shulou Source: shulou.com Published: 2022-06-01 03:26:23 10月27日 Update

This article mainly introduces how to delete mysql users, the article is very detailed, has a certain reference value, interested friends must read it!

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

Syntax format:

DROP USER [,]...

You should pay attention to the following points when using DROP USER statements:

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 DELETE permissions or global CREATE USER permissions for the MySQL database in MySQL.

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

Note: users' deletions do not affect their previously created tables, indexes, or other database objects, because MySQL does not record who created these objects.

[instance] use DROP USER statement to delete user 'jack'@'localhost'. The SQL statement entered and the execution procedure are shown below.

Mysql > DROP USER 'jack'@'localhost'

In the Windows command line tool, log in to the database server using jack and password lion, and find that the login failed, indicating that the user has been deleted, as shown below.

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

Expand

Drop

Drop user XXX

Delete existing users, the default is' XXX'@'%' this user, if there are other users, such as' XXX'@'localhost', etc., will not be deleted together. If you want to delete 'XXX'@'localhost', you need to add host, that is, drop user' XXX'@'localhost' when you use drop to delete.

Delete

Delete from user where user='XXX' and host='localhost'

Where XXX is the user name and localhost hostname.

Difference

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

The above is how mysql deletes all the user's content, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: User statement permission data content database host multiple object account login value global interest command instance password buddy partner tool Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Xiaomi Docker Shulou Tech Info