Removing users in MySQL
As with creating databases and tables, the opposite of creating a user is to DROP
. As we shall see, removing a user does not revert any changes that they have made to the database(s) to which they had access. If a user had the ability to create users, removing them will not remove the users they created.
Unlike databases and tables, dropping a user requires that you also specify the hostname of the user's record. Therefore, one cannot always enter:
DROP USER exemplar;
This will only work if the user was created without specifying the hostname.
If it exists, one must include the hostname. For best practice, the basic syntax is:
DROP USER <userid>@<hostname>;
Therefore to drop user exemplar
, we would pass the following statement:
DROP USER 'exemplar'@@'localhost';
Note that this will not impact that user's ability to log in from another host if that user had permission to connect from the other host.
DROP
, by design, only removes the user's account and its privileges...