Article directory
MySQLHow to delete the database?deleteMySQL databaseCommand/Syntax/Statement
MySQL delete database
drop database using mysqladmin
Log in to the mysql server as a normal user, you may need specific privileges to create or delete MySQL databases.
So we use the root user to log in here. The root user has the highest authority and can use the mysql mysqladmin command to create a database.
Be very careful when deleting a database, as all data will be gone after the delete command is executed.
The following example deletes the database chenweiliang (the database was created in the previous chapter):
[root@host]# mysqladmin -u root -p drop chenweiliang 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 'chenweiliang' database [y/N] y Database "chenweiliang" dropped
Delete database using PHP script
PHP uses the mysqli_query function to create or delete MySQL databases.
The function has two parameters and returns TRUE if the execution is successful, otherwise it returns FALSE.
grammar
mysqli_query(connection,query,resultmode);
参数 | Description |
---|---|
connection | Required.Specifies the MySQL connection to use. |
Query | Required, specifies the query string. |
result mode | Optional.a constant.Can be any of the following values:
|
Examples
The following example demonstrates the use of the PHP mysqli_query function to delete a database:
delete database
<? php $dbhost = 'localhost:3306'; // mysql服务器主机地址 $dbuser = 'root'; // mysql用户名 $dbpass = '123456'; // mysql用户名密码 $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('连接失败: ' . mysqli_error($conn)); } echo '连接成功 '; $sql = 'DROP DATABASE chenweiliang'; $retval = mysqli_query( $conn, $sql ); if(! $retval ) { die('删除数据库失败: ' . mysqli_error($conn)); } echo "数据库 chenweiliang 删除成功\n"; mysqli_close($conn); ?>
After successful execution, the number result is:
connection succeeded
Database chenweiliang deleted successfully
note: When deleting a database using a PHP script, the confirmation message will not appear, and the specified database will be deleted directly, so you should be very careful when deleting the database.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How does MySQL delete a database?Remove MySQL Database Commands/Syntax/Statements" to help you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-465.html
Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!