doc-exports/docs/ddm/umn/ddm_03_0031.html
Ru, Li Yi 4b09a03a51 ddm_umn
Reviewed-by: Wagner, Fabian <fabian.wagner@t-systems.com>
Co-authored-by: Ru, Li Yi <liyiru7@huawei.com>
Co-committed-by: Ru, Li Yi <liyiru7@huawei.com>
2024-04-11 11:39:26 +00:00

31 lines
7.7 KiB
HTML

<a name="ddm_03_0031"></a><a name="ddm_03_0031"></a>
<h1 class="topictitle1">LOAD DATA</h1>
<div id="body1597045079951"><div class="section" id="ddm_03_0031__s8fd2b790d2f142e390a1b9f1e18ae2d7"><h4 class="sectiontitle">Standard Example</h4><p id="ddm_03_0031__p11944104115499">LOAD DATA LOCAL INFILE '/data/data.txt' IGNORE INTO TABLE test CHARACTER SET 'utf8' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (id, sid, asf);</p>
</div>
<div class="note" id="ddm_03_0031__n76f3bfb0d6d84644b81090485adf669e"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="ddm_03_0031__p132788251228">If a data field contains special characters like separators and escapes, execute OPTIONALLY ENCLOSED BY '"' to enclose the field with double quotation marks ("").</p>
<p id="ddm_03_0031__p172210217215">Example:</p>
<p id="ddm_03_0031__p13316171821617">The following data field contains separators (,) and is enclosed with quotation marks:</p>
<p id="ddm_03_0031__p11626734141419"><strong id="ddm_03_0031__b16562132813210">"aab,,,bba,ddd"</strong></p>
<p id="ddm_03_0031__p38841126172217">If a data field contains quotation marks, the preceding method may not work. You can add a backslash (\) before each quotation mark (") in the field, for example, <strong id="ddm_03_0031__b888517247292">"aab,,,bba,ddd\"ddd\"bb,ae"</strong>.</p>
</div></div>
<ul id="ddm_03_0031__en-us_topic_0077295700_ul2811566712"><li class="msonormal" id="ddm_03_0031__en-us_topic_0077295700_li15814566718">If keyword <strong id="ddm_03_0031__b32228112816">LOCAL</strong> is specified, the file is read from the client host. If keyword <strong id="ddm_03_0031__b15925147112816">LOCAL</strong> is not specified, this function is not supported for security purposes.</li><li class="msonormal" id="ddm_03_0031__l6eb09b48b55d463e87c0696d622c89a7">You can use <strong id="ddm_03_0031__b34841612142815">FIELDS TERMINATED BY</strong> to specify a separator between characters. The default value is <strong id="ddm_03_0031__b16486131292811">\t</strong>.</li><li id="ddm_03_0031__l73dca3d4e8f246e8916b8fcde0bcfd88">You can use <strong id="ddm_03_0031__b945614214286">OPTIONALLY ENCLOSED BY</strong> to ignore symbols in the data source fields.</li><li class="msonormal" id="ddm_03_0031__l5ecb5831a0144542afca7c44b472d3e2">You can use <strong id="ddm_03_0031__b432854520285">LINES TERMINATED BY</strong> to specify a newline character between lines. The default value is <strong id="ddm_03_0031__b193308456280">\n</strong>.<div class="note" id="ddm_03_0031__en-us_topic_0077295700_note395042155"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="ddm_03_0031__en-us_topic_0077295700_p095015212510">On some hosts running the Windows OS, the newline character of text files may be <strong id="ddm_03_0031__b69487515285">\r\n</strong>. The newline character is invisible, so you may need to check whether it is there.</p>
</div></div>
</li><li class="msonormal" id="ddm_03_0031__en-us_topic_0077295700_li11431562818">You can use <strong id="ddm_03_0031__b135039952915">CHARACTER SET</strong> to specify a file code that should be the same as the code used by physical databases in the target RDS for MySQL instance, to avoid garbled characters. The character set code shall be enclosed in quotation marks to avoid parsing errors.</li><li class="msonormal" id="ddm_03_0031__en-us_topic_0077295700_li35111337916">You can use <strong id="ddm_03_0031__b117731615132916">IGNORE</strong> or <strong id="ddm_03_0031__b37743153297">REPLACE</strong> to specify whether repeated records are replaced or ignored.</li><li class="msonormal" id="ddm_03_0031__le5837d93053e408e8c4529ff7460e3e5">Currently, the column name must be specified, and the sharding field must be included. Otherwise, the route cannot be determined.</li><li class="msonormal" id="ddm_03_0031__laa798c13cc5a47f39a7b03d16eadc420">For other parameters, see the <a href="https://dev.mysql.com/doc/refman/8.0/en/load-data.html" target="_blank" rel="noopener noreferrer">LOAD DATA INFILE Syntax</a> on the MySQL official website. The sequence of other parameters must be correct. For more information, visit <a href="https://dev.mysql.com/doc/refman/8.0/en/load-data.html" target="_blank" rel="noopener noreferrer">the MySQL official website</a>.</li></ul>
<div class="notice" id="ddm_03_0031__ne238ab28d22d4ee98ec372aebae5e9cf"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><ol id="ddm_03_0031__o745f275d83f64e4e8db6b71d5815604c"><li id="ddm_03_0031__l3187145fdc8e4af895caf5bfc1b10c3b">Importing data affects performance of DDM instances and RDS for MySQL instances. Import data during off-peak hours.</li><li id="ddm_03_0031__en-us_topic_0077295700_li16699711229">Do not to send multiple LOAD DATA requests at the same time. If you do so, SQL transactions may time out due to highly concurrent data write operations, table locking, and system I/O occupation, resulting in failure of all LOAD DATA requests.</li><li id="ddm_03_0031__l5be15aa820fc4956896adfa6ac27c4d1">Manually submit transactions when using LOAD DATA to import data so that data records are modified correctly.<p id="ddm_03_0031__en-us_topic_0077295700_p29870133917"><a name="ddm_03_0031__l5be15aa820fc4956896adfa6ac27c4d1"></a><a name="l5be15aa820fc4956896adfa6ac27c4d1"></a>For example, configure your client as follows:</p>
<p id="ddm_03_0031__a3042407f1ee549b38fc47ca4cfb2f6fb"><strong id="ddm_03_0031__abf5f93116cd748498568a825971da0f4">mysql&gt; set autocommit=0; </strong><em id="ddm_03_0031__aaeeee4ed04ff4c279a4a1d46c3a064f4"></em></p>
<p id="ddm_03_0031__p1477615194534"><strong id="ddm_03_0031__b15775319205318">mysql&gt; </strong><strong id="ddm_03_0031__b2083018553538">LOAD DATA LOCAL INFILE</strong> '/data/data.txt' <strong id="ddm_03_0031__b6314219545">IGNORE INTO TABLE</strong> <strong id="ddm_03_0031__b117941525419">test CHARACTER SET</strong> <strong id="ddm_03_0031__b53151244205412">'utf8' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (id, sid, asf);</strong></p>
<p id="ddm_03_0031__en-us_topic_0077295700_p46101925395"><strong id="ddm_03_0031__ad1a8e7dbb6d445e7b2f68ad620cae15c">mysql&gt; commit;</strong></p>
</li></ol>
</div></div>
<div class="section" id="ddm_03_0031__s3d5ff5d75d634f4f922235e072427269"><h4 class="sectiontitle">Use Constraints</h4><p id="ddm_03_0031__p198410167175">There are the following constraints on LOAD DATA syntax.</p>
<ul id="ddm_03_0031__u503e8adfa28a48f191bb99a25ad94579"><li id="ddm_03_0031__li7615184019393">LOW_PRIORITY is not supported.</li><li id="ddm_03_0031__li6737195583919">CONCURRENT is not supported.</li><li id="ddm_03_0031__li97314104012">PARTITION (partition_name [, partition_name] ...) is not supported.</li><li id="ddm_03_0031__li8540151215447">LINES STARTING BY 'string' is not supported.</li><li id="ddm_03_0031__li761442174417">User-defined variables are not supported.</li><li id="ddm_03_0031__li443884114515">ESCAPED BY supports only '\\'.</li><li id="ddm_03_0031__li1546101424520">If you have not specified a value for your auto-increment key when you insert a data record, DDM will not fill a value for the key. The auto-increment keys of data nodes of a DDM instance all take effect, so the auto-increment key values may be duplicate.</li><li id="ddm_03_0031__li152397175459">If the primary key or unique index is not routed to the same physical table, REPLACE does not take effect.</li><li id="ddm_03_0031__li19357203119455">If the primary key or unique index is not routed to the same physical table, IGNORE does not take effect.</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="ddm_08_0002.html">Supported SQL Statements</a></div>
</div>
</div>