RDS(MySQL)からCSVエクスポートを行う方法についてまとめてみた

2015.08.05

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

 

AWSに於けるビッグデータ分析環境構築に於いては、DWHであるAmazon Redshiftにデータを貯めこむ為に様々な経路からCSVやJSONファイルをS3等の環境に集約する作業が必要となります。そしてその作業の中にはオンプレ環境を始めとした外部データソースをAWSに集約するという経路がある一方で、AWS環境下にあるデータをAmazon Redshiftに投入させるために一旦ファイルとして出力させる(そしてAmazon Redshiftに投入する)という経路もあるかと思います。そこで当エントリでは、『RDS(MySQL)からAmazon Redshiftにデータを移行する際にどのような手段を取ることが出来るのか』という点について、幾つか洗い出してまとめてみたいと思います。

目次

検証環境準備

まずは今回の検証を行う上での環境を整えます。Tableauで良く使っているデモデータ『Superstore』を使います。RDS(MySQL)インスタンスを立ち上げ、ログイン。

$ mysql -h xxxxxxx.yyyyyyy.us-east-1.rds.amazonaws.com -u (ユーザー名) -p -D (DB名)
Enter password: (XXXXXXXXXXXXXXXXX)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

DBを指定し、

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| csvexpdb           |
| innodb             |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.38 sec)

mysql> USE csvexpdb;
Database changed
mysql>

データを投入するためのテーブルを作成します。(※今回はRDSのパラメータなどは特に意識していなかったため、エンコーディングに関する設定をその場で行なっています)

mysql> set character_set_database=utf8;
Query OK, 0 rows affected (0.35 sec)

mysql> CREATE TABLE orders (
    ->   order_id INT NOT NULL,
    ->   order_date DATE NOT NULL,
    ->   priority VARCHAR(12) NOT NULL,
    ->   quantity SMALLINT NOT NULL,
    ->   sales DOUBLE PRECISION,
    ->   discount_rate DOUBLE PRECISION,
    ->   ship_mode VARCHAR(20) NOT NULL,
    ->   profit INT NOT NULL,
    ->   unit_price INT NOT NULL,
    ->   ad_expenses INT NOT NULL,
    ->   shipping_cost INT NOT NULL,
    ->   customer_name VARCHAR(50) NOT NULL,
    ->   prefecture VARCHAR(12) NOT NULL,
    ->   city VARCHAR(20) NOT NULL,
    ->   area VARCHAR(12) NOT NULL,
    ->   shop_name VARCHAR(20) NOT NULL,
    ->   customer_segment VARCHAR(30) NOT NULL,
    ->   product_category VARCHAR(30) NOT NULL,
    ->   product_sub_category VARCHAR(100) NOT NULL,
    ->   product_id VARCHAR(10) NOT NULL,
    ->   product_name VARCHAR(100) NOT NULL,
    ->   product_description VARCHAR(200) NOT NULL,
    ->   product_container VARCHAR(100) NOT NULL,
    ->   base_margin DOUBLE PRECISION,
    ->   supplier VARCHAR(30) NOT NULL,
    ->   deliver_date DATE NOT NULL,
    ->   ship_date DATE NOT NULL
    -> ) CHARACTER SET 'utf8';
Query OK, 0 rows affected (0.47 sec)

予め用意してあったCSVファイルをLOADコマンドを使ってテーブルに投入します。

mysql> LOAD DATA LOCAL INFILE '/xxxx/superstore-orders-utf8.csv' 
    -> INTO TABLE orders 
    -> FIELDS TERMINATED BY ',' 
    -> IGNORE 1 LINES;                
Query OK, 8369 rows affected, 25107 warnings (17.13 sec)
Records: 8369  Deleted: 0  Skipped: 0  Warnings: 25107

mysql> SELECT COUNT(*) FROM orders;
+----------+
| COUNT(*) |
+----------+
|     8369 |
+----------+
1 row in set (0.44 sec)

