语法;
drop database ‘DBname‘;
说明:普通mysql用户需要root用户赋特定删除或者创建的权限
温馨提醒:删除数据库请多次确认是否要删除,删除数据库是不可逆的操作。
一、MySQL内置删库
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| linuxtest |
| linuxview |
| ltest |
| lvtest |
| mysql |
| performance_schema |
| sys |
| viewtest |
+--------------------+
9 rows in set (0.00 sec)
MySQL [(none)]> drop database lvtest;
Query OK, 0 rows affected (0.38 sec)
MySQL [(none)]>
二、MySQLadmin删库
[[email protected] ~]# mysqladmin -uroot -p drop linuxtest #drop后面填写要删除的数据库
Enter password:
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 ‘linuxtest‘ database [y/N] y #提示是否删除该数据库(不可逆)
Database "linuxtest" dropped
[[email protected] ~]#
三、PHP删库
语法
mysqli_query(connection,query,resultmode);
参数说明:
实例操作
[[email protected] web]# cat index.php
<?
$dbhost = ‘localhost:3306‘; //MySQL的服务器地址和端口
$dbuser = ‘root‘; //登录MySQL数据库用户名
$dbpass = ‘000000‘; //登录MySQL数据库用户密码
$conn = mysqli_connect($dbhost,$dbuser,$dbpass);
if ( ! $conn)
{
die(‘Could not connect:‘ . mysqli_error());
}
echo ‘connect success!!!<br />‘;
$vsql1 = ‘drop database linuxview‘;
$retval = mysqli_query($conn,$vsql1);
if ( ! $retval)
{
die(‘删除数据库失败:‘ . mysqli_query($conn));
}
echo "删除数据库linuxview成功\n";
mysqli_close($conn);
?>
[[email protected] web]#
查看效果;
查看数据库:
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| viewtest |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]>
原文地址:http://blog.51cto.com/leoheng/2166229
时间: 2024-10-09 13:16:18