1.如何将数据表导入到mysql的表中,可以使用:load data infile ... into table  ...

示例:

load data infile 'e:\datainfo.txt' into table `table_1`  fields terminated by '\t'    lines terminated by'\r\n'  
参数说明,其中:
 fields terminated by '\t' :表示使用tab制表符作为字段分隔符;
 lines terminated by'\r\n'  :表示使用回车换行符作为行分隔符
 
 
2.还有一种,比如想把5列数据导入到3列的表中,使用变量占位。
示例:
load data infile 'e:\data2info.txt' into table `table_2`  fields terminated by '\t'    lines terminated by'\r\n' (@abc,uid,name,@abc,age)
@abc表示的是变量,把数据中的第一列赋值给一个变量,导入时等于丢掉这一列数据。
 
3.还有一种,有一个自增字段id,数据有3列,表有4列。id是自增的,数据中无该列。
比如数据:
 
    lisi
lisi
lisi
lisi
lisi
lisi
示例:
load data infile 'e:\data3info.txt' into table `table_3`  fields terminated by '\t'    lines terminated by'\r\n' (uid,name,age)

有的人,在导入数据时会遇到如下错误:

查询:load data local infile "e:\data1.txt" into table table(myid,myname,myaddr) fields terminated by '\t' lines terminat...

错误代码: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fields terminated by '\t' lines terminated by '\r\n'' at line 1

大概可能是在写导入语句的时候:把指定字段的部分放到了表名后面,导致的。应该放到最后。

还有可能是mysql的版本不支持按照字段导入,那暂时无解。

参考:

LOAD DATA INFILE error 1064

mysql 导入txt数据到数据表【原创】的更多相关文章

  1. mysql 导入导出数据库、数据表的方法

    mysql 导入导出数据库.数据表的方法. Linux操作系统中,均在控制台下操作.1,导入数据库:前提:数据库和数据表要存在(已经被创建)(1)将数据表 test_user.sql 导入到test ...

  2. 复杂业务下向Mysql导入30万条数据代码优化的踩坑记录

    从毕业到现在第一次接触到超过30万条数据导入MySQL的场景(有点low),就是在顺丰公司接入我司EMM产品时需要将AD中的员工数据导入MySQL中,因此楼主负责的模块connector就派上了用场. ...

  3. MYSQL导入CSV格式文件数据执行提示错误(ERROR 1290): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement.

    MYSQL导入CSV格式文件数据执行提示错误(ERROR 1290): The MySQL server is running with the --secure-file-priv option s ...

  4. Mysql导入大容量SQL文件数据问题

    mysql在通过导入sql文件可能会出现下面二个问题: 1.如果sql文件过大,会出现"MySQL server has gone away"问题; 2.如果sql文件数据有中文, ...

  5. Bash中使用MySQL导入导出CSV格式数据[转]

    转自: http://codingstandards.iteye.com/blog/604541 MySQL中导出CSV格式数据的SQL语句样本如下:   select * from test_inf ...

  6. mysql 导入导出数据库、数据表

    Linux下 均在控制台下操作. 导入数据库: 前提:数据库和数据表要存在(已经被创建) (1)将数据表 test_user.sql 导入到test 数据库的test_user 表中 [root@te ...

  7. mysql 导入txt数据

    在导入数据的时候,特别是数据包含中文的时候,在导入的时候,容易出现编码规则引起的错误.例如错误提示:Invalid utf8 character string: '' 这种情况下,我们可以把需要导入的 ...

  8. Mysql 导入导出数据结构及数据

    方式一: mysqldump -ukevin -P3306 --default-character-set=utf8 -p -h10.1.15.123 activity sign_in_user &g ...

  9. Mysql 导入导出表结构与数据

    1.导出整个数据库 mysqldump -u用户名 -p密码  数据库名 > 导出的文件名  C:\Users\jack> mysqldump -uroot -pmysql account ...

随机推荐

  1. 自学git

    网址:https://github.com/join/plan 注册:gzhcsu 注册邮箱:QQ邮箱.

  2. learning shell monitor prog function

    [Purpose]        Shell script monitor prog function   [Eevironment]        Ubuntu 16.04 bash env   [ ...

  3. 用户管理命令——useradd、paaswd、who、w

    1.useradd和passwd命令: 其中:useradd用来添加用户,passwd用来添加用的的密码: 用户创建后可以用用户名和密码进行登录. 2.passwd:密码的更改: (1)普通用户: 只 ...

  4. ABP 03 解决 编辑User报错

    1.编辑用户时,报错.后面有跟解决方案. 解决方案1: 2.导致出错的原因是这样的,这里的功能是请求服务端的html页面,渲染后显示编辑页面. 关键点是默认参数那儿 路径:\aspnet-core\s ...

  5. [RN] React Native 删除第三方开源组件依赖包 后 还要做的 (以 删除 react-native-video为例)

    近期测试使用了下  react-native-video 使用一直不成功,后来想着删除掉, 使用命令: npm uninstall react-native-video 重新编译后,还是一直报错 后来 ...

  6. nginx 访问控制之 限速

    nginx限速可以通过 ngx_http_limit_conn_module 和 ngx_http_limit_req_module 模块来实现限速的功能. 一.ngx_http_limit_conn ...

  7. ftp使用

    1.pom文件中添加依赖 <!-- ftp使用 --><dependency> <groupId>commons-net</groupId> <a ...

  8. shell 编写进度条

    test.sh #!/bin/bash i= bar='' label=("|" "/" "-" "\\") ] do ...

  9. WPF——OXY绘图

    private PlotModel _plotModel; public PlotModel plotModel { get { return _plotModel; } set { _plotMod ...

  10. js之select三级联动

    效果图如下: 代码逻辑梳理:层层递进,比如选择了课程后,将对应的课程id保存,然后点击选择章时自动触发对应的时间,根据这个课程ID获取其下面的章信息.其它的如节等,同理. 代码说明:如下代码不规范,可 ...