我想要做的是将txt中的“12/26/17 14:30”转移到MySQL中的“2017-12-26 14:30:00”
我已经试过这个 Importing a CSV to MySQL with different date format0
所以我的代码看起来像这样
create_tb_str = r'''DROP TABLE IF EXISTS TABLENAME;
CREATE TABLE TABLENAME (
Datetime DATETIME,
Open float(8,3),
High float(8,3),
Low float(8,3),
Close float(8,3),
Volume INT,
PRIMARY KEY (Datetime)
);'''
insert_tb_str = r''' LOAD DATA LOCAL INFILE 'FILENAME'
INTO TABLE TABLENAME FIELDS TERMINATED BY '\t\t'
ENCLOSED BY '"' LINES
TERMINATED BY '\n'
(@time, open, high, low, close, @dummy, volume);
SET Datetime = STR_TO_DATE(@time,'%y-%m-%d %H:%i:%S');
'''
但是,在我生成 .sql 并尝试导入到我的数据库后,这是我得到的结果,终端无法识别我的表的列名。
$:~/Downloads/bartest$ mysql -u root -p bar -A < bartest.sql
Enter password:
ERROR 1193 (HY000) at line 21: Unknown system variable 'Datetime'
有什么建议吗?