日期:2014-05-16  浏览次数:20473 次

MYSQL批量插入数据最佳实践(MYISAM,InnoDB)

在使用MYSQL批量插入数据时我们一般可选的方式有:


?? *?长SQL? insert into table(xx,xx) values(xx,xx),(xx,xx)

? ?* 或者执行多个单条 INSERT INTO table(xx,xx)?VALUES (xx,xx);语句

? ?*?使用 LOAD DATA INFILE(导入)是SELECT...INTO OUTFILE(导出)

? ?*?使用 insert into ...select... 等


?? 但在使用这些方式之前,你可能得考虑一下执行速度问题。因为在MYSQL中的MyISAM与InnoDB引擎在读写操作执行效率有所不同。

?? 至于MyISAM与InnoDB的区别请看:

Advantages of InnoDB

InnoDB should be used where data integrity comes a priority because it inherently takes care of them by the help of relationship constraints and transactions.

Faster in write-intensive (inserts, updates) tables because it utilizes row-level locking and only hold up changes to the same row that’s being inserted or updated.

Disadvantages of InnoDB

Because InnoDB has to take care of the different relationships between tables, database administrator and scheme creators have to take more time in designing the data models which are more complex than those of MyISAM.

Consumes more system resources such as RAM. As a matter of fact, it is recommended by many that InnoDB engine be turned off if there’s no substantial need for it after installation of MySQL.

No full-text indexing .

?

Advantages of MyISAM

Simpler to design and create , thus better for beginners. No worries about the foreign relationships between tables.

Faster than InnoDB on the whole as a result of the simpler structure thus much less costs of server resources.

Full-text indexing .

Especially good for read-intensive (select) tables .

Disadvantages of MyISAM

No data integrity