MySQL is a popular open source relational database management system that is widely used in various types of applications. While using MySQL, we may need to delete one or more databases. This article will introduce how to delete a database in MySQL.
There are two ways to delete a database in MySQL: through command line tools and using graphical user interface (GUI) tools. This article will introduce both methods in detail.
Using Command Line Tools
The MySQL command line tool is a way to perform various administrative tasks, such as creating, deleting, and repairing databases. If you are familiar with command line tools, this method will be very convenient.
Step 1: First, launch the MySQL command line tool in the command prompt or terminal. On Windows operating systems, you can search for "cmd" in the Start menu and open the command prompt. On Linux, you can open the Terminal application.
Step 2: In the MySQL command line tool, enter the following command to connect to the MySQL server:
mysql -u root -p
This will prompt you for your password. Enter the root user's password and press Enter. If the password entered is correct, you will get the following output on the MySQL command line:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is #. Server version: x.x.x
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
Step 3: Enter the following command to delete the database:
DROP DATABASE
In this command, replace
DROP DATABASE test;
After executing this command, the database will be completely deleted from the MySQL server and cannot be used recover.
Step 4 (optional): When you are done, you can use the following command to disconnect from the MySQL server.
exit;
Using Graphical User Interface (GUI) Tools
There is another method that can be used to delete a database in MySQL, and that is to use Graphical User Interface (GUI) )tool. This may be more convenient if you are not familiar with the command line interface.
Step 1: Start the MySQL GUI tool. MySQL provides a variety of GUI tools, such as MySQL Workbench, PHPMyAdmin, and more. In this article, we will use MySQL Workbench as an example.
Step 2: Connect to the MySQL server. After launching the MySQL Workbench application, click the "Connect to MySQL Instance" button. Enter the MySQL server’s hostname, port number, username, and password. Click the "Test Connection" button to make sure the connection is correct.
Step 3: After clicking Connect, the global view of the MySQL server will be displayed. In the left menu, you will see an option called "Admin" or "Admin Tools."
Step 4: Click the "Manage" or "Administrative Tools" option and select "Data Warehouse". After this, you will see a list of all databases. In this list, select the database to delete.
Step 5: Right-click on the selected database name. Select the "Delete" option from the drop-down menu. Click "Confirm" in the pop-up confirmation dialog box.
Step 6: Once you complete the above steps, you can safely delete the database. NOTE: When deleting a database using the GUI tool, you will have no way to undo and the data will be immediately deleted from the server and cannot be recovered.
Summary:
MySQL database is an excellent database widely used in a variety of different applications. During the use of MySQL, sometimes it is necessary to delete the database to ensure data security and management. MySQL provides command line windows and GUI tools to accomplish this task. This article describes two methods. If you are familiar with command line operations, you can choose to use the command line window; if you like the graphical interface, you can choose to use GUI tools to delete the MySQL database. No matter which method you choose, remember to confirm whether you can delete the database before deleting it, because once deleted, it cannot be undone.
The above is the detailed content of mysql delete database. For more information, please follow other related articles on the PHP Chinese website!