July 30, 2008

Quick tip: how to convert tables to InnoDB

Posted by Baron Schwartz

I use Maatkit for a lot of grunt work and thought you might appreciate this quick tip. Suppose you have a bazillion tables to convert from MyISAM to InnoDB, but they are mixed in with other tables that are already InnoDB, or are another storage engine that you don't want to touch.

CODE:
  1. mk-find <db_name> --engine MyISAM --exec "ALTER TABLE %D.%N ENGINE=INNODB" --print

Here's a bonus tip, while I'm at it. I had a client a while back whose application creates tables as needed, so they had about 90,000 tables in a bunch of different databases, all named things like user_123_456_friends. I wanted to add an index to them -- but not to the ones named friends_123_456_user.

CODE:
  1. mk-find <db_name> --tblregex '^user_\d+_\d+_friends$' --exec 'ALTER TABLE %D.%N ADD KEY(site_id)'

Boy, is that a lot easier than adding indexes to 90k tables by hand!

Related posts: :Fixing column encoding mess in MySQL::Quick look at Ubuntu 6.06::JOIN Performance & Charsets:
 

3 Comments »

  1. Sounds interesting,

    but, one questions …. if you are allowed to answer it….. 90k tables for what ??

    isnt this a perfomance break itself ?

    Comment :: July 30, 2008 @ 1:59 pm

  2. Oh yeah, that was definitely a design flaw :-) This site was in serious trouble. But that’s another story.

    Comment :: July 30, 2008 @ 2:10 pm

  3. 3. kostja

    You could write a stored procedure that uses dynamic sql for the same thing. ALTER TABLE works in dynamic sql.

    Comment :: August 7, 2008 @ 10:41 am

 



Subscribe without commenting


This page was found by: convert all tables t... alter all tables to ... mysql convert to inn... mysql converting eng... converting tables to...