简体   繁体   中英

BULK INSERT syntax MYSQL

On MS SQL, I can do bulk insert using the sql command below:

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

The BIFormatFile content is as follows:

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

Now I want to do the same on MySQL but I can't seem to figure out how this works and what query to use..

So far the lines that I figured are:

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

However i still have not figured out all the necessary codes to convert those MSSQL code to MYSQL. Please help..

The example of line from 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"}

You need to first convert the JSON into a readable file format.

Then you can use LOAD DATA INFILE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM