Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

MySQL deletes the data table


May 15, 2021 MySQL


Table of contents


MySQL deletes the data table

Deleting data tables in MySQL is very easy to do, but you should be very careful when you delete tables again, because all data disappears after the delete command is executed.

Grammar

Here's a common syntax for deleting MySQL data tables:

DROP TABLE table_name ;

Delete the data table in the command prompt window

Remove the data sheet SQL statement as DROP TABLE in the mysql?command prompt window:

Instance

The following instances remove the data w3cschool_tbl:

root@host# mysql -u root -p
Enter password:*******
mysql> use W3CSCHOOL;
Database changed
mysql> DROP TABLE w3cschool_tbl
Query OK, 0 rows affected (0.8 sec)
mysql>

Use the PHP script to delete the data table

PHP uses mysql_query function to remove mySQL data tables.

The function has two arguments that return TRUE if executed successfully, otherwise FALSE is returned.

h3 syntax
bool mysql_query( sql, connection );
Parameters Describe
Sql Necessary. S pecify the SQL query to send. Note: The query string should not end with a sign.
connection Optional. S pecifies the SQL connection identifier. If not specified, the last open connection is used.

Instance

The following example uses a PHP script to delete the data w3cschool_tbl:

<html>
<head>
<meta charset="utf-8">
<title>创建 MySQL 数据表</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 TABLE w3cschool_tbl";
mysql_select_db( 'W3CSCHOOL' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('数据表删除失败: ' . mysql_error());
}
echo "数据表删除成功\n";
mysql_close($conn);
?>
</body>
</html>