How do I delete MySQL User Account

MySQL allows you to create multiple user accounts and grant the appropriate permissions so that users can access and manage the database. If the user does not need an account, it is best to delete user privileges or delete user accounts.

This tutorial describes how to remove MySQL / MariaDB user account.

DROP USER statement

In MySQL, you can use the DROP USER statement removes one or more users and assign permissions. The general syntax of the statement is as follows:

DROP USER [IF EXISTS] USER_ACCOUNT [, USER_ACCOUNT] ...

For example, to delete linux @ localhost user account to log on to the MYSQL shell and run:

mysql> DROP USER 'linux'@'localhost';

After the success, the command will return:

Query OK, 0 rows affected (0.00 sec)

As shown below:

How do I delete MySQL User Account

To delete a single command multiple user accounts, run the DROP USER statement, and then run the per-user space-separated you want to delete:

If you try to delete a user account does not exist and are not using IF EXISTS clause, the command returns an error.

If you try to remove a user is currently logged on, the user does not close the session, and the user will be able to run queries, until the end of the session. After the session closes, the user will be removed, it will no longer be able to log MySQL server.

It does not automatically delete the database and user-created objects.

Delete MySQL User Account

This section provides step by step instructions on how to list and delete MySQL user accounts.

First, root or other administrative user logs MySQL shell. To do this, type the following command:

sudo mysql

If you are using an old native MySQL authentication plug logged in as root, run the following command and enter the password when prompted:

mysql -u root -p

The following commands are executed in the MySQL shell.

MySQL to store information about a user in the user table mysql database. Use the following SELECT statement to get a list of all MySQL user accounts:

SELECT User, Host FROM mysql.user;

The output should be as follows:


mysql> SELECT User, Host FROM mysql.user;
+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| linuxmi          | %         |
| linux            | localhost |
| linuxidc         | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
7 rows in set (0.01 sec)

How do I delete MySQL User Account

To delete a user run:

Export

Query OK, 0 rows affected (0.00 sec)

This command will delete user accounts and their privileges.

Now the user has been deleted, you may want to delete the database associated with the user.

to sum up

To delete a MySQL user account, use the DROP USER statement, followed by the name you want to delete the user.

If you have any questions or feedback, please feel free to comment.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/160322.htm