What is the best/fastest way to upload a csv file into a mysql table? I would like for the first row of data be used as the column names.

Found this:

But the only answer was to use a GUI and not shell?

解决方案

Instead of writing a script to pull in information from a CSV file, you can link MYSQL directly to it and upload the information using the following SQL syntax.

To import an Excel file into MySQL, first export it as a CSV file. Remove the CSV headers from the generated CSV file along with empty data that Excel may have put at the end of the CSV file.

You can then import it into a MySQL table by running:

load data local infile 'uniq.csv' into table tblUniq fields terminated by ','

enclosed by '"'

lines terminated by '\n'

(uniqName, uniqCity, uniqComments)

EDIT

For your case, you'll need to write an interpreter first, for finding the first row, and assigning them as column names.

EDIT-2

The IGNORE number LINES option can be used to ignore lines at the

start of the file. For example, you can use IGNORE 1 LINES to skip

over an initial header line containing column names:

LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;

Therefore, you can use the following statement:

LOAD DATA LOCAL INFILE 'uniq.csv'

INTO TABLE tblUniq

FIELDS TERMINATED BY ','

ENCLOSED BY '"'

LINES TERMINATED BY '\n'

IGNORE 1 LINES

(uniqName, uniqCity, uniqComments)

将csv添加到mysql,将CSV导入到mysql表相关推荐

  1. 用sqoop将mysql的数据导入到hive表中,原理分析

    Sqoop 将 Mysql 的数据导入到 Hive 中 准备Mysql 数据 如图所示,准备一张表,数据随便造一些,当然我这里的数据很简单. 编写命令 编写参数文件 个人习惯问题,我喜欢把参数写到文件 ...

  2. 用sqoop将mysql的数据导入到hive表

    一.先将mysql一张表的数据用sqoop导入到hdfs 1.1.先在mysql中准备一张测试用的表 mysql> desc user_info; +-----------+---------- ...

  3. linux mysql导出导入表_linux mysql 数据库操作导入导出 数据表导出导入

    在Linux下安装和使用MySQL [简 介] 想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的MySQL.本以为有Windows下使用SQL ...

  4. mysqldump导入导出mysql数据库

    mysqldump导入导出mysql数据库 mysqldump导入导出mysql数据库 2011-02-21 16:33 数据库的基本导入\导出的命令 是 mysqldump 和 source 在li ...

  5. mysql删除时级联语句,MySQL删除级联

    MySQL的删除级联 当我们从父表中删除行时,MySQL中的ON DELETE CASCADE子句用于自动从子表中删除匹配的记录.这是与外键有关的一种引用动作. 假设我们创建了两个带有外键关系的FOR ...

  6. linux解压mysql文件命令行_linux mysql命令

    1.linux下启动mysql的命令: mysqladmin start /ect/init.d/mysql start (前面为mysql的安装路径) 2.linux下重启mysql的命令: mys ...

  7. linux mysql dump命令_linux下mysql命令

    1.linux下启动mysql的命令: mysqladmin start /ect/init.d/mysql start (前面为mysql的安装路径) 2.linux下重启mysql的命令: mys ...

  8. mysql drop 几十g的表_MySQL Drop 大表的解决方案

    一 引子 在生产环境中,删除一个大文件,比如一个数十 G 或者上百 G 的文件是很耗时的. 本文介绍一个快速 DROP TABLE 的方法.使用本文提供的方法,不管该表数据量.占用空间有多大,都可以快 ...

  9. php mysql导出csv文件_详解PHP导入导出CSV文件

    我们先准备mysql数据表,假设项目中有一张记录学生信息的表student,并有id,name,sex,age分别记录学生的姓名.性别.年龄等信息. CREATE TABLE `student` ( ...

最新文章

  1. FZU 2297 Number theory【线段树/单点更新/思维】
  2. android运行exe没有反应,安卓最担心的事情发生了
  3. spring in action 7.1 小结
  4. BUUCTF--[VN2020 公开赛]拉胯的三条命令
  5. java map 随机取值_随机获取一个集合(List, Set)中的元素,随机获取一个Map中的key或value...
  6. c++builder tadoquery存储过程_Electron桌面应用程序从创建项目、启动项目到打包程序的详细过程...
  7. 用CImage类来显示PNG JPG等图片
  8. php正则如何使用 1,PHP正则表达式使用详解(1)
  9. 萦绕在头脑中的思路_我的编程梦们 【更新至2010.06.03】
  10. 解决Win11安装Keil芯片包失败/软件卡死/无法解压的问题
  11. 如果时间不够 ,无法进行充分的测试怎么办?
  12. 微信小程序云数据库的分页提取,解决提取大量数据的耗时问题
  13. Syntax error on token?excepted agter this token
  14. 2022年N1叉车司机考试题目及答案
  15. IMO 2017 T1解答
  16. 超算入门笔记:大型机上如何运行WRF模式?一文总结(并行运算、Linux基础、作业调度、WRF运行)
  17. pimple学习:源码解读
  18. android模拟器命令大全,玩转安卓模拟器命令行
  19. C#微信开放平台开发——1、序言
  20. 【操作系统】Linux内核和Windows系统的内核有什么区别?

热门文章

  1. GCD中的队列与任务
  2. asp.net 2.0常见问题技巧1
  3. js 一些的数组的方法
  4. [Node.js] 模块化 -- NodeJS之heroAdmin后台管理系统基础
  5. 15个最新的HTML5及CSS3特效代码生成器
  6. OpenCV中 IplImage 与 Mat的区别
  7. NG Command(命令)
  8. 使用函数输出水仙花数
  9. MyBatis复习(八):MyBatis 分页插件 PageHelper
  10. 使用rust编译linux,在 Ubuntu 上为 CentOS 编译 Rust 程序,