<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: MySQL Copy Table from One Database to Another</title>
	<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/</link>
	<description>Freelance PHP Ecommerce and SEO Developer in the UK</description>
	<pubDate>Tue, 06 Jan 2009 22:21:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
		<item>
		<title>By: admin</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-803</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 20 Nov 2008 12:05:53 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-803</guid>
		<description>note thats using this db_query function

[php]
function db_query($query){
	$output = mysql_query($query) or die('&lt;h1 style="color: red;"&gt;MySQL Error:&lt;/h1&gt;Please copy and paste between the lines and email to YOUREMAIL@ADDRESS.COM&lt;br&gt;&lt;br&gt;------------------------------------------------------------------------------------&lt;h3&gt;Query:&lt;/h3&gt;&lt;pre&gt;' . htmlentities($query) . '&lt;/pre&gt;&lt;h3&gt;MySQL Error:&lt;/h3&gt;' . mysql_error() . '&lt;br&gt;&lt;br&gt;------------------------------------------------------------------------------------');
	return $output;
}
[/php]</description>
		<content:encoded><![CDATA[<p>note thats using this db_query function</p>
<div class="igBar"><span id="lphp-1"><a href="#" onclick="javascript:showPlainTxt('php-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-1">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> db_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$output</span> = <a href="http://www.php.net/mysql_query"><span style="color:#000066;">mysql_query</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span> or <a href="http://www.php.net/die"><span style="color:#000066;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'&lt;h1 style=&quot;color: red;&quot;&gt;MySQL Error:&lt;/h1&gt;Please copy and paste between the lines and email to <a href="mailto:YOUREMAIL@ADDRESS.COM">YOUREMAIL@ADDRESS.COM</a>&lt;br&gt;&lt;br&gt;------------------------------------------------------------------------------------&lt;h3&gt;Query:&lt;/h3&gt;&lt;pre&gt;'</span> . <a href="http://www.php.net/htmlentities"><span style="color:#000066;">htmlentities</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'&lt;/pre&gt;&lt;h3&gt;MySQL Error:&lt;/h3&gt;'</span> . <a href="http://www.php.net/mysql_error"><span style="color:#000066;">mysql_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'&lt;br&gt;&lt;br&gt;------------------------------------------------------------------------------------'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$output</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-802</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 20 Nov 2008 12:04:32 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-802</guid>
		<description>Hi 

I made a little function for this query as per Julz advice

[php]
function backup_table($table_name, $backup_table_name){
	db_query("CREATE TABLE $backup_table_name LIKE $table_name");
	db_query("ALTER TABLE $backup_table_name DISABLE KEYS");
	db_query("INSERT INTO $backup_table_name SELECT * FROM $table_name");
	db_query("ALTER TABLE $backup_table_name ENABLE KEYS");
}
[/php]</description>
		<content:encoded><![CDATA[<p>Hi </p>
<p>I made a little function for this query as per Julz advice</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> backup_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$table_name</span>, <span style="color:#0000FF;">$backup_table_name</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; db_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"CREATE TABLE $backup_table_name LIKE $table_name"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; db_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"ALTER TABLE $backup_table_name DISABLE KEYS"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; db_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"INSERT INTO $backup_table_name SELECT * FROM $table_name"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; db_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"ALTER TABLE $backup_table_name ENABLE KEYS"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rigo</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-750</link>
		<dc:creator>rigo</dc:creator>
		<pubDate>Sun, 12 Oct 2008 19:56:44 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-750</guid>
		<description>Very useful tip, thanks to Julz and Admin</description>
		<content:encoded><![CDATA[<p>Very useful tip, thanks to Julz and Admin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tony</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-746</link>
		<dc:creator>tony</dc:creator>
		<pubDate>Fri, 03 Oct 2008 07:57:25 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-746</guid>
		<description>any one? please</description>
		<content:encoded><![CDATA[<p>any one? please</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tony</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-745</link>
		<dc:creator>tony</dc:creator>
		<pubDate>Thu, 02 Oct 2008 14:31:27 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-745</guid>
		<description>hi, i want to update my table2 with only the new data that i have entered from table1. hopefully on a daily basis

how wud i go about this? pls help

tony</description>
		<content:encoded><![CDATA[<p>hi, i want to update my table2 with only the new data that i have entered from table1. hopefully on a daily basis</p>
<p>how wud i go about this? pls help</p>
<p>tony</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-209</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Fri, 13 Jun 2008 08:47:38 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-209</guid>
		<description>Nice one Julz

Yes if you want to do more than simply backup the table data and want to actually make a proper fully functional copy of the table then the above is definitely the best way to do so.</description>
		<content:encoded><![CDATA[<p>Nice one Julz</p>
<p>Yes if you want to do more than simply backup the table data and want to actually make a proper fully functional copy of the table then the above is definitely the best way to do so.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julz</title>
		<link>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-208</link>
		<dc:creator>Julz</dc:creator>
		<pubDate>Thu, 12 Jun 2008 23:42:01 +0000</pubDate>
		<guid>http://www.edmondscommerce.co.uk/blog/mysql/mysql-copy-table-from-one-database-to-another/#comment-208</guid>
		<description>Just remember that this won't create the table using the same engine as the existing table and it won't recreate the primary keys or indexes.

To do this you have to use:

CREATE TABLE new_table_name LIKE old_table_name;

then you populate it with the data from the old table with:

INSERT INTO new_table_name SELECT * FROM old_table_name;

If the copied old table has many keys then it may help to speed the INSERT if you turn off the keys using the following before the INSERT:

ALTER TABLE new_table_name DISABLE KEYS;

And then after the INSERT:

ALTER TABLE new_table_name ENABLE KEYS;

These two statements are not supported by all MySQL Engine types though.  InnoDB being one of them in MySQL ver 5.x

Cheers
Julz</description>
		<content:encoded><![CDATA[<p>Just remember that this won't create the table using the same engine as the existing table and it won't recreate the primary keys or indexes.</p>
<p>To do this you have to use:</p>
<p>CREATE TABLE new_table_name LIKE old_table_name;</p>
<p>then you populate it with the data from the old table with:</p>
<p>INSERT INTO new_table_name SELECT * FROM old_table_name;</p>
<p>If the copied old table has many keys then it may help to speed the INSERT if you turn off the keys using the following before the INSERT:</p>
<p>ALTER TABLE new_table_name DISABLE KEYS;</p>
<p>And then after the INSERT:</p>
<p>ALTER TABLE new_table_name ENABLE KEYS;</p>
<p>These two statements are not supported by all MySQL Engine types though.  InnoDB being one of them in MySQL ver 5.x</p>
<p>Cheers<br />
Julz</p>
]]></content:encoded>
	</item>
</channel>
</rss>