mysql> SELECT * FROM orders LIMIT 10;
+----------+------------+--------------+----------+--------+---------------+--------------------+--------+------------+-------------+---------------+------------------+------------+-----------+-----------+-----------+-----------------------+--------------------+------------------------------------------------------+------------+---------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+----------+--------------+------------+
| order_id | order_date | priority     | quantity | sales  | discount_rate | ship_mode          | profit | unit_price | ad_expenses | shipping_cost | customer_name    | prefecture | city      | area      | shop_name | customer_segment      | product_category   | product_sub_category                                 | product_id | product_name                                                  | product_description                                                                                               | product_container     | base_margin | supplier | deliver_date | ship_date  |
+----------+------------+--------------+----------+--------+---------------+--------------------+--------+------------+-------------+---------------+------------------+------------+-----------+-----------+-----------+-----------------------+--------------------+------------------------------------------------------+------------+---------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+----------+--------------+------------+
|    55554 | 2009-01-01 | 重要         |        6 |  15261 |          0.04 | 通常航空便         |  -1520 |       1897 |      230393 |           954 | 中谷 成広        | 宮崎       | 小林      | 九州      | Morris    | 小規模事業所          | 事務用品           | 紙                                                   | P1186      | Xerox 1939                                                    | This is the field which has product description for Xerox 1939                                                    | 小型ボックス          |        0.37 | Elan     | 2009-02-02   | 2009-02-02 |
|    47873 | 2009-01-01 | 重要         |        8 |   6548 |          0.08 | 通常航空便         |  -1738 |        589 |      224716 |           557 | 吉津 正晃        | 大分       | 臼杵      | 九州      | Coleman   | 企業                  | 家具               | オフィス家具                                         | P428       | Eldon Wave Desk Accessories                                   | This is the field which has product description for Eldon Wave Desk Accessories                                   | 小型ボックス          |        0.41 | Argot    | 2009-03-10   | 2009-03-12 |
|    29187 | 2009-01-02 | 低           |       10 |   9447 |             0 | 通常航空便         |  -4326 |        648 |      443895 |           819 | 河本 訓治        | 愛知       | 名古屋    | 中部      | Lane      | 消費者                | 事務用品           | 紙                                                   | P1248      | Xerox 217                                                     | This is the field which has product description for Xerox 217                                                     | 小型ボックス          |        0.37 | Merxin   | 2009-01-23   | 2009-01-23 |
|    24519 | 2009-01-02 | 重要         |       22 |  15945 |          0.03 | 通常航空便         |  -6072 |        534 |      219107 |           563 | 神保 雄二        | 京都       | 八幡      | 関西      | Anderson  | 消費者                | 事務用品           | バインダーとバインダー アクセサリー                  | P885       | Pressboard Data Binder Crimson 12 X 8 1/2                     | This is the field which has product description for Pressboard Data Binder Crimson 12 X 8 1/2                     | 小型ボックス          |        0.39 | Elan     | 2009-04-01   | 2009-04-02 |
|     4871 | 2009-01-02 | 重要         |        8 |  96967 |          0.02 | 配送トラック       | -21539 |       8999 |      426147 |          4200 | 久保田 智和      | 北海道     | 紋別      | 北海道    | Allen     | 消費者                | 家具               | 椅子とチェアマット                                   | P565       | Global Leather Task Chair Black                               | This is the field which has product description for Global Leather Task Chair Black                               | ジャンボドラム        |        0.66 | Argot    | 2009-04-01   | 2009-04-04 |
|    45671 | 2009-01-02 | 低           |       13 |  15835 |          0.05 | 通常航空便         |    700 |        977 |      332466 |           602 | 田畑 純也        | 埼玉       | 飯能      | 関東      | Jenkins   | 消費者                | 家具               | オフィス家具                                         | P365       | DAX Solid Wood Frames                                         | This is the field which has product description for DAX Solid Wood Frames                                         | 中型ボックス          |        0.48 | Elan     | 2009-04-01   | 2009-04-02 |
|    45376 | 2009-01-02 | 重要         |       19 | 831072 |          0.08 | 配送トラック       | -55598 |      37098 |      386406 |          9900 | 重川 功一郎      | 徳島       | 小松島    | 四国      | Wright    | 消費者                | 事務用品           | 保管と整理                                           | P944       | Sauder Facets Collection Locker/File Cabinet Sky Alder Finish | This is the field which has product description for Sauder Facets Collection Locker/File Cabinet Sky Alder Finish | ジャンボドラム        |        0.65 | Ningbo   | 2009-04-18   | 2009-04-19 |
|    58755 | 2009-01-02 | 低           |       18 |   5888 |             0 | 通常航空便         |  -9542 |        218 |      222817 |           709 | 泉田 近智        | 岡山       | 倉敷      | 中国      | Powell    | ホームオフィス        | 事務用品           | 紙                                                   | P155       | Ampad Evidence Wirebond Steno Books 6 x 9                     | This is the field which has product description for Ampad Evidence Wirebond Steno Books 6 x 9                     | ラップバッグ          |        0.38 | Elan     | 2009-04-19   | 2009-04-19 |
|    12228 | 2009-01-03 | 指定なし     |       30 | 626881 |          0.05 | 通常航空便         | 109043 |      20099 |      234489 |           420 | 剱持 卓也        | 茨城       | 石岡      | 関東      | Shale     | 企業                  | テクノロジー       | 電話と通信                                           | P20        | 2160i                                                         | This is the field which has product description for 2160i                                                         | 小型ボックス          |        0.59 | Argot    | 2009-01-20   | 2009-01-19 |
|    23333 | 2009-01-03 | 中           |       44 |  79265 |          0.04 | 通常航空便         |  -2165 |       1442 |      116707 |           675 | 村木 善幸        | 山口       | 美祢      | 中国      | Reyes     | ホームオフィス        | 事務用品           | アプライアンス                                       | P598       | Holmes Odor Grabber                                           | This is the field which has product description for Holmes Odor Grabber                                           | 中型ボックス          |        0.52 | Alibaba  | 2009-01-24   | 2009-01-24 |
+----------+------------+--------------+----------+--------+---------------+--------------------+--------+------------+-------------+---------------+------------------+------------+-----------+-----------+-----------+-----------------------+--------------------+------------------------------------------------------+------------+---------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+----------+--------------+------------+
10 rows in set (0.22 sec)

これで準備が整いました。以降の手順で色々と試してみたいと思います。

EC2上でmysqlコマンドによるクエリ実行結果をファイルとして出力

こちらの大元になった情報は以下StackOverflowのエントリ。かなり泥臭い感じではありますね。

mysqlコマンド実行例は以下の通り。冒頭の--local-infile=1はクライアント側でのload data local infileを認めるオプションとなります。これが無いと動かないので指定に入れました。1行目にはCONCAT関数の定義文がそのまま出力されてしまっていたのでsedコマンドで出力結果の1行目を除去しています。ここまでの処理内容をローカル(※ここでは実行を想定したEC2サーバ)環境にCSVファイルとして出力しています。

mysql --local-infile=1 \
-h xxxxxxx.yyyyyyy.us-east-1.rds.amazonaws.com \
-u(ユーザー名) -p(DB接続パスワード) \
-D (DB名) \
-e "SELECT CONCAT( \
    '\"',order_id,'\",', \
    '\"',DATE_FORMAT(order_date,\"%Y/%m/%d\"),'\",' \
    '\"',priority,'\",' \
    '\"',quantity,'\",' \
    '\"',sales,'\",' \
    '\"',discount_rate,'\",' \
    '\"',ship_mode,'\",' \
    '\"',profit,'\",' \
    '\"',unit_price,'\",', \
    '\"',ad_expenses,'\",', \
    '\"',shipping_cost,'\",', \
    '\"',customer_name,'\",', \
    '\"',prefecture,'\",', \
    '\"',city,'\",', \
    '\"',area,'\",', \
    '\"',shop_name,'\",', \
    '\"',customer_segment,'\",', \
    '\"',product_category,'\",', \
    '\"',product_sub_category,'\",', \
    '\"',product_id,'\",', \
    '\"',product_name,'\",', \
    '\"',product_description,'\",', \
    '\"',product_container,'\",', \
    '\"',base_margin,'\",', \
    '\"',supplier,'\",', \
    '\"',DATE_FORMAT(deliver_date,\"%Y/%m/%d\"),'\",', \
    '\"',DATE_FORMAT(ship_date,\"%Y/%m/%d\"),'\"' \
) FROM orders" \
| sed -e '1d' $1 > /xxxxxxxxxx/orders-export.csv

DBパスワードの部分については、上記例では直に設定する形を取っていますが、これは実利用の際にはあまりよろしく無いでしょう、置き換えるとすれば、実行ユーザーのホームディレクトリ直下に.my.cnfファイルを作成して置く(下記の場合であればEC2の実行ユーザー(ec2-user))か、

/home/ec2-user/.my.cnf

[client]
password="(MySQL接続パスワード)"

mysqlコマンド実行時に--defaults-extra-fileオプションで任意の場所にあるmy.cnfファイルを読み込む事でパスワード入力を省くことが出来ます。こちらは状況に応じて最も好ましい方法を選んでください。

mysql --defaults-extra-file=/path/to/my.cnf -h xxxxxxx.yyyyyyy.us-east-1.rds.amazonaws.com -u(ユーザー名) -D (DB名)...

