We can drop/delete/remove the MySQL database simply with the MySQL DROP database command. It deletes all the tables of the database alongside the database permanently. It throws a mistake if the database isn’t available. we will use the IF EXISTS option with the DROP DATABASE statement. It returns the numbers of tables which are deleted through the DROP DATABASE statement. we should always take care while deleting any database because we’ll lose all the info available within the database.
Syntax
1 2 |
[root@host]# mysqladmin -u root -p drop LEARNING Enter password:****** |
Drop a database from MySQL with PHP
Let’s take an example to drop a database from MySQL with PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php //Your MySQL databse settings $servername = "localhost"; $username = "root"; $password = "root"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Create database $sql = "DROP DATABASE LEARNING"; if ($conn->query($sql) === TRUE) { echo "Database deleted successfully"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?> |
What is Next?
In the next section, you will learn how to create a table in MySQL.
* Please do let us know your views on this article and what type of articles would you are interested to read.
Widget not in any sidebars
