I use the following command to know the create table structure.
mysqldump myDBName myTBName -d --compact
And I get the following output...
CREATE TABLE `tblThreads` (
`threadID` smallint(4) unsigned zerofill NOT NULL auto_increment,
`threadTitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`threadID`)
) ENGINE=MyISAM AUTO_INCREMENT=154 DEFAULT CHARSET=latin1 COMMENT='Forum threads';
I want to remove everything after AUTO_INCREMENT till the end of that line. But I want to retain the last semicolon ;
The engine can be MyISAM or InnoDB or Memory and so on. something like...
mysqldump myDBName myTBName -d --compact | grep --keep engine --remove others
zaxxon
November 6, 2008, 9:14am
2
Something like this?
root@isau02:/data/tmp/testfeld> cat infile
CREATE TABLE `tblThreads` (
`threadID` smallint(4) unsigned zerofill NOT NULL auto_increment,
`threadTitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`threadID`)
) ENGINE=MyISAM AUTO_INCREMENT=154 DEFAULT CHARSET=latin1 COMMENT='Forum threads';
root@isau02:/data/tmp/testfeld> sed 's/\(^.*AUTO_INCREMENT[^ ]*\) .*/\1;/g' infile
CREATE TABLE `tblThreads` (
`threadID` smallint(4) unsigned zerofill NOT NULL auto_increment,
`threadTitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`threadID`)
) ENGINE=MyISAM AUTO_INCREMENT=154;
I do not want auto_increment as well, but do want engine...
ENGINE=MyISAM ;
zaxxon
November 6, 2008, 9:32am
4
sed 's/\(.*ENGINE=MyISAM[^ ]*\) .*/\1;/g' infile
Thanks.
Only 2 points to note...
1) The engine can be something else like InnoDB and not necessarily MyISAM
2) Though it was not mentioned in the original question, is it possible to keep auto_increment but reset it to 0?
ENGINE=SomeThingChanging AUTO_INCREMENT=0;
zaxxon
November 6, 2008, 11:04am
6
sed 's/\(.*ENGINE.*AUTO_INCREMENT=\).*/\10;/g' infile
Perfect and amazing.
(I guess, mysqldump does not have any built-in tool to do this)
zaxxon
November 7, 2008, 12:55am
8
I doubt it. Check the man page or the online docu for mysqldump.