zoukankan      html  css  js  c++  java
  • MySQL 大数据量文本插入

    导入几万条数据需要等好几分钟的朋友来围观一下!

    百万条数据插入,只在一瞬间。呵呵夸张,夸张!! 不到半分钟是真的!  

     

    插入指令: load data infile 'c:/wamp/tmp/Data_OutFile.csv' replace into table data_1 character set utf8 fields terminated by ',' enclosed by '"' lines terminated by ' ' (name,age,description );

    指令说明:

    replace into table data_1   :指 在表data_1中插入数据时,碰到相同的数据怎么处理。replace是替换。也可以使用ignore,指不处理本条数据。

    character set utf8:  使用字符集 utf8。

    fields terminated by ','   :  字段之间使用英文逗号隔开。

    Enclosed By '"' :内容包含在双引号内。

    lines terminated by ' '  :每条数据以 结尾。

    (name,age,description )是可选的,当不写的时候,就是所有字段。如果数据与数据库的字段不对应的时候,需要填写,以使字段对应

     

    运行的时候,如果不注意文件路径,可能会报: ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 错误。

    原因是mysql 默认对导出的目录有权限限制,也就是说使用命令行进行导出的时候,需要指定目录进行操作;

    解决办法:

     查询mysql 的my.ini文件的secure_file_priv 值配置的是什么。一般你的导入导出的文件需要放在这个文件夹下!当然你也可以修改这个值。

    文件导出:

    Select * From data_1 Into OutFile 'c:/wamp/tmp/Data_OutFile.csv' character set utf8 fields terminated by ',' enclosed by '"' lines terminated by ' ' ( name,age,description );

    这是文件导入导出最快的方法。

  • 相关阅读:
    [模板] 循环数组的最大子段和
    [最短路][几何][牛客] [国庆集训派对1]-L-New Game
    [洛谷] P1866 编号
    1115 Counting Nodes in a BST (30 分)
    1106 Lowest Price in Supply Chain (25 分)
    1094 The Largest Generation (25 分)
    1090 Highest Price in Supply Chain (25 分)
    树的遍历
    1086 Tree Traversals Again (25 分)
    1079 Total Sales of Supply Chain (25 分 树
  • 原文地址:https://www.cnblogs.com/xunhanliu/p/10484957.html
Copyright © 2011-2022 走看看