duanbu9345 2014-10-20 21:25
浏览 17
已采纳

插入mysql extra列导致错误

Basically I have a table with 20million rows and 5 columns(fields), when I do a mysql dump then I want to import the rows to another table that has 6 columns it returns an error because the the columns are not the same

INSERT INTO table2 VALUES (value1, value2, value3, value4, value5)

I would like to insert all the rows with the 6th column that way I don't get the error. I can't really edit the .sql dump its 2gb. Is there a way to do it? please remember the destination table (where the data is to be dumped) already contains a considerable amount of data (8million rows) so altering the table would take forever any suggestions ?

  • 写回答

3条回答 默认 最新

  • duanlian1960 2014-10-20 21:33
    关注

    There are several ways to do this.

    First, there are ways to edit 2GB files (depending on your OS). For Windows, I had good experience with EmEditor that can handle Search & Replace operations on large files.

    Second, you can do it in two stages: 1. Open the dump file into a table with 5 columns, e.g. temp. 2. Copy from that table to your destination table.

    INSERT INTO table2 (col1, col2, col3, col4, col5) 
    SELECT (col1, col2, col3, col4, col5) 
    FROM temp;
    

    This is assuming col6 in table2, for which you don't have data, has a default value. Otherwise:

    INSERT INTO table2 (col1, col2, col3, col4, col5, col6) 
    SELECT (col1, col2, col3, col4, col5, 'anyDefaultValue') 
    FROM temp;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度