How to delete MySQL database and user via command line in Linux?

LearnTips Internet How to delete MySQL database and user via command line in Linux?

Tagged: , ,

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2140

    Login in MySQL.
    sudo mysql -u root -p

    Deleting a MySQL database.

    Identify the MySQL database.
    You can list all available databases by using the following command.
    mysql> SHOW DATABASES;

    The output should be something like this.

    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | database_name      |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    5 rows in set (0.00 sec)

    Note the name of the database that you want to delete from the displayed list.

    Delete the database.
    You can now, delete that particular database by using the following command.
    mysql> DROP DATABASE database_name;
    Make sure you replace the database_name with the name of the database that you want to delete.

    The output should be something like this:
    Query OK, 0 rows affected (0.00 sec)

    Deleting a MySQL user.

    Identify the MySQL user.
    Type the following command to list all MySQL users.
    mysql> SELECT User FROM mysql.user;

    The output should be something like this:

    +-------+
    | User |
    +-------+
    | root |
    +-------+
    | newuser |
    +-------+

    Delete the MySQL user.
    You can delete a MySQL user with the following command.
    mysql> DROP USER 'newuser'@'localhost';
    Make sure to replace newuser with the name of the user that you want to delete.

    The output should be something like this:
    Query OK, 0 rows affected (0.01 sec)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.