开发者

Does MYSQL truncate a table when the tables size limit is reached?

开发者 https://www.devze.com 2023-03-02 19:32 出处:网络
I have been pouring over the MYSQL documentation trying to determine if my script or MYSQL itself is causing a truncation of a large table. The basic behavior I am seeing:

I have been pouring over the MYSQL documentation trying to determine if my script or MYSQL itself is causing a truncation of a large table. The basic behavior I am seeing:

  • A PHP script is kicked off from the browser to select rows from a MSSQL table and immediately insert them into a local MySQL database table.
  • After determining the number of rows in MSSQL, my script breaks down the select into chunks to avoid any out of memory issues.
  • The script then truncates the local table and starts to import the data by iterating over the chunks
  • Following the data in MySQL directly, I see the table close in on ~20开发者_JAVA技巧0,000 rows and then suddenly the table truncates and the count starts over
  • I would think that I would see some errors about the table being full and I didn't think MySQL would truncate the table if the table limit was reached.

Can anyone confirm whether or not MySQL would truncate a table automatically if the table limit is reached or a setting to check to turn off such behavior?


No MySQL sets no hard limits on the size of the table, but there are some limits...

Explicit table size
You can set the max table size with

ALTER TABLE tbl_name MAX_ROWS=200000

You can see the current settings for table size with

SHOW TABLE STATUS FROM db_name LIKE 'tbl_name';

See: http://dev.mysql.com/doc/refman/5.0/en/full-table.html

Note that MAX_ROWS is:

The maximum number of rows you plan to store in the table. This is not a hard limit, but rather a hint to the storage engine that the table must be able to store at least this many rows.

Filesystem limits
MySQL 5.x has a default tablesize of 256TB, but if your filesystem does not allow files > 4GB, that might be a limit that can cause this behaviour as well.

Memory limits
If you're using the memory (heap) engine, your table size is determined by the max_heap_table_size system variable.


I don't think MySQL is truncating your data, I'v worked with tables with 500,000 rows or more and I had no problems at all. So, I think you better watch out your PHP Script or at least the PHP configuration, all the timeouts setting and size of the scripts that PHP can handle.

  • max_execution_time
  • max_input_time
  • memory_limit

I hope this could help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消