0

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"}
4

1 に答える 1

1

まず、JSON を読み取り可能なファイル形式に変換する必要があります。

次に、 LOAD DATA INFILEを使用できます。

于 2013-09-10T15:03:37.510 に答える