mysqlinnodb

How to copy data from another table without lock the table in MYSQL 6.2?


I have a table that has all history data in Mysql server and it is very huge (about 700 million rows). I am creating a new table with the same columns but with partitioning, then I need to copy all data from the old table into the new partitioned table. I have already got the right script to do that but I think it might lock the table. I don't want that happen because it is on production server. What should I do to avoid locking the table?


Solution

  • Give that the tables have the exact same columns you can do something like this:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
    INSERT INTO NEW_TABLE (SELECT * FROM OLD_TABLE);
    COMMIT ;
    

    I've included some additional explanation based on Wistar's comment. The read levels that can be used here are:

    I hope this helps.