When using the MySQL database, sometimes you need to delete certain tables and related data. This article will introduce how to delete database tables using the command line and MySQL Workbench.
Delete database table using command line
Use command line to connect to MySQL database. If the database is running locally, you can connect directly using the following command:
mysql -u root -p
This will prompt you to enter the MySQL root user password.
After the connection is successful, use the following command to select the database to be operated:
use database_name;
Change the above "database_name" Replace with the name of the database you want to operate on.
Use the following command to display all tables in the currently selected database:
show tables;
A list containing The names of all tables.
Use the following command to delete a table:
drop table table_name;
Replace "table_name" above with the name of the table you want to delete.
When you run this command, MySQL will ask you whether to confirm deletion of the table. Enter "yes" to confirm the deletion.
MySQL Workbench delete database table
MySQL Workbench is an easy-to-use GUI tool that can help you manage MySQL database easily.
Open MySQL Workbench and connect to the database where you want to delete the table.
In MySQL Workbench, you can easily display all tables in the currently selected database. In the Navigator pane, click the database name. Then expand the "Tables" node to display all tables in the current Database.
In the table list, right-click the table you want to delete.
Select "Drop Table" from the context menu.
When you click "Drop Table", MySQL will ask you whether to confirm the deletion of the table. Click "OK" to confirm the deletion.
Summary
There are two ways to delete a table in MySQL: through the command line and MySQL Workbench. Whichever method you use, you need to be careful with the tables you delete as this will permanently delete the data. Before performing the deletion operation, make sure to back up your data to prevent data loss.
The above is the detailed content of mysql delete table database table. For more information, please follow other related articles on the PHP Chinese website!