Home >Database >Mysql Tutorial >linux mysql delete
In Linux systems, MySQL is a very commonly used database management system. If you use MySQL frequently, you will inevitably encounter situations where you need to delete a database or table. This article will introduce how to delete databases and tables in MySQL in Linux systems.
Delete MySQL database
In MySQL, deleting a database is very simple, just use the DROP DATABASE command. Assuming that the database to be deleted is named example, you can delete it with the following command:
DROP DATABASE example;
However, before deleting the database, you should back up the database to avoid accidentally deleting important data. Additionally, the delete operation will fail if the database is in use or there are clients connected to it.
Delete MySQL table
Similar to deleting a database, deleting a table is also very simple. Just use the DROP TABLE command. Assuming that the table to be deleted is named student, you can delete it with the following command:
DROP TABLE student;
Similarly, you should back up the data before deleting the table to avoid accidentally deleting important data.
Delete MySQL user
If you want to delete a user in MySQL, you can use the following steps:
Enter the following command in the terminal:
mysql -u root -p
Then enter your MySQL password to log in.
After logging in, run the following command in the MySQL command line:
SELECT user, host FROM mysql.user;
You will see the list of users in MySQL.
Assuming that the user you want to delete is foo, you can use the following command to delete it:
DROP USER 'foo'@'localhost';
If you only want to delete the account For some permissions, you can use the REVOKE statement, for example:
REVOKE INSERT ON *.* FROM 'foo'@'localhost';
The above command will revoke the INSERT permission of the foo account in all databases.
Summary
This article introduces how to delete MySQL databases, tables and users in Linux systems. Before deleting any objects, remember to back up your data. Also, be careful when dropping databases or tables as these operations cannot be undone.
The above is the detailed content of linux mysql delete. For more information, please follow other related articles on the PHP Chinese website!