This is a very smart script to copy a mysql database (with contents) to another database or it simply duplicates/backups a mysql database
<? // Change the source & destination database // You don't need to create the destination database, only change the name below $source_db="db1"; $new_db="db2"; mysql_connect("localhost","root",""); mysql_select_db($source_db); $result=mysql_query("show tables"); $table_names=array(); while($row=mysql_fetch_array($result)){ $table_names[]=$row[0]; } mysql_query("create database $new_db"); mysql_select_db($new_db); for($i=0;$i<count($table_names);$i++){ mysql_query("create table ".$table_names[$i]." select * from $source_db.".$table_names[$i]); } echo count($table_names)." tables successfully copied!"; ?>
discuss this topic to forum