生成したCSVは以下のようになりました。

orders-export.csv

"55554","2009/01/01","重要","6","15261","0.04","通常航空便","-1520","1897","230393","954","中谷 成広","宮崎","小林","九州","Morris","小規模事業所","事務用品","紙","P1186","Xerox 1939","This is the field which has product description for Xerox 1939","小型ボックス","0.37","Elan","2009/02/02","2009/02/02"
"47873","2009/01/01","重要","8","6548","0.08","通常航空便","-1738","589","224716","557","吉津 正晃","大分","臼杵","九州","Coleman","企業","家具","オフィス家具","P428","Eldon Wave Desk Accessories","This is the field which has product description for Eldon Wave Desk Accessories","小型ボックス","0.41","Argot","2009/03/10","2009/03/12"
"29187","2009/01/02","低","10","9447","0","通常航空便","-4326","648","443895","819","河本 訓治","愛知","名古屋","中部","Lane","消費>者","事務用品","紙","P1248","Xerox 217","This is the field which has product description for Xerox 217","小型ボックス","0.37","Merxin","2009/01/23","2009/01/23"
"24519","2009/01/02","重要","22","15945","0.03","通常航空便","-6072","534","219107","563","神保 雄二","京都","八幡","関西","Anderson","消費者","事務用品","バインダーとバインダー アクセサリー","P885","Pressboard Data Binder Crimson 12 X 8 1/2","This is the field which has product description for Pressboard Data Binder Crimson 12 X 8 1/2","小型ボックス","0.39","Elan","2009/04/01","2009/04/02"
"4871","2009/01/02","重要","8","96967","0.02","配送トラック","-21539","8999","426147","4200","久保田 智和","北海道","紋別","北海道","Allen","消費者","家具","椅子とチェアマット","P565","Global Leather Task Chair Black","This is the field which has product description for Global Leather Task Chair Black","ジャンボドラム","0.66","Argot","2009/04/01","2009/04/04"
:

mysqlコマンドでTSVファイルを生成し、CSVに変換

実行自体は上記同様mysqlコマンドからですが、上記セクションを書いた後に下記のエントリを見つけて『あっ、こっちの方が全然スマートだわ』となったので併せてご紹介します。

まずはCSVの元となるデータを取得するSQL文を作成。

orders-extract.sql

SELECT
    CONCAT('"', order_id, '"') AS order_id,
    CONCAT('"', DATE_FORMAT(order_date,"%Y/%m/%d"), '"') AS order_date,
    CONCAT('"', priority, '"') AS priority,
    CONCAT('"', quantity, '"') AS quantity,
    CONCAT('"', sales, '"') AS sales,
    CONCAT('"', discount_rate, '"') AS discount_rate,
    CONCAT('"', ship_mode, '"') AS ship_mode,
    CONCAT('"', profit, '"') AS profit,
    CONCAT('"', unit_price, '"') AS unit_price,
    CONCAT('"', ad_expenses, '"') AS ad_expenses,
    CONCAT('"', shipping_cost, '"') AS shipping_cost,
    CONCAT('"', customer_name, '"') AS customer_name,
    CONCAT('"', prefecture, '"') AS prefecture,
    CONCAT('"', city, '"') AS city,
    CONCAT('"', area, '"') AS area,
    CONCAT('"', shop_name, '"') AS shop_name,
    CONCAT('"', customer_segment, '"') AS customer_segment,
    CONCAT('"', product_category, '"') AS product_category,
    CONCAT('"', product_sub_category, '"') AS product_sub_category,
    CONCAT('"', product_id, '"') AS product_id,
    CONCAT('"', product_name, '"') AS product_name,
    CONCAT('"', product_description, '"') AS product_description,
    CONCAT('"', product_container, '"') AS product_container,
    CONCAT('"', base_margin, '"') AS base_margin,
    CONCAT('"', supplier, '"') AS supplier,
    CONCAT('"', DATE_FORMAT(deliver_date,"%Y/%m/%d"), '"') AS deliver_date,
    CONCAT('"', DATE_FORMAT(ship_date,"%Y/%m/%d"), '"') AS ship_date
FROM
    orders;

SQL内容を展開した状態で実行させて、その結果をCSVに出力させます。

$ mysql -h xxxxxxx.yyyyyyy.us-east-1.rds.amazonaws.com \
-u(ユーザー名) \
-D (DB名) \
-e "`cat /xxxx/xxxx/xxxx/orders-extract.sql`" > orders-ext-result.csv

