How to delete or remove a MySQL/MariaDB user account on Linux/Unix

To delete or remove a MySQL or MariaDB user account on Linux or Unix, you can use the DROP USER command. Here’s how to delete a MySQL or MariaDB user account:

  1. Connect to the MySQL or MariaDB database as a user with sufficient privileges:
    mysql -u <username> -p

    where <username> is the name of the user account with sufficient privileges.

  2. Execute the DROP USER command:
    DROP USER '<user-to-be-deleted>'@'<hostname>';

    where <user-to-be-deleted> is the name of the user account to be deleted, and <hostname> is the hostname of the computer where the user is allowed to connect.

  3. Flush the privileges to make the changes take effect:
    FLUSH PRIVILEGES;
  4. Exit the MySQL or MariaDB shell:
    exit;

Now, the specified user account has been deleted, and it will no longer be able to connect to the database.

Leave a Comment