shantanuo
shantanuo

Reputation: 32316

Changing table type to InnoDB

I have a myisam only dedicated 32 GB RAM mysql server that is running on default configuration. I want to change the engine type to InnoDB of one table in order to avoid table locks. It has 50 million records and size on disk is around 15 GB. I am using mysql version 5.5 I guess I will need to add the following options and restart mysql.

innodb_buffer_pool_size=1G
innodb_log_file_size=100M
innodb_file_per_table=1

What else is considered to be necessary while changing the engine type?

Upvotes: 7

Views: 11050

Answers (2)

Flo Doe
Flo Doe

Reputation: 5381

First of all check if your database supports InnoDB engine (I bet it is supported ;)):

SHOW ENGINES\G

If so, there is already default innodb related parameters in place, check them with:

SHOW VARIABLES LIKE '%innodb%'

and try to understand them and alter the to your specific needs. Even if you use the default params, you are now fine to play arround with InnoDB tables.

If you want to create only InnoDB tables, you can change your default storage engine, either for your current session with: SET storage_engine=INNODB; or in your config using default-storage-engine option.

By the way, the fastest way to convert a table to InnoDB is not the above described way. One can do the following to convert a table to InnoDB by simply inserting the data:

CREATE TABE new AS SELECT * FROM old WHERE 1<>1;
ALTER TABLE new ENGINE = INNODB;
INSERT INTO new SELECT * FROM old;

Of course you have to add the indexes you need manually, but its usually worth the time (and pain) you save compared to the ALTER TABLE ... on slightly bigger tables.

Upvotes: 7

Jonathan Barlow
Jonathan Barlow

Reputation: 1075

You'll actually be running a command to convert each table.

It goes faster to first sort the table:

ALTER TABLE tablename ORDER BY primary_key_column;

Then, run the alter command:

ALTER TABLE tablename ENGINE = INNODB;

It might take a while if the table is really large, and it will use a lot of your CPU....

Upvotes: 18

Related Questions