简体   繁体   English

将表类型更改为 InnoDB

[英]Changing table type to InnoDB

I have a myisam only dedicated 32 GB RAM mysql server that is running on default configuration.我有一个 myisam 只有专用的 32 GB RAM mysql 服务器,它在默认配置下运行。 I want to change the engine type to InnoDB of one table in order to avoid table locks.为了避免表锁,我想将引擎类型更改为一张表的InnoDB。 It has 50 million records and size on disk is around 15 GB.它有 5000 万条记录,磁盘大小约为 15 GB。 I am using mysql version 5.5 I guess I will need to add the following options and restart mysql.我正在使用 mysql 版本 5.5 我想我需要添加以下选项并重新启动 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?更改发动机类型时还需要考虑什么?

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....如果表真的很大,可能需要一段时间,并且会占用大量 CPU……

First of all check if your database supports InnoDB engine (I bet it is supported;)):首先检查你的数据库是否支持 InnoDB 引擎(我敢打赌它是支持的;)):

SHOW ENGINES\G

If so, there is already default innodb related parameters in place, check them with:如果是这样,已经有默认的innodb 相关参数,检查它们:

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.即使您使用默认参数,您现在也可以使用 InnoDB 表。

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;如果你只想创建 InnoDB 表,你可以更改你的默认存储引擎,或者为你当前的 session 使用: SET storage_engine=INNODB; or in your config using default-storage-engine option.或者在您的配置中使用default-storage-engine选项。

By the way, the fastest way to convert a table to InnoDB is not the above described way.顺便说一句,将表转换为 InnoDB 的最快方法不是上面描述的方法。 One can do the following to convert a table to InnoDB by simply inserting the data:可以执行以下操作,通过简单地插入数据将表转换为 InnoDB:

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.当然,您必须手动添加所需的索引,但与ALTER TABLE...在稍大的表上相比,它通常值得您节省时间(和痛苦)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM