When should you choose to use InnoDB in MySQL?

前端 未结 10 2122
感情败类
感情败类 2020-12-24 14:50

I am rather confused by the hurt-mongering here.

I know how to do them, see below, but no idea why? What are they for?

create table orders (         


        
相关标签:
10条回答
  • 2020-12-24 15:26

    Always. Unless you need to use MySQL's full-text search or InnoDB is disabled in your shared webhost.

    0 讨论(0)
  • 2020-12-24 15:32

    A supplement to Machine and knoopx's answer about transactions:

    The default MySQL table type, MyISAM, does not support transactions. BerkeleyDB and InnoDB are the transaction-safe table types available in open source MySQL, version 3.23.34 and greater.

    The definition of the transaction and an banking example

    A transaction is a sequence of individual database operations that are grouped together. -- A good example where transactions are useful is in banking.

    Source of the citations

    0 讨论(0)
  • 2020-12-24 15:35

    In general for me the most important point is that InnoDB offers per row locking, while MyISAM does look per table. On big tables with a lot of writes this might make a big performance issue.

    On the otherhand MyISAM table have a easier file structure, copying and repairing table on file level is way easier.

    0 讨论(0)
  • 2020-12-24 15:36

    InnoDB is a storage engine in MySQL. There are quite a few of them, and they all have their pros and cons. InnoDB's greatest strengths are:

    • Support for transactions (giving you support for the ACID property).
    • Row-level locking. Having a more fine grained locking-mechanism gives you higher concurrency compared to, for instance, MyISAM.
    • Foreign key constraints. Allowing you to let the database ensure the integrity of the state of the database, and the relationships between tables.
    0 讨论(0)
  • 2020-12-24 15:36

    You may be interested in this article from Database Journal which discusses the InnoDB table type in MySQL.

    Excerpt:

    Last month we looked at the HEAP table type, a table type which runs entirely in memory. This month we look at setting up the InnoDB table type, the type of most interest to serious users. The standard MyISAM table type is ideal for website use, where there are many reads in comparison to writes, and no transactions. Where these conditions do not apply (and besides websites, they do not apply often in the database world), the InnoDB table is likely to be the table type of choice. This article is aimed at users who are familiar with MySQL, but have only used the default MyISAM table type.

    I wouldn't be put off by the other question. Keep proper backups of your database, of any type -- and don't drop tables by accident ;-) -- and you'll be ok whatever table type you choose.

    0 讨论(0)
  • 2020-12-24 15:38

    In your example, you create foreign keys. Foreign keys are only supported for InnoDB tables, not for MyISAM tables.

    0 讨论(0)
提交回复
热议问题