Home > Database > Mysql Tutorial > mysql delete table database table

mysql delete table database table

王林
Release: 2023-05-23 09:24:28
Original
591 people have browsed it

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

  1. Connect to MySQL database

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
Copy after login

This will prompt you to enter the MySQL root user password.

  1. Select the database to be operated

After the connection is successful, use the following command to select the database to be operated:

use database_name;
Copy after login

Change the above "database_name" Replace with the name of the database you want to operate on.

  1. Display database table list

Use the following command to display all tables in the currently selected database:

show tables;
Copy after login

A list containing The names of all tables.

  1. Delete table

Use the following command to delete a table:

drop table table_name;
Copy after login

Replace "table_name" above with the name of the table you want to delete.

  1. Confirm deletion

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.

  1. Open MySQL Workbench

Open MySQL Workbench and connect to the database where you want to delete the table.

  1. Display database table list

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.

  1. Right-click the table you want to delete

In the table list, right-click the table you want to delete.

  1. Select "Drop Table"

Select "Drop Table" from the context menu.

  1. Confirm Delete

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template