Home > Database > Mysql Tutorial > Mysql 删除数据库drop database

Mysql 删除数据库drop database

WBOY
Release: 2016-06-01 09:58:18
Original
1224 people have browsed it

方法-:使用cmd模式下载删除

<code>mysql> drop database school;</code>
Copy after login

此命名删除了school数据库。但如果school数据库不存在就会报错。所以完整的语句应该这么写:

<code>mysql> drop database if exists school;</code>
Copy after login

 

方法二:PHP脚本删除数据库

在php中,我们可以使用mysql_query函数来执行sql语句。 所以删除数据库时,我们可以直接用mysql_query来执行删除命令。

<code class="language-php"><?php $dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$sql = 'DROP DATABASE TUTORIALS';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not delete database: ' . mysql_error());
}
echo "Database TUTORIALS deleted successfullyn";
mysql_close($conn);
?></code>
Copy after login

好了,关于mysql drop database就介绍这么多。如果小伙伴想了解更多关于mysql的知识,可以阅读本文网站的《mysql 教程》

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template