Two ways for MySQL to delete a database: mysql
Use mysqladmin to delete a database
When you log on to the mysql server as a common user, you may need specific permissions to create or delete a MySQL database.
Therefore, we use the root user to log on. the root user has the highest permissions and can use the mysql mysqladmin command to create a database.
Exercise caution when deleting a database because all data will disappear after the DELETE command is executed.
The following instances Delete the database TUTORIALS (this database has been created in the previous chapter ):
[root@host]# mysqladmin -u root -p drop TUTORIALSEnter password:******
After executing the delete database command, a prompt box appears to confirm whether the database is 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 'TUTORIALS' database [y/N] yDatabase "TUTORIALS" dropped
Use a PHP script to delete a database
PHP uses the mysql_query function to create or delete a MySQL database.
This function has two parameters. TRUE is returned when execution is successful. Otherwise, FALSE is returned.
Syntax
bool mysql_query( sql, connection );
Parameters |
Description |
SQL |
Required. Specifies the SQL query to be sent. Note: The query string should not end with a semicolon. |
Connection |
Optional. Specifies the SQL connection identifier. If not specified, the last opened connection is used. |
Instance
The following example demonstrates how to use the PHP mysql_query function to delete a database:
<Html>
Note:When you use a PHP script to delete a database, you do not need to confirm whether to delete the information or delete the specified database directly. Therefore, you must be careful when deleting the database.
Address: http://www.manongjc.com/mysql/mysql_drop_database.html
Related reading:
Mysql join three table join query instances
Use functions in mysql select statements
Mysql order by sorts select query result sets
Mysql select and where substatement query result set
Mysql select retrieves or queries data from a table