码迷,mamicode.com
首页 > 数据库 > 详细

DBA:多方式删库不跑路

时间:2018-08-30 00:14:23      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:删除数据库   form   cat   方式   database   root用户   需要   cte   ror   

语法;
drop database ‘DBname‘;

说明:普通mysql用户需要root用户赋特定删除或者创建的权限

温馨提醒:删除数据库请多次确认是否要删除,删除数据库是不可逆的操作。

一、MySQL内置删库

[root@mysql-linuxview ~]# 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删库

[root@mysql-linuxview ~]# 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
[root@mysql-linuxview ~]#

三、PHP删库

语法
mysqli_query(connection,query,resultmode);

参数说明:
技术分享图片

实例操作

[root@mysql-linuxview 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);
?>
[root@mysql-linuxview web]#

查看效果;
技术分享图片

技术分享图片

查看数据库:
MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| viewtest           |
+--------------------+
5 rows in set (0.00 sec)

MySQL [(none)]>

DBA:多方式删库不跑路

标签:删除数据库   form   cat   方式   database   root用户   需要   cte   ror   

原文地址:http://blog.51cto.com/leoheng/2166229

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!