[thelist] MySQL, copy between databases?
Hassan Schroeder
hassan at webtuitive.com
Tue Sep 30 18:23:19 CDT 2003
Ken Moore apparently didn't really want this answered after all,
but I realized after I sent it that it might be a useful tip, if
only because I've been up to my lower branches in DB gyrations for
the last week or so... :-)
<tip type="MySQL">
To copy one table to another, even from one MySQL DB to another:
/* assuming proper permissions on both DBs */
CREATE TABLE IF NOT EXISTS db2.table2 SELECT * FROM db1.table1
|_____________|
|_____________________________________| |________________________|
However, be aware that the "IF NOT EXISTS" only applies to the
CREATE TABLE part of the statement; whether it evaluates true or
false, the SELECT will occur.
So, if db2.table2 was previously created and there's a PRIMARY KEY
or other UNIQUE column, MySQL will report an error.
</tip>
--
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
dream. code.
More information about the thelist
mailing list