中身はTSV(タブ区切りファイル)となっていますので、

order_id        order_date      priority        quantity        sales   discount_rate   ship_mode       profit  unit_price      ad_expenses     shipping_cost   customer_name   prefecture      city    area    shop_name       customer_segment        product_category        product_sub_category    product_id      product_name    product_description     product_container       base_margin     supplier        deliver_date    ship_date
"55554" "2009/01/01"    "重要"  "6"     "15261" "0.04"  "通常航空便"    "-1520" "1897"  "230393"        "954"   "中谷 成広"     "宮崎"  "小林"  "九州"  "Morris"        "小規模事業所"  "事務用品"      "紙"    "P1186" "Xerox 1939"    "This is the field which has product description for Xerox 1939"        "小型>ボックス" "0.37"  "Elan"  "2009/02/02"    "2009/02/02"
"47873" "2009/01/01"    "重要"  "8"     "6548"  "0.08"  "通常航空便"    "-1738" "589"   "224716"        "557"   "吉津 正晃"     "大分"  "臼杵"  "九州"  "Coleman"       "企業"  "家具"  "オフィス家具"  "P428"  "Eldon Wave Desk Accessories"   "This is the field which has product description for Eldon Wave Desk Accessories"       "小型ボックス"  "0.41"  "Argot" "2009/03/10"    "2009/03/12"
"29187" "2009/01/02"    "低"    "10"    "9447"  "0"     "通常航空便"    "-4326" "648"   "443895"        "819"   "河本 訓治"     "愛知"  "名古屋"        "中部"  "Lane"  "消費者"        "事務用品"      "紙"    "P1248" "Xerox 217"     "This is the field which has product description for Xerox 217" "小型ボックス"  "0.37"  "Merxin"        "2009/01/23"    "2009/01/23"

sedコマンドでタブ文字をカンマに変換します。

$ mysql -h xxxxxxx.yyyyyyy.us-east-1.rds.amazonaws.com \
-u(ユーザー名) \
-D (DB名) \
-e "`cat /xxxx/xxxx/xxxx/orders-extract.sql`" \
| sed -e 's/\t/,/g' > orders-ext-result.csv

変換・生成結果は以下の通り。こちらの方法の方が全然良いですね。1個前のやつは忘れてくださいw

orders-ext-result.csv

order_id,order_date,priority,quantity,sales,discount_rate,ship_mode,profit,unit_price,ad_expenses,  shipping_cost,customer_name,prefecture,city,area,shop_name,customer_segment,product_category,product_sub_category,product_id,product_name,product_description,product_container,base_margin,supplier,deliver_date,ship_date
"55554","2009/01/01","重要","6","15261","0.04","通常航空便","-1520","1897","230393","954","中谷 成広","宮崎","小林","九州", "Morris","小規模事業所","事務用品","紙","P1186","Xerox 1939","This is the field which has product description for Xerox 1939","小型ボックス","0.37","Elan","2009/02/02","2009/02/02"
"47873","2009/01/01","重要","8","6548","0.08","通常航空便","-1738","589","224716","557","吉津 正晃","大分","臼杵","九州", "Coleman","企業","家具","オフィス家具","P428","Eldon Wave Desk Accessories","This is the field which has product description for Eldon Wave Desk Accessories","小型ボックス","0.41","Argot","2009/03/10","2009/03/12"
"29187","2009/01/02","低","10","9447","0","通常航空便","-4326","648","443895","819","河本 訓治","愛知","名古屋","中部","Lane","消費者","事務用品","紙","P1248","Xerox 217","This is the field which has product description for Xerox 217","小型ボックス","0.37","Merxin","2009/01/23","2009/01/23"
:

mysqldumpを使ってCSVをエクスポートする

MySQLには、mysqldumpというコマンドも用意されています。こちらで何らかCSVを出すことは可能なのでしょうか。

MySQLであれば、mysqldumpコマンドのオプションを使ってCSVの形式で結果を出力させる事は出来そうです。

がしかし、Amazon RDS(MySQL)で!となるとどうやら出来ない模様。

mysqldump単体ではRDS(MySQL)のデータをCSVでエクスポートするのは叶わなさそうですが、上記Qiitaで紹介されているpython製ツールを使う事で、お手軽にCSVファイルを出力させる事が出来そうです。

