How to delete MySQL database and user via command line in Linux?
- This topic has 0 replies, 1 voice, and was last updated 3 years, 9 months ago by
Santhosh Kumar D.
- AuthorPosts
- November 26, 2019 at 12:02 AM #2140
Santhosh Kumar D
KeymasterLogin 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 thedatabase_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 replacenewuser
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)
- AuthorPosts
- You must be logged in to reply to this topic.