I am backing up several tables via a PHP script. The script lists the tables, you click on one, then click "backup table" and the table is backed up (the new table name is the old table name appended with the date of the backup, so table 'orders' would become 'orders_043007').
The problem is the size of the backed up table. They always end up being 6x larger than the original table.
I backed up one table last night that had a size of 31.8 MB and the backup was 197.4 MB, according to the data in phpMyAdmin.
The SQL I am using to do the backup is:
The other thing I am doing after the copy / creation is I am setting the primary keys:
Anybody have any ideas or thoughts as to why this large increase in size might be happening?
The problem is the size of the backed up table. They always end up being 6x larger than the original table.
I backed up one table last night that had a size of 31.8 MB and the backup was 197.4 MB, according to the data in phpMyAdmin.
The SQL I am using to do the backup is:
PHP:
$dateString = date('mdy');
$newTable = $_POST[buTable] . "_$dateString";
$sql = "CREATE TABLE $newTable AS SELECT * FROM $_POST[buTable]";
The other thing I am doing after the copy / creation is I am setting the primary keys:
PHP:
# add primary keys
$pk = array (
'AUTO_ORDER' => 'ID',
'CB_ITEMS' => 'id',
'CB_ITEMS_CLOSED' => 'id',
'CB_ORDERS' => 'number',
'CB_ORDERS_CLOSED' => 'number',
'CREDITS' => 'id',
'CUSTOMER' => 'custID',
'product' => 'id',
'RESUBMITS' => 'id',
);
$pk_type = array (
'AUTO_ORDER' => 'int',
'CB_ITEMS' => 'bigint',
'CB_ITEMS_CLOSED' => 'bigint',
'CB_ORDERS' => 'bigint',
'CB_ORDERS_CLOSED' => 'bigint',
'CREDITS' => 'bigint',
'CUSTOMER' => 'bigint',
'product' => 'int',
'RESUBMITS' => 'bigint',
);
$sql = "ALTER TABLE $newTable ADD PRIMARY KEY({$pk[$_POST[buTable]]})";
$result = mysql_db_query($db_name,$sql,$db_connect);
if(mysql_error($db_connect)) {die("Error:<br>SQL: $sql<br>Error: " . mysql_error($db_connect) . "<br>");}
$sql = "ALTER TABLE $newTable CHANGE {$pk[$_POST[buTable]]} {$pk[$_POST[buTable]]} {$pk_type[$_POST[buTable]]} NOT NULL AUTO_INCREMENT";
$result = mysql_db_query($db_name,$sql,$db_connect);
if(mysql_error($db_connect)) {die("Error:<br>SQL: $sql<br>Error: " . mysql_error($db_connect) . "<br>");}
main("Backed up Table: $_POST[buTable]");
Anybody have any ideas or thoughts as to why this large increase in size might be happening?




