zoukankan      html  css  js  c++  java
  • mysql_load

    将文本内容导入mysql数据库中
    
    
    导入语句加入字符集,否则乱码
    character set gbk;
    
    因为name列加了唯一索列,加这个是为避免重复数据插入报错
    ignore into table
    
    把相同的先删除掉
    replace into table
    
    
    [linux]
    这里关键
    
    load data infile '/tmp/t0.txt' ignore into table t0 
    character set gbk fields terminated by ',' 
    enclosed by '"' lines terminated by '\n' (`name`,`age`,`description`);
    
    
    [windows]
    load data infile 'f:/2.txt' ignore into table t0
     character set gbk fields terminated by ',' 
    enclosed by '"' lines terminated by '\r\n' (`name`,`age`,`description`);
    
    
    
    CREATE TABLE `t0` (
      `id` bigint(20) unsigned NOT NULL auto_increment,
      `name` char(20) NOT NULL,
      `age` tinyint(3) unsigned NOT NULL,
      `description` text NOT NULL,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `idx_name` (`name`)
    ) ENGINE=MyISAM DEFAULT CHARSET=gbk;
    
    
    
    
    导入的文件
    2.txt
    
    "我爱你1","201","相貌平常,经常耍流氓!哈哈"
    "我爱你2","202","相貌平常,经常耍流氓!哈哈"
    "我爱你3","203","相貌平常,经常耍流氓!哈哈"
    "我爱你4","204","相貌平常,经常耍流氓!哈哈"
  • 相关阅读:
    MySQL语法
    SQL必知必会
    大话设计模式
    软件工程
    myeclipse中git的使用
    提取文件中图片标签
    pandas 分析各地区男女的分布情况
    提取图片标签
    Requwsts+正则表达式爬取猫眼电影Top100
    PyCharm激活码
  • 原文地址:https://www.cnblogs.com/kaka100/p/2947337.html
Copyright © 2011-2022 走看看