{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"MySQL Tables Export Integration CLI","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"mysql-tables-export-integration-cli","__idx":0},"children":["MySQL Tables Export Integration CLI"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["CLIを使用してクエリを発行し、結果を出力することができます。以下の手順では、CLIを使用してクエリ出力結果をフォーマットする方法を説明します。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"td-queryコマンドの使用方法","__idx":1},"children":["TD Queryコマンドの使用方法"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["単一のクエリの結果をMySQLサーバーに出力するには、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td query"]},"コマンドに",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["--result"]},"オプションを追加します。ジョブが完了すると、結果がデータベースに書き込まれます:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ td query --result 'mysql://user:password@host/database/table' \\\n  -w -d testdb \\\n  \"SELECT code, COUNT(1) FROM www_access GROUP BY code\"\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"スケジュールされたジョブ","__idx":2},"children":["スケジュールされたジョブ"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["出力が体系的にMySQLに書き込まれるスケジュールされたクエリを作成するには、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td sched:create"]},"コマンドでスケジュールを作成する際に",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["--result"]},"オプションを追加します。ジョブが実行されるたびに、結果が",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mytbl"]},"に書き込まれます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ td result:create mydb mysql://user:password@host/database\n$ td sched:create hourly_count_example \"0 * * * *\" -d testdb \"select count(*) from www_access\" --result mydb:mytbl\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"結果出力urlフォーマット","__idx":3},"children":["結果出力URLフォーマット"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["結果出力先は、以下の形式のURLで表されます:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql://username:password@hostname:port/database/table\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ここで:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["mysql"]}," は、MySQLへの結果出力を示します"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["username"]}," と ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["password"]}," は、MySQLサーバーへの認証情報です"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["hostname"]}," は、MySQLサーバーのホスト名です"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["port"]}," は、MySQLサーバーにアクセスできるポート番号です。「:」はオプションであり、デフォルトでは3306と想定されます"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["database"]}," は、宛先データベースの名前です"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["table"]}," は、上記のデータベース内のテーブルの名前です。クエリ出力の実行時に存在しない場合もありますが、その場合はユーザーのために指定された名前のテーブルが作成されます"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"オプション","__idx":4},"children":["オプション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ジョブ結果のMySQLサーバーへの書き込みは、以下のオプションをサポートしています。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"データを変更するモードappendreplacetruncateupdate","__idx":5},"children":["データを変更するモード（Append/Replace/Truncate/Update）"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["データを4つの方法で追加または削除できます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql://user:password@host/database/table               # append\nmysql://user:password@host/database/table?mode=append   # append\nmysql://user:password@host/database/table?mode=replace  # replace\nmysql://user:password@host/database/table?mode=truncate # truncate\nmysql://user:password@host/database/table?mode=update   # update\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["4つのモードすべてが",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["アトミック"]},"です。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["「host」セクションでは、ポートも指定できます。"]}," 以下は例です:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql://superadmin:superstrongpassword@data.science.com:27013/transaction/user_info\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"append","__idx":6},"children":["APPEND"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["これはデフォルトのモードです。クエリ結果はテーブルに追加されます。テーブルが存在しない場合は、新しいテーブルが作成されます。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"replace","__idx":7},"children":["REPLACE"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["テーブルがすでに存在する場合、既存のテーブルの行はクエリ結果で置き換えられます。テーブルが存在しない場合は、新しいテーブルが作成されます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["単一のトランザクション"]},"で以下の3つのステップを実行することにより、",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["アトミック性"]},"（テーブルのコンシューマーが常に一貫性のあるデータを持つように）を実現します。"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["一時テーブルを作成します。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["一時テーブルに書き込みます。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["ALTER TABLE RENAMEを使用して、既存のテーブルを一時テーブルで置き換えます。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["replaceモードを使用すると、MySQLテーブルのスキーマが変更される可能性があります。ターゲットテーブルへのスキーマ変更を避けるには、「Preserve schema?」オプションを選択してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"truncate","__idx":8},"children":["TRUNCATE"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["システムは最初に既存のテーブルをトランケートし、次にクエリ結果を挿入します。テーブルが存在しない場合は、新しいテーブルが作成されます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["REPLACEとは異なり、TRUNCATEはテーブルのインデックスを保持します。"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"update","__idx":9},"children":["UPDATE"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["このモードは、以下のステップを実行することにより、新しいデータを挿入し、既存のデータを更新します。"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["一時テーブルを作成します。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["一時テーブルに書き込みます。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["一時テーブルから宛先テーブルにデータを更新します。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["一時テーブルから宛先テーブルに残りのデータを挿入します。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["一意キーを指定するには、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["unique"]},"パラメータを設定できます。これはキーのカンマ区切りのリストです。すべてのキーの値が既存のレコードのすべてと一致する場合、そのレコードは置き換えられます。以下は例です:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql://superadmin:superstrongpassword@data.science.com:27013/transaction/user_infomode=update&unique=column1%2Ccolumn2\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["CLIでは、パラメータ内のカンマはURLエンコードする必要があります（「,」は「%2C」にする必要があります）。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"追加オプション","__idx":10},"children":["追加オプション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ジョブ結果のMySQLサーバーへの書き込みは、オプションのURLパラメータとして指定できる以下の追加オプションをサポートしています。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sslオプション","__idx":11},"children":["sslオプション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["ssl"]},"オプションは、MySQLサーバーへの接続にSSLを使用するかどうかを決定します。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"ssltrue","__idx":12},"children":["ssl=true"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure DataからMySQLサーバーへの接続にSSLを使用します。MySQLサーバーは、SSL接続を受け入れるように設定されている必要があります。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql://user:password@host/database/table?ssl=true\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"sslfalseデフォルト","__idx":13},"children":["ssl=false（デフォルト）"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure DataからMySQLサーバーへSSLを使用しません。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql://user:password@host/database/table?ssl=false\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"文字エンコーディング","__idx":14},"children":["文字エンコーディング"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Dataは常に文字エンコーディングとしてUTF-8を使用します。また、デフォルトでUTF-8を使用するようにデータベースを設定する必要があります。エンコーディングに関連する問題が発生した場合は、以下の設定を確認してください。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"mysql> show variables like 'char%';\n+--------------------------+----------------------------+\n| Variable_name | Value |\n+--------------------------+----------------------------+\n| character_set_client | utf8 |\n| character_set_connection | utf8 |\n| character_set_database | utf8 |\n| character_set_filesystem | binary |\n| character_set_results | utf8 |\n| character_set_server | utf8 |\n| character_set_system | utf8 |\n| character_sets_dir | /usr/share/mysql/charsets/ |\n+--------------------------+----------------------------+\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"mysqlのint-unsigned型","__idx":15},"children":["MySQLのINT UNSIGNED型"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["MySQLへのジョブ結果は、MySQLのINT UNSIGNED型をサポートしていません。その値は予期しない値に変換されます。"]}]},"headings":[{"value":"MySQL Tables Export Integration CLI","id":"mysql-tables-export-integration-cli","depth":1},{"value":"TD Queryコマンドの使用方法","id":"td-queryコマンドの使用方法","depth":2},{"value":"スケジュールされたジョブ","id":"スケジュールされたジョブ","depth":2},{"value":"結果出力URLフォーマット","id":"結果出力urlフォーマット","depth":2},{"value":"オプション","id":"オプション","depth":2},{"value":"データを変更するモード（Append/Replace/Truncate/Update）","id":"データを変更するモードappendreplacetruncateupdate","depth":3},{"value":"APPEND","id":"append","depth":4},{"value":"REPLACE","id":"replace","depth":4},{"value":"TRUNCATE","id":"truncate","depth":4},{"value":"UPDATE","id":"update","depth":4},{"value":"追加オプション","id":"追加オプション","depth":3},{"value":"sslオプション","id":"sslオプション","depth":2},{"value":"ssl=true","id":"ssltrue","depth":3},{"value":"ssl=false（デフォルト）","id":"sslfalseデフォルト","depth":3},{"value":"文字エンコーディング","id":"文字エンコーディング","depth":4},{"value":"MySQLのINT UNSIGNED型","id":"mysqlのint-unsigned型","depth":4}],"frontmatter":{"seo":{"title":"MySQL Tables Export Integration CLI"}},"lastModified":"2025-11-13T03:31:21.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/int/mysql-tables-export-integration-cli","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}