To log in to the MySQL server as a normal user, you may need specific permissions to create or delete the MySQL database, so we use root to log in, root has the highest permissions.

Be very careful when deleting a database, because all data will disappear after the delete command is executed.

 

The drop command deletes a database

Format of the drop command:

Drop database < database name >;Copy the code

For example, delete a database named RUNOOB:

mysql> drop database RUNOOB;
Copy the code

Delete the database using mysqladmin

You can also use the mysql mysqladmin command on the terminal to perform the delete command.

The following example deletes the RUNOOB database that was created in the previous section:

 

[root@host]# mysqladmin -u root -p drop RUNOOB
Enter password:******
Copy the code

After executing the delete database command above, a dialog box will appear to confirm whether the database is really deleted:

Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'RUNOOB' database [y/N] y
Database "RUNOOB" dropped
Copy the code

Delete the database using the PHP script

PHP uses the mysqli_query function to create or delete MySQL databases.

This function takes two arguments and returns TRUE on success and FALSE otherwise.

grammar

mysqli_query(connection,query,resultmode);
Copy the code
parameter describe
connection A necessity. Specify the MySQL connection to use.
query Required, specifies the query string.
resultmode Optional. A constant. Can be any of the following values: * MYSQLI_USE_RESULT (use this if you need to retrieve large amounts of data)
  • | MYSQLI_STORE_RESULT (the default)

The instance

The following example demonstrates using the PHP mysqli_query function to drop a database:

Deleting a Database

<? php $dbhost = ‘localhost’; $dbuser = ‘root’; $dbpass = ‘123456’; $conn = mysqli_connect($dbuser, $dbpass); if(! $conn) {die(‘ connection failed: ‘. Mysqli_error ($conn)); } echo ‘connect successfully <br />’ $sql = ‘DROP DATABASE RUNOOB’; $retval = mysqli_query( $conn, $sql ); if(! $retval) {die(‘ delete database failed: ‘.mysqli_error ($conn)); } echo “RUNOOB delete successfully \n”; mysqli_close($conn); ? >