I’m currently dumping MySQL tables with mysqldump.
The dump is currently producing:
DROP TABLE IF EXISTS `versions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `versions` (
`major` int(11) NOT NULL DEFAULT '0',
`minor` int(11) NOT NULL DEFAULT '0',
`revision` int(11) NOT NULL DEFAULT '0',
`build` int(11) NOT NULL DEFAULT '0',
`date_installed` datetime NOT NULL,
`current` tinyint(4) NOT NULL DEFAULT '0',
`product_type` varchar(30) DEFAULT NULL,
`product` varchar(30) DEFAULT NULL,
`product_class_name` varchar(80) DEFAULT NULL,
`lazy_load` tinyint(4) NOT NULL DEFAULT '0',
`sitewide` tinyint(4) NOT NULL DEFAULT '0',
UNIQUE KEY `versions_pkey` (`product`,`major`,`minor`,`revision`,`build`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
What I’d like the dump to say is something like,
IF TABLE EXISTS, UPDATE IT TO MATCH THIS STRUCTURE (
`major` int(11) NOT NULL DEFAULT '0',
`minor` int(11) NOT NULL DEFAULT '0',
`revision` int(11) NOT NULL DEFAULT '0',
`build` int(11) NOT NULL DEFAULT '0',
`date_installed` datetime NOT NULL,
`current` tinyint(4) NOT NULL DEFAULT '0',
`product_type` varchar(30) DEFAULT NULL,
`product` varchar(30) DEFAULT NULL,
`product_class_name` varchar(80) DEFAULT NULL,
`lazy_load` tinyint(4) NOT NULL DEFAULT '0',
`sitewide` tinyint(4) NOT NULL DEFAULT '0',
UNIQUE KEY `versions_pkey` (`product`,`major`,`minor`,`revision`,`build`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Is this possible through MySQL dump (or indeed any other MySQL-related tools)?
Thanks
You may need to dump the schema ahead of time and convert
CREATE TABLEtoCREATE TABLE IF NOT EXISTSThis will bypass adding the
DROP TABLE IF EXISTS versions;command and transformCREATE TABLEintoCREATE TABLE IF NOT EXISTS.Give it a Try !!!