Vim+MySQL
After dumping some MySQL tables, whose the structure is the follwing:
CREATE TABLE `mydata` (
`id` tinyint(10) NOT NULL auto_increment,
`content` varchar(20) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
INSERT INTO `mydata` VALUES ('1', 'First entry');
etc.
After dumping the tables, you want to drop the original tables from the database in order to replace the content; however, typing
DROP TABLE IF EXISTS `mydata`;
on each line would not be so easy if you had hundreds of tables.
You can fix that with vim : Edit the SQL file and execute the follwoing command:
:%s/\(^CREATE\ TABLE\ \)\(`.*`\)/DROP\ TABLE\ IF\ EXISTS\ \2\;\r&
Worked for me!
