DBA:多方式刪庫不跑路
阿新 • • 發佈:2018-08-30
sql 用戶密碼 分享 不可 die oss command current to do
語法;
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:多方式刪庫不跑路