How to Remove MySQL Tables, Databases and users using CMD

May 1, 2024 / MySQL

In this article, we will explain how to remove MySQL tables, databases, and users using the command line.

Follow the steps:

  1. Deleting tables and databases-
    1. To remove MySQL tables and databases using the command line, execute the following command from the mysql> prompt. Substitute the table name with the name of the table that you wish to remove-
      DROP TABLE tablename;

      The above command accepts that you have already chosen a database by using the USE statement.

    2. In the same manner, to remove the whole database, enter the below command from the mysql> prompt. Substitute dbname with the name of the database that you wish to remove-
      DROP DATABASE dbname;

      The MySQL program executes this command without seeking confirmation. Upon pressing Enter, MySQL promptly deletes the database along with all its data.

  2. Deleting users-
    1. To see a comprehensive list of all users, enter the following command at the mysql> prompt-
      SELECT user FROM mysql.user GROUP BY user;
    2. To remove a particular user, input the subsequent command at the mysql> prompt. Substituting “username” with the desired user’s name-
      DELETE FROM mysql.user WHERE user = ‘username’;

In this way, you can remove MySQL tables, databases, and users using the command line. Hope you liked our article. If you encounter any issues, feel free to contact our support team.

Spread the love