You can drop/delete/remove a MySQL database easily 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

 

[root@host]# mysqladmin -u root -p drop LEARNING
Enter password:******

 

Let's take an example to drop a database from MySQL with PHP

 

<?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.

 

About Tec News

Tec News is optimized for learning Web Development, Programming, Database System and Tutorials, Articles, References for your development. This web help developers, learners learn these technologies easy and free.

Contact Us

If you have any suggestions or have any questions regarding our web please feel free to contact us.

info@tec-news.com        

https://www.tec-news.com