php大量刪除資料庫下指定首碼的表以prefix_為例,大量刪除prefix_PHP教程

來源:互聯網
上載者:User

php大量刪除資料庫下指定首碼的表以prefix_為例,大量刪除prefix


如何用php大量刪除資料庫下所有首碼為prefix_的表。

例子,統一刪除首碼為“prefix_”的表。

<?php //設定資料庫連接資訊。資料庫伺服器地址,資料庫使用者名稱,資料密碼 mysql_connect('資料庫主機','資料庫使用者名稱','資料庫密碼'); //設定查詢的資料庫名稱 mysql_select_db('資料庫名'); $rs=mysql_query('show tables'); while($arr=mysql_fetch_array($rs)) { //設定要大量刪除的資料庫表首碼,如:prefix_ $TF=strpos($arr[0],'prefix_'); if($TF===0){ $FT=mysql_query("drop table $arr[0]"); if($FT){ echo "$arr[0] 刪除成功!
"; } } } ?>

操作執行個體:

建立一個php檔案,儲存為deletedata.php。
比如,要刪除www.jb51.net或者http://www.bkjia.com/的後台資料,操作兩個步驟就ok:

1. 首先將這個儲存好的deletedata.php檔案上傳至你的網站根目錄;

2. 直接在地址欄輸入:www.jb51.net/deletedata.php或者http://www.bkjia.com/deletedata.php執行這個刪除指令碼即中。
該指令碼會在瀏覽器中顯示出所有表刪除成功的資訊。


mysql 資料庫大量刪除同一首碼的資料表

先建立一個刪除指令碼

運行下語句
select 'drop table '+name from sysobjects where type='U' and name like 'B%'

會出來查詢結果,將查詢結果複製出來
然後在資料庫123中運行複製出來的查詢結果
 

mysql尋找一個資料庫中所有特定首碼的表

php 不會。

mysql 裡面, 查詢 表的資訊, 我倒是會的。

是從 information_schema.tables 這裡查詢的。

下面是一個例子:

mysql> SELECT table_name, table_type, engine
-> FROM information_schema.tables
-> WHERE table_schema = 'test'
-> ORDER BY table_name DESC;
-> //
+--------------------+------------+--------+
| table_name | table_type | engine |
+--------------------+------------+--------+
| v_sale_report_x | VIEW | NULL |
| v_sale_report | VIEW | NULL |
| union_tab_2 | BASE TABLE | InnoDB |
| union_tab_1 | BASE TABLE | InnoDB |
| test_trigger_table | BASE TABLE | InnoDB |
| test_tab2 | BASE TABLE | InnoDB |
| test_tab | BASE TABLE | InnoDB |
| test_main | BASE TABLE | InnoDB |
| test_dysql | BASE TABLE | InnoDB |
| test_create_tab4 | BASE TABLE | InnoDB |
| test_create_tab2 | BASE TABLE | InnoDB |
| test_create_tab1 | BASE TABLE | InnoDB |
| test_create_tab | BASE TABLE | InnoDB |
| sale_report | BASE TABLE | InnoDB |
| log_table | BASE TABLE | InnoDB |
+--------------------+------------+--------+
15 rows in set (0.02 sec)
 

http://www.bkjia.com/PHPjc/868485.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/868485.htmlTechArticlephp大量刪除資料庫下指定首碼的表以prefix_為例,大量刪除prefix 如何用php大量刪除資料庫下所有首碼為prefix_的表。 例子,統一刪除首碼為“...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.