早速試してみましょう。git及びpythonが環境に入っている状態で、プロジェクトをクローンし、mysqldumpの結果を受けてpythonのツールを実行させ、結果をCSVとして出力します。mysqldumpのコマンドでは、データベース名 テーブル名の引数を与えています。

$ git clone https://github.com/jamesmishra/mysqldump-to-csv.git
Cloning into 'mysqldump-to-csv'...
remote: Counting objects: 29, done.
remote: Total 29 (delta 0), reused 0 (delta 0), pack-reused 29
Unpacking objects: 100% (29/29), done.
Checking connectivity... done.
$
$ python --version
Python 2.7.6
$ ls
LICENSE    README.md    mysqldump_to_csv.py    testcases.txt
$
$ mysqldump \
-h xxxxxxx.yyyyyyy.us-east-1.rds.amazonaws.com \
-u(ユーザー名) csvexpdb orders | \
python mysqldump_to_csv.py > orders-export-by-mysqldump_to_csv.csv

結果は以下の通りとなりました。ヘッダ部分は無し、囲み文字も無い状態のCSVとなっています。この形で差し支えなければ一番実行まで早い手順となるかもですね。

orders-export-by-mysqldump_to_csv.csv

55554,2009-01-01,重要,6,15261,0.04,通常航空便,-1520,1897,230393,954,中谷 成広,宮崎,小林,九州,Morris,小規模事業所,事務用品,紙,P1186,Xerox 1939,This is the field which has product description for Xerox 1939,小型ボックス,0.37,Elan,2009-02-02,2009-02-02
47873,2009-01-01,重要,8,6548,0.08,通常航空便,-1738,589,224716,557,吉津 正晃,大分,臼杵,九州,Coleman,企業,家具,オフィス家具,P428,Eldon Wave Desk Accessories,This is the field which has product description for Eldon Wave Desk Accessories,小型ボックス,0.41,Argot,2009-03-10,2009-03-12
29187,2009-01-02,低,10,9447,0,通常航空便,-4326,648,443895,819,河本 訓治,愛知,名古屋,中部,Lane,消費者,事務用品,紙,P1248,Xerox 217,This is the field which has product description for Xerox 217,小型ボックス,0.37,Merxin,2009-01-23,2009-01-23
24519,2009-01-02,重要,22,15945,0.03,通常航空便,-6072,534,219107,563,神保 雄二,京都,八幡,関西,Anderson,消費者,事務用品,バインダーとバインダー アクセサリー,P885,Pressboard Data Binder Crimson 12 X 8 1/2,This is the field which has product description for Pressboard Data Binder Crimson 12 X 8 1/2,小型ボックス,0.39,Elan,2009-04-01,2009-04-02
:

AWS Data PipelineでRDS(MySQL)からS3/Redshiftへデータをコピーする

AWSのサービスの1つであるAWS Data Pipelineでは、そのものズバリの『RDS(MySQL)からS3』へのコピーを行う処理を構築する事が可能です。用途的にも、『テーブル全体』『任意のテーブル』『インクリメンタルコピー』が可能となっている様です。

更には、RDS(MySQL)からAmazon Redshiftにコピーを行う処理を構築する事も可能となっています。

ETL/ELT周りをAWS Data Pipelineで構成している、現状でAWS Data Pipelineを活用しているという場合であれば、連携面を考慮してこの選択肢もアリなのではないでしょうか。

並列データ転送ツール『Embulk』を使う

2015年2月にリリースされ、大きな注目を集めたオープンソースの並列データ転送ツール『Embulk』を使ってデータを転送・集約させるという方法も検討案の有力候補として挙げてみても良いのではないでしょうか。

以下のエントリではキーワード的に"どストライク"な内容で、Embulkを活用した手順を紹介しています。MySQLの他にもデータをS3やRedshiftに取り込む必要があり、またその種類が多岐にわたる場合であればEmbulkでその辺りを一括して管理するという案もアリかも知れません。

まとめ

Amazon RedshiftにはUNLOADというSQLコマンドがあり比較的簡単にデータのエクスポートが出来ていたので、『MySQLもその辺サクッと行けるんじゃね?』と思っていましたが、調べてみると意外とそうでも無いのかな?or結構色々やり方はあるのね、と思った次第でした。後半はツール及び関連リンクの紹介に留まってしまいましたが、手法としてはそれぞれ有力なものではあると思いますので折を見て実践で使ってみたいしたいと思います。どれを採用するかは状況に応じて選択頂けますと幸いです。こちらからは以上です。