BULK INSERT语法MYSQL

时间:2013-09-10 14:38:44

标签: php mysql sql sql-server

在MS SQL上,我可以使用下面的sql命令进行批量插入:

BULK INSERT dbo.TweetJSON
    from ‘D:\file.txt’
    with (CODEPAGE=’65001’, FORMATFILE=’D:\BIFormatFile.txt’
    );

BIFormatFile内容如下:

9.0
1
1 SQLCHAR 0 8000 “\r\n” 1 [JSONData] “”

现在我想在MySQL上做同样的事情,但我似乎无法弄清楚它是如何工作的以及使用什么查询..

到目前为止,我想到的是:

LOAD DATA INFILE 'C:\File.txt'
INTO TABLE dbo.tweetjson
FIELDS TERMINATED BY '\r\n'

但是我仍然没有找到将这些MSSQL代码转换为MYSQL的所有必要代码。请帮忙..

来自file.txt的行示例:

{"created_at":"Mon Sep 02 15:28:13 +0000 2013","id":374554364159225856,"id_str":"374554364159225856","text":"Smart watches: what are Apple, Samsung, Google and Microsoft up to? http:\/\/t.co\/bB3CS6xTDp","source":"\u003ca href=\"http:\/\/www.hootsuite.com\" rel=\"nofollow\"\u003eHootSuite\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":707472469,"id_str":"707472469","name":"SoftWatchTeam","screen_name":"SoftWatchTeam","location":"Everywhere ","url":"http:\/\/softwatch.weebly.com","description":"All the latest technology news","protected":false,"followers_count":231,"friends_count":439,"listed_count":0,"created_at":"Fri Jul 20 17:04:18 +0000 2012","favourites_count":0,"utc_offset":7200,"time_zone":"Amsterdam","geo_enabled":false,"verified":false,"statuses_count":16798,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2624051650\/tyc2cafp0viuma2o8d5m_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2624051650\/tyc2cafp0viuma2o8d5m_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/bB3CS6xTDp","expanded_url":"http:\/\/htl.li\/2zA3iq","display_url":"htl.li\/2zA3iq","indices":[68,90]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"medium","lang":"en"}

1 个答案:

答案 0 :(得分:1)

您需要先将JSON转换为可读的文件格式。

然后您可以使用LOAD DATA INFILE