Home > Database > Mysql Tutorial > body text

删除MySQL数据库的简单教程_MySQL

WBOY
Release: 2016-06-01 13:00:27
Original
825 people have browsed it

 使用mysqladmin删除数据库:

需要特殊的权限才能创建或删除一个MySQL数据库。因此,假设以root用户的访问,可以使用mysql mysqladmin二进制创建任何数据库。

小心删除任何数据库,因为它会失去数据库中可用的所有数据。

[root@host]# mysqladmin -u root -p drop TUTORIALS
Enter password:******

Copy after login

使用PHP脚本删除数据库:

PHP使用mysql_query函数来创建或删除一个MySQL数据库。这个函数有两个参数,成功返回TRUE或失败则返回FALSE。
例子:

bool mysql_query( sql, connection );
Copy after login

2015526102333231.jpg (654×119)

例子:

试试下面的例子中,删除一个数据库:

<html>
<head>
<title>Deleting MySQL Database - by www.jb51.com</title>
</head>
<body>
<&#63;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 successfully\n";
mysql_close($conn);
&#63;>
</body>
</html>

Copy after login

警告: 在删除一个数据库,使用PHP脚本,它不会提示任何确认。所以删除一个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