<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MySQL: how to drop multiple tables using single query</title>
	<atom:link href="http://www.phpmag.ru/2009/03/05/mysql-how-to-drop-multiple-tables-using-single-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpmag.ru/2009/03/05/mysql-how-to-drop-multiple-tables-using-single-query/</link>
	<description>Phrozn, Phing &#38; Zend Framework Musings</description>
	<lastBuildDate>Tue, 15 Nov 2011 15:38:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Rene</title>
		<link>http://www.phpmag.ru/2009/03/05/mysql-how-to-drop-multiple-tables-using-single-query/comment-page-1/#comment-1804</link>
		<dc:creator>Rene</dc:creator>
		<pubDate>Tue, 05 Jul 2011 12:25:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpmag.ru/?p=467#comment-1804</guid>
		<description>Hi,

if you can use php try this:

$delete_array = mysql_query(&quot;SHOW TABLE STATUS LIKE &#039;x__%&#039;&quot;);
while ($delete = mysql_fetch_array($delete_array)) {
    mysql_query(&quot;DROP TABLE &quot; . $delete[&#039;Name&#039;]);
}

greetz

Rene</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>if you can use php try this:</p>
<p>$delete_array = mysql_query(&#8220;SHOW TABLE STATUS LIKE &#8216;x__%&#8217;&#8221;);<br />
while ($delete = mysql_fetch_array($delete_array)) {<br />
    mysql_query(&#8220;DROP TABLE &#8221; . $delete['Name']);<br />
}</p>
<p>greetz</p>
<p>Rene</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deej</title>
		<link>http://www.phpmag.ru/2009/03/05/mysql-how-to-drop-multiple-tables-using-single-query/comment-page-1/#comment-1709</link>
		<dc:creator>deej</dc:creator>
		<pubDate>Thu, 24 Feb 2011 10:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpmag.ru/?p=467#comment-1709</guid>
		<description>If you have shell access try this simple script:

create a ~/.my.cnf with:

[client]
user = dbuserid
password = dbpassword
host = mysql_server

[mysql]
database = dbname

Now create the following shell script:

drop_tables.sh
#!/usr/bin/tcsh

if ($#argv != 1) then
echo &quot;Usage: $0 table_prefix&quot;
echo e.g. $0 wp
exit 1
endif

foreach i ( `mysql -e &quot;show tables like &#039;$1_%&#039;&quot; &#124; grep -v Tables_in_ ` )
echo mysql -e &quot;drop table $i&quot;
mysql -e &quot;drop table $i&quot;
end

exit 0

Handy for clearing out joomla and wordpress installs</description>
		<content:encoded><![CDATA[<p>If you have shell access try this simple script:</p>
<p>create a ~/.my.cnf with:</p>
<p>[client]<br />
user = dbuserid<br />
password = dbpassword<br />
host = mysql_server</p>
<p>[mysql]<br />
database = dbname</p>
<p>Now create the following shell script:</p>
<p>drop_tables.sh<br />
#!/usr/bin/tcsh</p>
<p>if ($#argv != 1) then<br />
echo &#8220;Usage: $0 table_prefix&#8221;<br />
echo e.g. $0 wp<br />
exit 1<br />
endif</p>
<p>foreach i ( `mysql -e &#8220;show tables like &#8216;$1_%&#8217;&#8221; | grep -v Tables_in_ ` )<br />
echo mysql -e &#8220;drop table $i&#8221;<br />
mysql -e &#8220;drop table $i&#8221;<br />
end</p>
<p>exit 0</p>
<p>Handy for clearing out joomla and wordpress installs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris</title>
		<link>http://www.phpmag.ru/2009/03/05/mysql-how-to-drop-multiple-tables-using-single-query/comment-page-1/#comment-1058</link>
		<dc:creator>chris</dc:creator>
		<pubDate>Thu, 29 Apr 2010 11:02:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpmag.ru/?p=467#comment-1058</guid>
		<description>Sometimes you will encounter to drop table many tables with lengthy names and it will be possible to excess the default length of group_concat can return . You can just edit the config file of mysql or make use of the function below to work-around this:
function drop_tables($host , $user , $password , $dbname , $prefix = &#039;&#039;)
{
	
	$con = mysql_connect($host , $user , $password );
	if (!$con)
	  {
	  die(&#039;Could not connect: &#039; . mysql_error());
	  }
	$array = array();
	$sql = &quot;SELECT table_name
			FROM information_schema.TABLES
			WHERE TABLE_SCHEMA = &#039;$dbname&#039; &quot;;
	if(empty($prefix))
		$sql .= &quot;AND TABLE_NAME LIKE &#039;%%&#039;&quot;;
	else
		$sql .= &quot;AND TABLE_NAME LIKE &#039;$prefix%&#039;&quot;;

	$result = mysql_query($sql,$con) or die( mysql_error());
	while($row = mysql_fetch_assoc($result))
	{
		$array[] = $row[&#039;table_name&#039;];
	}

	$sql = &quot;DROP table &quot;.implode(&quot;,&quot; , $array);
	
	mysql_close($con);
	
	return $sql;

}</description>
		<content:encoded><![CDATA[<p>Sometimes you will encounter to drop table many tables with lengthy names and it will be possible to excess the default length of group_concat can return . You can just edit the config file of mysql or make use of the function below to work-around this:<br />
function drop_tables($host , $user , $password , $dbname , $prefix = &#8221;)<br />
{</p>
<p>	$con = mysql_connect($host , $user , $password );<br />
	if (!$con)<br />
	  {<br />
	  die(&#8216;Could not connect: &#8216; . mysql_error());<br />
	  }<br />
	$array = array();<br />
	$sql = &#8220;SELECT table_name<br />
			FROM information_schema.TABLES<br />
			WHERE TABLE_SCHEMA = &#8216;$dbname&#8217; &#8220;;<br />
	if(empty($prefix))<br />
		$sql .= &#8220;AND TABLE_NAME LIKE &#8216;%%&#8217;&#8221;;<br />
	else<br />
		$sql .= &#8220;AND TABLE_NAME LIKE &#8216;$prefix%&#8217;&#8221;;</p>
<p>	$result = mysql_query($sql,$con) or die( mysql_error());<br />
	while($row = mysql_fetch_assoc($result))<br />
	{<br />
		$array[] = $row['table_name'];<br />
	}</p>
<p>	$sql = &#8220;DROP table &#8220;.implode(&#8220;,&#8221; , $array);</p>
<p>	mysql_close($con);</p>
<p>	return $sql;</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://www.phpmag.ru/2009/03/05/mysql-how-to-drop-multiple-tables-using-single-query/comment-page-1/#comment-808</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Fri, 30 Oct 2009 14:14:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpmag.ru/?p=467#comment-808</guid>
		<description>Thanks!

Exactly what I needed.</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
<p>Exactly what I needed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

