Maximum Number of Tables in MySQL

前端 未结 5 1311
野的像风
野的像风 2020-12-16 12:44

What is the maximum number of tables that MySQL can handle?

相关标签:
5条回答
  • 2020-12-16 12:51

    The fact that you are asking this question is probably an indicator that you are not taking a best practice approach to your problem.

    One potential situation where you could need a lot of tables is when you are developing multi-tenant application where for each tenant you create separate set of tables (let's say with tentantId as a table name prefix). See this article (part Data Isolation): http://www.javacodegeeks.com/2013/11/architecting-a-multi-tenant-application.html

    0 讨论(0)
  • 2020-12-16 12:54

    Here's an official answer from MySql: https://dev.mysql.com/doc/refman/8.0/en/database-count-limit.html

    8.4.5 Limits on Number of Databases and Tables

    MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories.

    MySQL has no limit on the number of tables. The underlying file system may have a limit on the number of files that represent tables. Individual storage engines may impose engine-specific constraints. InnoDB permits up to 4 billion tables.

    0 讨论(0)
  • 2020-12-16 13:09

    Contrary to Daniel Vassallo's answer, I have a use case where a large number of tables is needed. I could be wrong, but I don't think there is any "best practice" by which I could reduce the number of tables.

    Although it is probably correct that the number of tables is only limited by the OS, I just want to add that I am using well over 1000 tables in a database with pretty good performance. The only downside seems to be increased overhead for the .frm files. In my case, I have split a very large table into 1000+ separate tables with the same table structure. MySQL partitioning was not an option for me because of denormalization, which requires 2 copies of each record in separate tables.

    0 讨论(0)
  • 2020-12-16 13:10

    I also have a use case where a large number of tables is needed. At the moment one of our databases has close to 100.000 tables with excellent performance.

    As Rob Guinness mentioned, there is a significant overhead for the .frm files. It's also important to note that any queries into information_schema without limitations on the schema and if possible the table itself will result in a serious performance hit while the query runs.

    0 讨论(0)
  • 2020-12-16 13:11

    The fact that you are asking this question is probably an indicator that you are not taking a best practice approach to your problem.

    You may want to explain why you need to create many tables, in order to see if you will receive better suggestions on how to tackle this issue.

    However, there are no server limits on the number of tables in a MySQL database, but since each MyISAM table has associated files, then any OS limits on the number of files allowed will have an effect. InnoDB tables, indexes, etc, are stored in a single tablespace, with a maximum of two billion tables. (Source)

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