Home >Database >Mysql Tutorial >MySQL delete database (delete) 2 methods
This article mainly introduces in detail the two methods of deleting the database in MySQL. Interested friends can refer to it.
First method: Use mysqladmin to delete the database
Use a normal user to log in to the mysql server. You may need specific permissions to create or delete a MySQL database.
So we use the root user to log in. The root user has the highest authority and can use the mysql mysqladmin command to create the database.
Be very careful when deleting a database because all data will disappear after executing the delete command.
The following example deletes the database TUTORIALS (the database was created in the previous chapter):
[root@host]# mysqladmin -u root -p drop TUTORIALS
Enter password:******
After executing the above command to delete the database, a prompt 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 'TUTORIALS' database [y/N] y Database "TUTORIALS" dropped
Second method: Use PHP script to delete the database
PHP uses mysql_query function to create or delete a MySQL database.
This function takes two parameters and returns TRUE if the execution is successful, otherwise it returns FALSE.
grammar
bool mysql_query( sql, connection );
Example
The following example demonstrates using the PHP mysql_query function to delete a database:
<html> <head> <title>Deleting MySQL Database</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('连接失败: ' . mysql_error()); } echo '连接成功<br />'; $sql = 'DROP DATABASE TUTORIALS'; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('删除数据库失败: ' . mysql_error()); } echo "数据库 TUTORIALS 删除成功\n"; mysql_close($conn); ?> </body> </html>
Note: When using a PHP script to delete a database, no confirmation message will appear, and the specified database will be deleted directly, so you should be particularly careful when deleting the database.
The above is the detailed content of MySQL delete database (delete) 2 methods. For more information, please follow other related articles on the PHP Chinese website!