Use ordinary users to log in to the MySQL server. You may need specific permissions to create or delete MySQL databases, so we use the root user to log in here, and the root user has the highest permissions.
In the process of deleting the database, you must be very careful, because after executing the delete command, all data will disappear.
drop command to delete database
drop command format:
drop database ;
For example, delete the database named RUNOOB:
mysql> drop database RUNOOB;
Use mysqladmin to delete the database
You can also use the mysql mysqladmin command to execute the delete command in the terminal.
The following instance deletes the database RUNOOB (the database was created in the previous chapter):
[[emailprotected]]# mysqladmin -u root -p drop RUNOOB Enter password:******
After executing the above delete database command, a prompt box will appear to confirm whether to delete the database:
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' dat abase [y/N] y Database "RUNOOB" dropped span>
Use PHP script to delete database
PHP uses mysqli_query function to create or delete MySQL database.
This function has two parameters, it returns TRUE when the execution is successful, otherwise it returns FALSE.
Syntax
mysqli_query(connection,query,resultmode); span>
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to be used. |
query | Required, specifies the query string. |
resultmode |
Optional. A constant. Can be any of the following values:
|
Example
The following example demonstrates the use of PHP mysqli_query function to delete a database:
Delete database
After successful execution, count The result is:
Note : When you delete a database using a PHP script, there will be no confirmation message to delete, and the specified database will be deleted directly, so you must be careful when deleting the database.
Delete database