MySQL Delete Database To delete a database using mysqladmin
Using a normal user to log on to the MySQL server, you may need specific permissions to create or delete the MySQL database.
So here we are using the root user login, the root user has the highest privileges, you can use the MySQL mysqladmin command to create a database.
It is important to be careful when you delete a database, because all data disappears after the delete command is executed.
The following instance deletes the database tutorials (the database was created in the previous section):
[[email protected]]#--p Drop tutorialsEnter password:* * * * * *
After you execute the delete database command above, a prompt box appears to confirm that the database is actually deleted:
Dropping is does. Any in the database would be destroyed. Do' tutorials '[y/N] yDatabase"Tutorials" dropped
Delete a database using a PHP script
PHP uses the Mysql_query function to create or delete MySQL databases.
The function has two parameters, returns TRUE on successful execution, or FALSE.
Grammar
BOOL mysql_query( sql,);
Parameters |
Description |
Sql |
Necessary. Specifies the SQL query to send. Note: The query string should not end with a semicolon. |
Connection |
Optional. Specifies the SQL connection identifier. If not specified, the previous open connection is used. |
Instance
The following example demonstrates using the PHP mysql_query function to delete a database:
<title>Deleting MySQL Database</title><body><?Php$dbhost= ' localhost:3036 ';$dbuser= ' Root ';$dbpass= ' Rootpassword ';$conn=Mysql_connect($dbhost,$dbuser,$dbpass);If(!$conn){ Die(' Connection failed: ' .Mysql_error());}Echo' Connection succeeded <br/> ';$sql= ' DROP DATABASE Tutorials ';$retval=Mysql_query( $sql , $conn if (! $retval ) { die ( ' delete database failed: ' Mysql_error ()); }echo "database tutorials Delete succeeded \ n" mysql_close ( $conn ?></body>
Note: When you delete a database using a PHP script, there is no confirmation of whether to delete the information or delete the specified database, so you should be careful when deleting the database.
MySQL Delete Database