mysql - 从 csv 导入时 mysql 出错

标签 mysql load-data-infile

这是我的命令行查询。

mysql> load data local infile "c:\\re\\30-11-08.csv" 
into table powerdata(Date, DG1, DG2, DG3, Dg4, DG5, ChillerPanel1, 
    ChillerPanel2, ChillerPanel3, ChillerPanel4,1st_Floor, 2nd_Floor, 
    3rd_Floor, 4th_Floor, UPS1, UPS2, UPS3, UPS4, UPS5,Server_Power, 
    Cooling_Power) 
    fields terminated by ',' lines terminated by '\n'
set Dateformat=str_to_date(Date, '%m/%d/%Y' '%H:%i:%s');

ERROR 1064 (42000): 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 ',' lines terminated by '\n'set Dateformat=str_to_date(Date' at line 1

不知道哪里出错了!谁能帮帮我?

最佳答案

我想是“set Dateformat=”部分导致了问题。您的列名为“日期”,因此该部分应如下所示:

set Date = str_to_date(@datevar, 'your format')

另请参阅 the manual 中的以下代码示例:

LOAD DATA INFILE 'file.txt'
  INTO TABLE t1
  (column1, @var1)
  SET column2 = @var1/100;

顺便说一句:在 MySQL 5.0.3 之前,不支持 SET 子句。

关于mysql - 从 csv 导入时 mysql 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/629204/

相关文章:

mysql - 为什么 Table Import 显示错误 1366,Data looks good

mysql - 使用mysqlimport时不能显示警告吗?

Mysql权限错误, 'load data'

mysql - “Execute stmt”存储的过程中-没有错误但没有插入的记录

php - 每页查询太多

php - 全文搜索不起作用

php - 使用php从数据库中获取多行

mysql - 将平面文件加载到规范化的 MySQL 数据库中

与加载数据infile一起使用的mysql触发器

mysql - 使用 SQL 根据单条记录的更改来更改多条记录