插入255行后MySQL停止

时间:2011-08-11 02:39:37

标签: php mysql

我有一个非常大的数据库表,我需要根据不同的原因拆分成较小的表。

通过php接近此示例进行处理:

// Note: It's an example and not working code - the actual function is much larger
function split_db()
{
    $results = "
        SELECT *
        FROM big_table
    ";

    foreach ( $results as $result )
    {
        // Here I split the big_tables contents and ...
        $some_val = $result->SomeVal;
        // ...
        $another_val = $result->AnotherVal;

        // ... here I insert the contents in the different tables
        $sql = "
            INSERT
            INTO first_small_table
            // ...
            VALUES
            // ...
        ";
    }
}

问题:无论我是在本地环境还是在测试服务器上,查询都会插入255行。

问题:为什么?我做错了什么或者我错过了什么?我怎么能避免这个?

有关MySQL-Client-Version的信息:

  • Dev-Server: 5.0.32,
  • Local Dev-Env。: 5.1.41

我不是MySQL-Hero,所以任何帮助和解释都是值得赞赏的,因为Google对我没有任何意义(对我而言)。谢谢!

2 个答案:

答案 0 :(得分:7)

我敢打赌你的主键为unsigned tinyint类型,最大值限制为255.

因此将其更改为int

ALTER TABLE first_small_table MODIFY id INT;

答案 1 :(得分:5)

我不能说为什么你限制在255行,但我可以说你可以做一个查询,用你的大表将你的行添加到你的小表中,用INSERT INTO ... SELECT查询:

INSERT INTO first_small_table (col1, col2, col3)
SELECT col1, col2, col3
FROM big_table;

如果您不需要使用PHP,那么无论如何都不要使用它。只使用SQL会更快。

相关问题