<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>{ Berbagi, Menulis, Dan Mengajar } Ilmu... &#187; MYSQL</title>
	<atom:link href="http://dimas.ubhara.id/category/programming/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://dimas.ubhara.id</link>
	<description>sampaikanlah ilmu walau satu ayat</description>
	<lastBuildDate>Mon, 09 Feb 2026 04:09:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Update</title>
		<link>http://dimas.ubhara.id/2011/05/update/</link>
		<comments>http://dimas.ubhara.id/2011/05/update/#comments</comments>
		<pubDate>Sun, 08 May 2011 09:23:53 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://dimas.ubhara.id/?p=1285</guid>
		<description><![CDATA[UPDATE `pangkat`
SET
`Golongan`='IV',
`Ruang`='B',
`TMT`='12-12-2001',
`Gapok`='12000'
WHERE
	 `Kd_Pangkat`='G04'

]]></description>
				<content:encoded><![CDATA[<pre><code>UPDATE `pangkat`
SET
`Golongan`='IV',
`Ruang`='B',
`TMT`='12-12-2001',
`Gapok`='12000'
WHERE
	 `Kd_Pangkat`='G04'
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2011/05/update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dasar INSERT INTO</title>
		<link>http://dimas.ubhara.id/2011/05/dasar-update/</link>
		<comments>http://dimas.ubhara.id/2011/05/dasar-update/#comments</comments>
		<pubDate>Sun, 08 May 2011 08:59:52 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://dimas.ubhara.id/?p=1281</guid>
		<description><![CDATA[insert into `dbpenggajian`.`pangkat`(`Kd_Pangkat`,`Golongan`,`Ruang`,`TMT`,`Gapok`) values ( NULL,&#8217;877&#8242;,NULL,NULL,NULL)
Contoh
insert into `pangkat`(`Kd_Pangkat`,`Golongan`,`Ruang`,`TMT`,`Gapok`) VALUES('001','II','C','00-11-2011','2500')

]]></description>
				<content:encoded><![CDATA[<p>insert into `dbpenggajian`.`pangkat`(`Kd_Pangkat`,`Golongan`,`Ruang`,`TMT`,`Gapok`) values ( NULL,&#8217;877&#8242;,NULL,NULL,NULL)</p>
<p>Contoh</p>
<pre><code>insert into `pangkat`(`Kd_Pangkat`,`Golongan`,`Ruang`,`TMT`,`Gapok`) VALUES('001','II','C','00-11-2011','2500')
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2011/05/dasar-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inner Join</title>
		<link>http://dimas.ubhara.id/2011/04/inner-join/</link>
		<comments>http://dimas.ubhara.id/2011/04/inner-join/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 08:37:01 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://dimas.ubhara.id/?p=1225</guid>
		<description><![CDATA[(3:36:16 PM) dimas_4dityo: boss&#8230;INNER JOIN Kie piye ??
(3:36:22 PM) dimas_4dityo: pengertian konsep e
(3:37:25 PM) punyadony: nggabungno dua tabel.. penggabungane, berdasar ndek field key yg bersesuaian ndek masing2 tabel
(3:37:52 PM) punyadony: tabel A : NIP, Nama, Alamat
(3:38:11 PM) punyadony: tabel B : NIP, Gaji, Bonus
(3:38:21 PM) punyadony: nah join e
(3:39:31 PM) punyadony: select a.nama, a.alamat, b.gaji, b.bonus from A a inner join B b on a.NIP = b.NIP
(3:40:01 PM) dimas_4dityo: oo&#8230;
(3:40:05 PM) dimas_4dityo: oke2x
(3:40:29 PM) punyadony: ok2
]]></description>
				<content:encoded><![CDATA[<p><span style="color: #204a87;"><span style="font-size: x-small;">(3:36:16 PM) </span></span>dimas_4dityo: boss&#8230;INNER JOIN Kie piye ??<br />
<span style="color: #204a87;"><span style="font-size: x-small;">(3:36:22 PM) </span></span>dimas_4dityo: pengertian konsep e<br />
<span style="font-size: x-small;"><span style="color: #cc0000;">(3:37:25 PM) </span></span>punyadony: nggabungno dua tabel.. penggabungane, berdasar ndek field key yg bersesuaian ndek masing2 tabel<br />
<span style="font-size: x-small;"><span style="color: #cc0000;">(3:37:52 PM) </span></span>punyadony: tabel A : NIP, Nama, Alamat<br />
<span style="font-size: x-small;"><span style="color: #cc0000;">(3:38:11 PM) </span></span>punyadony: tabel B : NIP, Gaji, Bonus<br />
<span style="font-size: x-small;"><span style="color: #cc0000;">(3:38:21 PM) </span></span>punyadony: nah join e<br />
<span style="font-size: x-small;"><span style="color: #cc0000;">(3:39:31 PM) </span></span>punyadony: select a.nama, a.alamat, b.gaji, b.bonus from A a inner join B b on a.NIP = b.NIP<br />
<span style="color: #204a87;"><span style="font-size: x-small;">(3:40:01 PM) </span></span>dimas_4dityo: oo&#8230;<br />
<span style="color: #204a87;"><span style="font-size: x-small;">(3:40:05 PM) </span></span>dimas_4dityo: oke2x<br />
<span style="font-size: x-small;"><span style="color: #cc0000;">(3:40:29 PM) </span></span>punyadony: ok2</p>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2011/04/inner-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial MYSQL</title>
		<link>http://dimas.ubhara.id/2011/04/tutorial-mysql/</link>
		<comments>http://dimas.ubhara.id/2011/04/tutorial-mysql/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 08:28:35 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://dimas.ubhara.id/?p=1224</guid>
		<description><![CDATA[http://www.java2s.com/Tutorial/MySQL/0100__Table-Join/0040__Inner-Join.htm
]]></description>
				<content:encoded><![CDATA[<p>http://www.java2s.com/Tutorial/MySQL/0100__Table-Join/0040__Inner-Join.htm</p>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2011/04/tutorial-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysqldump Piye Nggawene ?</title>
		<link>http://dimas.ubhara.id/2008/09/mysqldump-piye-nggawene/</link>
		<comments>http://dimas.ubhara.id/2008/09/mysqldump-piye-nggawene/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 03:54:45 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://dimas.ubhara.id/?p=276</guid>
		<description><![CDATA[CONSOL >#$ mysqldump -u root -p &#8211;databases noc_db > noc_db.sql
]]></description>
				<content:encoded><![CDATA[<p>CONSOL >#$ mysqldump -u root -p &#8211;databases noc_db > noc_db.sql</p>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2008/09/mysqldump-piye-nggawene/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>itegno lagi</title>
		<link>http://dimas.ubhara.id/2008/04/itegno-lagi/</link>
		<comments>http://dimas.ubhara.id/2008/04/itegno-lagi/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 08:35:21 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[8. Data Comm / Inet of Things (IoT)]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://blog.ptpn-xi.com/?p=158</guid>
		<description><![CDATA[Ada Yang Butuh Itegno &#8211; 3000 
Namanya Pak Gunadi 
No HP : 031-70359992
]]></description>
				<content:encoded><![CDATA[<p>Ada Yang Butuh Itegno &#8211; 3000 </p>
<p>Namanya Pak Gunadi </p>
<p>No HP : 031-70359992</p>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2008/04/itegno-lagi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From Excel To Mysql &#8211; 2</title>
		<link>http://dimas.ubhara.id/2008/04/from-excel-to-mysql-2/</link>
		<comments>http://dimas.ubhara.id/2008/04/from-excel-to-mysql-2/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 16:27:27 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://blog.ptpn-xi.com/?p=154</guid>
		<description><![CDATA[Excel Ke MySQLCara nie agak panjang sikit berbanding cara lain (mungkin ada yang lebih senang)
Tapi memang boleh dipraktikkan. 

Fail disimpan (Save As) CVS


Buka PHPMyAdmin dan buat 1 DATABASE.

Kemudian buat 1 TABLE
No of field 5 (mengikut kesesuaian rekod dari Excel)

IMPORT FAIL

Setelah selesai membuat Database dan Table, klik Table, Import, Browse fail CVS
Pilih CVS Load Data, Field terminate by , (comma)
Klik GO


Add New User &#8211; jika belum

Uji Connection guna Dreamweaver

Hasilnya boleh dilihat dalam web browser. (IE)
OK.
]]></description>
				<content:encoded><![CDATA[<div id="post-677760" class="postcolor"><u><strong>Excel Ke MySQL</strong></u>Cara nie agak panjang sikit berbanding cara lain (mungkin ada yang lebih senang)<br />
Tapi memang boleh dipraktikkan. <img border="0" alt="http://dimas.ubhara.id/wp-content/uploads/2008/04/biggrin1.gif" style="vertical-align: middle" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/biggrin1.gif" /></p>
<p><img border="0" alt="262208c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/262208c.jpg" /><br />
Fail disimpan (Save As) <strong>CVS</strong></p>
<p><img border="0" alt="280163c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/280163c.jpg" /></p>
<p><img border="0" alt="764304c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/764304c.jpg" /><br />
Buka PHPMyAdmin dan buat 1 DATABASE.</p>
<p><img border="0" alt="653877c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/653877c.jpg" /><br />
Kemudian buat 1 TABLE<br />
No of field 5 (mengikut kesesuaian rekod dari Excel)</p>
<p><img border="0" alt="281945c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/281945c.jpg" /></p>
<p><u><strong>IMPORT FAIL</strong></u></p>
<p><img border="0" alt="298646c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/298646c.jpg" /><br />
Setelah selesai membuat Database dan Table, klik Table, Import, Browse fail CVS<br />
Pilih CVS Load Data, Field terminate by <span style="font-size: 12pt; line-height: 100%"><strong>,</strong> </span>(comma)<br />
Klik GO</p>
<p><img border="0" alt="55805cv" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/55805cv.jpg" /></p>
<p><img border="0" alt="663300c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/663300c.jpg" /><br />
Add New User &#8211; jika belum</p>
<p><img border="0" alt="980424c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/980424c.jpg" /><br />
Uji Connection guna Dreamweaver</p>
<p><img border="0" alt="408601c" class="linked-image" src="http://dimas.ubhara.id/wp-content/uploads/2008/04/408601c.jpg" /><br />
Hasilnya boleh dilihat dalam web browser. (IE)</p>
<p>OK.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2008/04/from-excel-to-mysql-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From Excel To Mysql 1</title>
		<link>http://dimas.ubhara.id/2008/04/from-excel-to-mysql/</link>
		<comments>http://dimas.ubhara.id/2008/04/from-excel-to-mysql/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 16:14:01 +0000</pubDate>
		<dc:creator><![CDATA[dms]]></dc:creator>
				<category><![CDATA[4. Programming / IDE]]></category>
		<category><![CDATA[MYSQL]]></category>

		<guid isPermaLink="false">http://blog.ptpn-xi.com/?p=153</guid>
		<description><![CDATA[



12.2.5. LOAD DATA INFILE Syntax



LOAD DATA [LOW_PRIORITY &#124; CONCURRENT] [LOCAL] INFILE &#8217;file_name&#8217;
    [REPLACE &#124; IGNORE]
    INTO TABLE tbl_name
    [CHARACTER SET charset_name]
    [FIELDS
        [TERMINATED BY &#8217;string&#8217;]
        [[OPTIONALLY] ENCLOSED BY &#8217;char&#8217;]
        [ESCAPED BY &#8217;char&#8217;]
    ]
    [LINES
        [STARTING BY &#8217;string&#8217;]
        [TERMINATED BY &#8217;string&#8217;]
    ]
    [IGNORE number LINES]
    [(col_name_or_user_var,...)]
    [SET col_name = expr,...]

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. The filename must be given as a literal string. 
LOAD DATA INFILE is the complement of SELECT ... ...]]></description>
				<content:encoded><![CDATA[<div class="section" lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title">12.2.5. <code class="literal">LOAD DATA INFILE</code> Syntax</h3>
</div>
</div>
</div>
<pre class="programlisting">LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE &rsquo;<em class="replaceable"><code>file_name</code></em>&rsquo;
    [REPLACE | IGNORE]
    INTO TABLE <em class="replaceable"><code>tbl_name</code></em>
    [CHARACTER SET <em class="replaceable"><code>charset_name</code></em>]
    [FIELDS
        [TERMINATED BY &rsquo;<em class="replaceable"><code>string</code></em>&rsquo;]
        [[OPTIONALLY] ENCLOSED BY &rsquo;<em class="replaceable"><code>char</code></em>&rsquo;]
        [ESCAPED BY &rsquo;<em class="replaceable"><code>char</code></em>&rsquo;]
    ]
    [LINES
        [STARTING BY &rsquo;<em class="replaceable"><code>string</code></em>&rsquo;]
        [TERMINATED BY &rsquo;<em class="replaceable"><code>string</code></em>&rsquo;]
    ]
    [IGNORE <em class="replaceable"><code>number</code></em> LINES]
    [(<em class="replaceable"><code>col_name_or_user_var</code></em>,...)]
    [SET <em class="replaceable"><code>col_name</code></em> = <em class="replaceable"><code>expr</code></em>,...]
</pre>
<p>The <code class="literal">LOAD DATA INFILE</code> statement reads rows from a text file into a table at a very high speed. The filename must be given as a literal string. </p>
<p><code class="literal">LOAD DATA INFILE</code> is the complement of <code class="literal">SELECT ... INTO OUTFILE</code>. (See <a title="12.2.7.&amp;amp;nbsp;SELECT Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/select.html" >Section 12.2.7, â€œ<code class="literal">SELECT</code> Syntaxâ€</a>.) To write data from a table to a file, use <code class="literal">SELECT ... INTO OUTFILE</code>. To read the file back into a table, use <code class="literal">LOAD DATA INFILE</code>. The syntax of the <code class="literal">FIELDS</code> and <code class="literal">LINES</code> clauses is the same for both statements. Both clauses are optional, but <code class="literal">FIELDS</code> must precede <code class="literal">LINES</code> if both are specified. </p>
<p>For more information about the efficiency of <code class="literal">INSERT</code> versus <code class="literal">LOAD DATA INFILE</code> and speeding up <code class="literal">LOAD DATA INFILE</code>, see <a title="7.2.17.&amp;amp;nbsp;Speed of INSERT Statements" href="http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html" >Section 7.2.17, â€œSpeed of <code class="literal">INSERT</code> Statementsâ€</a>. </p>
<p>The character set indicated by the <code class="literal">character_set_database</code> system variable is used to interpret the information in the file. <code class="literal">SET NAMES</code> and the setting of <code class="literal">character_set_client</code> do not affect interpretation of input. If the contents of the input file use a character set that differs from the default, it is usually preferable to specify the character set of the file by using the <code class="literal">CHARACTER SET</code> clause, which is available as of MySQL 5.1.17. </p>
<p><code class="literal">LOAD DATA INFILE</code> interprets all fields in the file as having the same character set, regardless of the data types of the columns into which field values are loaded. For proper interpretation of file contents, you must ensure that it was written with the correct character set. For example, if you write a data file with <span><strong class="command">mysqldump -T</strong></span> or by issuing a <code class="literal">SELECT ... INTO OUTFILE</code> statement in <span><strong class="command">mysql</strong></span>, be sure to use a <code class="option">--default-character-set</code> option with <span><strong class="command">mysqldump</strong></span> or <span><strong class="command">mysql</strong></span> so that output is written in the character set to be used when the file is loaded with <code class="literal">LOAD DATA INFILE</code>. </p>
<p>Note that it is currently not possible to load data files that use the <code class="literal">ucs2</code> character set. </p>
<p>As of MySQL 5.0.19, the <code class="literal">character_set_filesystem</code> system variable controls the interpretation of the filename. </p>
<p>You can also load data files by using the <span><strong class="command">mysqlimport</strong></span> utility; it operates by sending a <code class="literal">LOAD DATA INFILE</code> statement to the server. The <code class="option">--local</code> option causes <span><strong class="command">mysqlimport</strong></span> to read data files from the client host. You can specify the <code class="option">--compress</code> option to get better performance over slow networks if the client and server support the compressed protocol. See <a title="4.5.5.&amp;amp;nbsp;mysqlimport - A Data Import Program" href="http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html" >Section 4.5.5, â€œ<span><strong class="command">mysqlimport</strong></span> &#8211; A Data Import Programâ€</a>. </p>
<p>If you use <code class="literal">LOW_PRIORITY</code>, execution of the <code class="literal">LOAD DATA</code> statement is delayed until no other clients are reading from the table. This affects only storage engines that use only table-level locking (<code class="literal">MyISAM</code>, <code class="literal">MEMORY</code>, <code class="literal">MERGE</code>). </p>
<p>If you specify <code class="literal">CONCURRENT</code> with a <code class="literal">MyISAM</code> table that satisfies the condition for concurrent inserts (that is, it contains no free blocks in the middle), other threads can retrieve data from the table while <code class="literal">LOAD DATA</code> is executing. Using this option affects the performance of <code class="literal">LOAD DATA</code> a bit, even if no other thread is using the table at the same time. </p>
<p>The <code class="literal">LOCAL</code> keyword, if specified, is interpreted with respect to the client end of the connection: </p>
<div class="itemizedlist">
<ul>
<li>
<p>If <code class="literal">LOCAL</code> is specified, the file is read by the client program on the client host and sent to the server. The file can be given as a full pathname to specify its exact location. If given as a relative pathname, the name is interpreted relative to the directory in which the client program was started. </p>
</li>
<li>
<p>If <code class="literal">LOCAL</code> is not specified, the file must be located on the server host and is read directly by the server. The server uses the following rules to locate the file: </p>
<div class="itemizedlist"></li>
<ul></li>
<li>
<p>If the filename is an absolute pathname, the server uses it as given. </p>
</li>
<li>
<p>If the filename is a relative pathname with one or more leading components, the server searches for the file relative to the server&rsquo;s data directory. </p>
</li>
<li>
<p>If a filename with no leading components is given, the server looks for the file in the database directory of the default database. </p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>Note that, in the non-<code class="literal">LOCAL</code> case, these rules mean that a file named as <code class="filename">./myfile.txt</code> is read from the server&rsquo;s data directory, whereas the file named as <code class="filename">myfile.txt</code> is read from the database directory of the default database. For example, if <code class="literal">db1</code> is the default database, the following <code class="literal">LOAD DATA</code> statement reads the file <code class="filename">data.txt</code> from the database directory for <code class="literal">db1</code>, even though the statement explicitly loads the file into a table in the <code class="literal">db2</code> database: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;data.txt&rsquo; INTO TABLE db2.my_table;
</pre>
<p>Windows pathnames are specified using forward slashes rather than backslashes. If you do use backslashes, you must double them. </p>
<p>For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use <code class="literal">LOAD DATA INFILE</code> on server files, you must have the <code class="literal">FILE</code> privilege. See <a title="5.4.3.&amp;amp;nbsp;Privileges Provided by MySQL" href="http://dev.mysql.com/doc/refman/5.0/en/privileges-provided.html" >Section 5.4.3, â€œPrivileges Provided by MySQLâ€</a>. </p>
<p>Using <code class="literal">LOCAL</code> is a bit slower than letting the server access the files directly, because the contents of the file must be sent over the connection by the client to the server. On the other hand, you do not need the <code class="literal">FILE</code> privilege to load local files. </p>
<p><code class="literal">LOCAL</code> works only if your server and your client both have been enabled to allow it. For example, if <span><strong class="command">mysqld</strong></span> was started with <code class="option">--local-infile=0</code>, <code class="literal">LOCAL</code> does not work. See <a title="5.3.4.&amp;amp;nbsp;Security Issues with LOAD DATA LOCAL" href="http://dev.mysql.com/doc/refman/5.0/en/load-data-local.html" >Section 5.3.4, â€œSecurity Issues with <code class="literal">LOAD DATA LOCAL</code>â€</a>. </p>
<p>On Unix, if you need <code class="literal">LOAD DATA</code> to read from a pipe, you can use the following technique (here we load the listing of the <code class="filename">/</code> directory into a table): </p>
<pre class="programlisting">mkfifo /mysql/db/x/x
chmod 666 /mysql/db/x/x
find / -ls &gt; /mysql/db/x/x &amp;
mysql -e &quot;LOAD DATA INFILE &rsquo;x&rsquo; INTO TABLE x&quot; x
</pre>
<p>Note that you must run the command that generates the data to be loaded and the <span><strong class="command">mysql</strong></span> commands either on separate terminals, or run the data generation process in the background (as shown in the preceding example). If you do not do this, the pipe will block until data is read by the <span><strong class="command">mysql</strong></span> process. </p>
<p>The <code class="literal">REPLACE</code> and <code class="literal">IGNORE</code> keywords control handling of input rows that duplicate existing rows on unique key values: </p>
<div class="itemizedlist">
<ul>
<li>
<p>If you specify <code class="literal">REPLACE</code>, input rows replace existing rows. In other words, rows that have the same value for a primary key or unique index as an existing row. See <a title="12.2.6.&amp;amp;nbsp;REPLACE Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/replace.html" >Section 12.2.6, â€œ<code class="literal">REPLACE</code> Syntaxâ€</a>. </p>
</li>
<li>
<p>If you specify <code class="literal">IGNORE</code>, input rows that duplicate an existing row on a unique key value are skipped. If you do not specify either option, the behavior depends on whether the <code class="literal">LOCAL</code> keyword is specified. Without <code class="literal">LOCAL</code>, an error occurs when a duplicate key value is found, and the rest of the text file is ignored. With <code class="literal">LOCAL</code>, the default behavior is the same as if <code class="literal">IGNORE</code> is specified; this is because the server has no way to stop transmission of the file in the middle of the operation. </p>
</li>
</ul>
</div>
<p>If you want to ignore foreign key constraints during the load operation, you can issue a <code class="literal">SET FOREIGN_KEY_CHECKS=0</code> statement before executing <code class="literal">LOAD DATA</code>. </p>
<p>If you use <code class="literal">LOAD DATA INFILE</code> on an empty <code class="literal">MyISAM</code> table, all non-unique indexes are created in a separate batch (as for <code class="literal">REPAIR TABLE</code>). Normally, this makes <code class="literal">LOAD DATA INFILE</code> much faster when you have many indexes. In some extreme cases, you can create the indexes even faster by turning them off with <code class="literal">ALTER TABLE ... DISABLE KEYS</code> before loading the file into the table and using <code class="literal">ALTER TABLE ... ENABLE KEYS</code> to re-create the indexes after loading the file. See <a title="7.2.17.&amp;amp;nbsp;Speed of INSERT Statements" href="http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html" >Section 7.2.17, â€œSpeed of <code class="literal">INSERT</code> Statementsâ€</a>. </p>
<p>For both the <code class="literal">LOAD DATA INFILE</code> and <code class="literal">SELECT ... INTO OUTFILE</code> statements, the syntax of the <code class="literal">FIELDS</code> and <code class="literal">LINES</code> clauses is the same. Both clauses are optional, but <code class="literal">FIELDS</code> must precede <code class="literal">LINES</code> if both are specified. </p>
<p>If you specify a <code class="literal">FIELDS</code> clause, each of its subclauses (<code class="literal">TERMINATED BY</code>, <code class="literal">[OPTIONALLY] ENCLOSED BY</code>, and <code class="literal">ESCAPED BY</code>) is also optional, except that you must specify at least one of them. </p>
<p>If you specify no <code class="literal">FIELDS</code> clause, the defaults are the same as if you had written this: </p>
<pre class="programlisting">FIELDS TERMINATED BY &rsquo;&rsquo;t&rsquo; ENCLOSED BY &rsquo;&rsquo; ESCAPED BY &rsquo;&rsquo;&rsquo;&rsquo;
</pre>
<p>If you specify no <code class="literal">LINES</code> clause, the defaults are the same as if you had written this: </p>
<pre class="programlisting">LINES TERMINATED BY &rsquo;&rsquo;n&rsquo; STARTING BY &rsquo;&rsquo;
</pre>
<p>In other words, the defaults cause <code class="literal">LOAD DATA INFILE</code> to act as follows when reading input: </p>
<div class="itemizedlist">
<ul>
<li>
<p>Look for line boundaries at newlines. </p>
<li>
<p>Do not skip over any line prefix. </p>
<li>
<p>Break lines into fields at tabs. </p>
<li>
<p>Do not expect fields to be enclosed within any quoting characters. </p>
<li>
<p>Interpret occurrences of tab, newline, or â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€ preceded by â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€ as literal characters that are part of field values. </p>
</li>
</ul>
</div>
<p>Conversely, the defaults cause <code class="literal">SELECT ... INTO OUTFILE</code> to act as follows when writing output: </p>
<div class="itemizedlist">
<ul>
<li>
<p>Write tabs between fields. </p>
<li>
<p>Do not enclose fields within any quoting characters. </p>
<li>
<p>Use â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€ to escape instances of tab, newline, or â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€ that occur within field values. </p>
<li>
<p>Write newlines at the ends of lines. </p>
</li>
</ul>
</div>
<p>Backslash is the MySQL escape character within strings, so to write <code class="literal">FIELDS ESCAPED BY &rsquo;&rsquo;&rsquo;&rsquo;</code>, you must specify two backslashes for the value to be interpreted as a single backslash. </p>
<div style="MARGIN-LEFT: 0.5in; MARGIN-RIGHT: 0.5in" class="note">
<h3 class="title">Note</h3>
<p>If you have generated the text file on a Windows system, you might have to use <code class="literal">LINES TERMINATED BY &rsquo;&rsquo;r&rsquo;n&rsquo;</code> to read the file properly, because Windows programs typically use two characters as a line terminator. Some programs, such as <span><strong class="command">WordPad</strong></span>, might use <code class="literal">&rsquo;r</code> as a line terminator when writing files. To read such files, use <code class="literal">LINES TERMINATED BY &rsquo;&rsquo;r&rsquo;</code>. </p>
</div>
<p>If all the lines you want to read in have a common prefix that you want to ignore, you can use <code class="literal">LINES STARTING BY &rsquo;<em class="replaceable"><code>prefix_string</code></em>&rsquo;</code> to skip over the prefix, <span class="emphasis"><em>and anything before it</em></span>. If a line does not include the prefix, the entire line is skipped. Suppose that you issue the following statement: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;/tmp/test.txt&rsquo; INTO TABLE test
  FIELDS TERMINATED BY &rsquo;,&rsquo;  LINES STARTING BY &rsquo;xxx&rsquo;;
</pre>
<p>If the data file looks like this: </p>
<pre class="programlisting">xxx&quot;abc&quot;,1
something xxx&quot;def&quot;,2
&quot;ghi&quot;,3
</pre>
<p>The resulting rows will be <code class="literal">(&quot;abc&quot;,1)</code> and <code class="literal">(&quot;def&quot;,2)</code>. The third row in the file is skipped because it does not contain the prefix. </p>
<p>The <code class="literal">IGNORE <em class="replaceable"><code>number</code></em> LINES</code> option can be used to ignore lines at the start of the file. For example, you can use <code class="literal">IGNORE 1 LINES</code> to skip over an initial header line containing column names: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;/tmp/test.txt&rsquo; INTO TABLE test IGNORE 1 LINES;
</pre>
<p>When you use <code class="literal">SELECT ... INTO OUTFILE</code> in tandem with <code class="literal">LOAD DATA INFILE</code> to write data from a database into a file and then read the file back into the database later, the field- and line-handling options for both statements must match. Otherwise, <code class="literal">LOAD DATA INFILE</code> will not interpret the contents of the file properly. Suppose that you use <code class="literal">SELECT ... INTO OUTFILE</code> to write a file with fields delimited by commas: </p>
<pre class="programlisting">SELECT * INTO OUTFILE &rsquo;data.txt&rsquo;
  FIELDS TERMINATED BY &rsquo;,&rsquo;
  FROM table2;
</pre>
<p>To read the comma-delimited file back in, the correct statement would be: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;data.txt&rsquo; INTO TABLE table2
  FIELDS TERMINATED BY &rsquo;,&rsquo;;
</pre>
<p>If instead you tried to read in the file with the statement shown following, it wouldn&rsquo;t work because it instructs <code class="literal">LOAD DATA INFILE</code> to look for tabs between fields: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;data.txt&rsquo; INTO TABLE table2
  FIELDS TERMINATED BY &rsquo;&rsquo;t&rsquo;;
</pre>
<p>The likely result is that each input line would be interpreted as a single field. </p>
<p><code class="literal">LOAD DATA INFILE</code> can be used to read files obtained from external sources. For example, many programs can export data in comma-separated values (CSV) format, such that lines have fields separated by commas and enclosed within double quotes. If lines in such a file are terminated by newlines, the statement shown here illustrates the field- and line-handling options you would use to load the file: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;data.txt&rsquo; INTO TABLE <em class="replaceable"><code>tbl_name</code></em>
  FIELDS TERMINATED BY &rsquo;,&rsquo; ENCLOSED BY &rsquo;&quot;&rsquo;
  LINES TERMINATED BY &rsquo;&rsquo;n&rsquo;;
</pre>
<p>If the input values are not necessarily enclosed within quotes, use <code class="literal">OPTIONALLY</code> before the <code class="literal">ENCLOSED BY</code> keywords. </p>
<p>Any of the field- or line-handling options can specify an empty string (<code class="literal">&rsquo;&rsquo;</code>). If not empty, the <code class="literal">FIELDS [OPTIONALLY] ENCLOSED BY</code> and <code class="literal">FIELDS ESCAPED BY</code> values must be a single character. The <code class="literal">FIELDS TERMINATED BY</code>, <code class="literal">LINES STARTING BY</code>, and <code class="literal">LINES TERMINATED BY</code> values can be more than one character. For example, to write lines that are terminated by carriage return/linefeed pairs, or to read a file containing such lines, specify a <code class="literal">LINES TERMINATED BY &rsquo;&rsquo;r&rsquo;n&rsquo;</code> clause. </p>
<p>To read a file containing jokes that are separated by lines consisting of <code class="literal">%%</code>, you can do this </p>
<pre class="programlisting">CREATE TABLE jokes
  (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  joke TEXT NOT NULL);
LOAD DATA INFILE &rsquo;/tmp/jokes.txt&rsquo; INTO TABLE jokes
  FIELDS TERMINATED BY &rsquo;&rsquo;
  LINES TERMINATED BY &rsquo;&rsquo;n%%&rsquo;n&rsquo; (joke);
</pre>
<p><code class="literal">FIELDS [OPTIONALLY] ENCLOSED BY</code> controls quoting of fields. For output (<code class="literal">SELECT ... INTO OUTFILE</code>), if you omit the word <code class="literal">OPTIONALLY</code>, all fields are enclosed by the <code class="literal">ENCLOSED BY</code> character. An example of such output (using a comma as the field delimiter) is shown here: </p>
<pre class="programlisting">&quot;1&quot;,&quot;a string&quot;,&quot;100.20&quot;
&quot;2&quot;,&quot;a string containing a , comma&quot;,&quot;102.20&quot;
&quot;3&quot;,&quot;a string containing a &rsquo;&quot; quote&quot;,&quot;102.20&quot;
&quot;4&quot;,&quot;a string containing a &rsquo;&quot;, quote and comma&quot;,&quot;102.20&quot;
</pre>
<p>If you specify <code class="literal">OPTIONALLY</code>, the <code class="literal">ENCLOSED BY</code> character is used only to enclose values from columns that have a string data type (such as <code class="literal">CHAR</code>, <code class="literal">BINARY</code>, <code class="literal">TEXT</code>, or <code class="literal">ENUM</code>): </p>
<pre class="programlisting">1,&quot;a string&quot;,100.20
2,&quot;a string containing a , comma&quot;,102.20
3,&quot;a string containing a &rsquo;&quot; quote&quot;,102.20
4,&quot;a string containing a &rsquo;&quot;, quote and comma&quot;,102.20
</pre>
<p>Note that occurrences of the <code class="literal">ENCLOSED BY</code> character within a field value are escaped by prefixing them with the <code class="literal">ESCAPED BY</code> character. Also note that if you specify an empty <code class="literal">ESCAPED BY</code> value, it is possible to inadvertently generate output that cannot be read properly by <code class="literal">LOAD DATA INFILE</code>. For example, the preceding output just shown would appear as follows if the escape character is empty. Observe that the second field in the fourth line contains a comma following the quote, which (erroneously) appears to terminate the field: </p>
<pre class="programlisting">1,&quot;a string&quot;,100.20
2,&quot;a string containing a , comma&quot;,102.20
3,&quot;a string containing a &quot; quote&quot;,102.20
4,&quot;a string containing a &quot;, quote and comma&quot;,102.20
</pre>
<p>For input, the <code class="literal">ENCLOSED BY</code> character, if present, is stripped from the ends of field values. (This is true regardless of whether <code class="literal">OPTIONALLY</code> is specified; <code class="literal">OPTIONALLY</code> has no effect on input interpretation.) Occurrences of the <code class="literal">ENCLOSED BY</code> character preceded by the <code class="literal">ESCAPED BY</code> character are interpreted as part of the current field value. </p>
<p>If the field begins with the <code class="literal">ENCLOSED BY</code> character, instances of that character are recognized as terminating a field value only if followed by the field or line <code class="literal">TERMINATED BY</code> sequence. To avoid ambiguity, occurrences of the <code class="literal">ENCLOSED BY</code> character within a field value can be doubled and are interpreted as a single instance of the character. For example, if <code class="literal">ENCLOSED BY &rsquo;&quot;&rsquo;</code> is specified, quotes are handled as shown here: </p>
<pre class="programlisting">&quot;The &quot;&quot;BIG&quot;&quot; boss&quot;  -&gt; The &quot;BIG&quot; boss
The &quot;BIG&quot; boss      -&gt; The &quot;BIG&quot; boss
The &quot;&quot;BIG&quot;&quot; boss    -&gt; The &quot;&quot;BIG&quot;&quot; boss
</pre>
<p><code class="literal">FIELDS ESCAPED BY</code> controls how to write or read special characters. If the <code class="literal">FIELDS ESCAPED BY</code> character is not empty, it is used to prefix the following characters on output: </p>
<div class="itemizedlist">
<ul>
<li>
<p>The <code class="literal">FIELDS ESCAPED BY</code> character </p>
<li>
<p>The <code class="literal">FIELDS [OPTIONALLY] ENCLOSED BY</code> character </p>
<li>
<p>The first character of the <code class="literal">FIELDS TERMINATED BY</code> and <code class="literal">LINES TERMINATED BY</code> values </p>
<li>
<p>ASCII <code class="literal">0</code> (what is actually written following the escape character is ASCII â€œ<span class="quote"><code class="literal">0</code></span>â€, not a zero-valued byte) </p>
</li>
</ul>
</div>
<p>If the <code class="literal">FIELDS ESCAPED BY</code> character is empty, no characters are escaped and <code class="literal">NULL</code> is output as <code class="literal">NULL</code>, not <code class="literal">&rsquo;N</code>. It is probably not a good idea to specify an empty escape character, particularly if field values in your data contain any of the characters in the list just given. </p>
<p>For input, if the <code class="literal">FIELDS ESCAPED BY</code> character is not empty, occurrences of that character are stripped and the following character is taken literally as part of a field value. Some two-character sequences that are exceptions, where the first character is the escape character. These sequences are shown in the following table (using â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€ for the escape character). The rules for <code class="literal">NULL</code> handling are described later in this section. </p>
<div class="informaltable">
<table border="1">
<colgroup>
<col>
<col></colgroup>
<tbody>
<tr>
<td><code class="literal">&rsquo;0</code> </td>
<td>An ASCII 0 (<code class="literal">NUL</code>) character</td>
</tr>
<tr>
<td><code class="literal">&rsquo;b</code> </td>
<td>A backspace character</td>
</tr>
<tr>
<td><code class="literal">&rsquo;n</code> </td>
<td>A newline (linefeed) character</td>
</tr>
<tr>
<td><code class="literal">&rsquo;r</code> </td>
<td>A carriage return character</td>
</tr>
<tr>
<td><code class="literal">&rsquo;t</code> </td>
<td>A tab character.</td>
</tr>
<tr>
<td><code class="literal">&rsquo;Z</code> </td>
<td>ASCII 26 (Control-Z)</td>
</tr>
<tr>
<td><code class="literal">&rsquo;N</code> </td>
<td>NULL</td>
</tr>
</tbody>
</table>
</div>
<p>For more information about â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€-escape syntax, see <a title="8.1.&amp;amp;nbsp;Literal Values" href="http://dev.mysql.com/doc/refman/5.0/en/literals.html" >Section 8.1, â€œLiteral Valuesâ€</a>. </p>
<p>In certain cases, field- and line-handling options interact: </p>
<div class="itemizedlist">
<ul>
<li>
<p>If <code class="literal">LINES TERMINATED BY</code> is an empty string and <code class="literal">FIELDS TERMINATED BY</code> is non-empty, lines are also terminated with <code class="literal">FIELDS TERMINATED BY</code>. </p>
<li>
<p>If the <code class="literal">FIELDS TERMINATED BY</code> and <code class="literal">FIELDS ENCLOSED BY</code> values are both empty (<code class="literal">&rsquo;&rsquo;</code>), a fixed-row (non-delimited) format is used. With fixed-row format, no delimiters are used between fields (but you can still have a line terminator). Instead, column values are read and written using a field width wide enough to hold all values in the field. For <code class="literal">TINYINT</code>, <code class="literal">SMALLINT</code>, <code class="literal">MEDIUMINT</code>, <code class="literal">INT</code>, and <code class="literal">BIGINT</code>, the field widths are 4, 6, 8, 11, and 20, respectively, no matter what the declared display width is. </p>
<p><code class="literal">LINES TERMINATED BY</code> is still used to separate lines. If a line does not contain all fields, the rest of the columns are set to their default values. If you do not have a line terminator, you should set this to <code class="literal">&rsquo;&rsquo;</code>. In this case, the text file must contain all fields for each row. </p>
<p>Fixed-row format also affects handling of <code class="literal">NULL</code> values, as described later. Note that fixed-size format does not work if you are using a multi-byte character set. </p>
<div style="MARGIN-LEFT: 0.5in; MARGIN-RIGHT: 0.5in" class="note">
<h3 class="title">Note</h3>
<p>Before MySQL 5.0.6, fixed-row format used the display width of the column. For example, <code class="literal">INT(4)</code> was read or written using a field with a width of 4. However, if the column contained wider values, they were dumped to their full width, leading to the possibility of a â€œ<span class="quote">ragged</span>â€ field holding values of different widths. Using a field wide enough to hold all values in the field prevents this problem. However, data files written before this change was made might not be reloaded correctly with <code class="literal">LOAD DATA INFILE</code> for MySQL 5.0.6 and up. This change also affects data files read by <span><strong class="command">mysqlimport</strong></span> and written by <span><strong class="command">mysqldump &#8211;tab</strong></span>, which use <code class="literal">LOAD DATA INFILE</code> and <code class="literal">SELECT ... INTO OUTFILE</code>. </p>
</div>
</li>
</ul>
</div>
<p>Handling of <code class="literal">NULL</code> values varies according to the <code class="literal">FIELDS</code> and <code class="literal">LINES</code> options in use: </p>
<div class="itemizedlist">
<ul>
<li>
<p>For the default <code class="literal">FIELDS</code> and <code class="literal">LINES</code> values, <code class="literal">NULL</code> is written as a field value of <code class="literal">&rsquo;N</code> for output, and a field value of <code class="literal">&rsquo;N</code> is read as <code class="literal">NULL</code> for input (assuming that the <code class="literal">ESCAPED BY</code> character is â€œ<span class="quote"><code class="literal">&rsquo;</code></span>â€). </p>
<li>
<p>If <code class="literal">FIELDS ENCLOSED BY</code> is not empty, a field containing the literal word <code class="literal">NULL</code> as its value is read as a <code class="literal">NULL</code> value. This differs from the word <code class="literal">NULL</code> enclosed within <code class="literal">FIELDS ENCLOSED BY</code> characters, which is read as the string <code class="literal">&rsquo;NULL&rsquo;</code>. </p>
<li>
<p>If <code class="literal">FIELDS ESCAPED BY</code> is empty, <code class="literal">NULL</code> is written as the word <code class="literal">NULL</code>. </p>
<li>
<p>With fixed-row format (which is used when <code class="literal">FIELDS TERMINATED BY</code> and <code class="literal">FIELDS ENCLOSED BY</code> are both empty), <code class="literal">NULL</code> is written as an empty string. Note that this causes both <code class="literal">NULL</code> values and empty strings in the table to be indistinguishable when written to the file because both are written as empty strings. If you need to be able to tell the two apart when reading the file back in, you should not use fixed-row format. </p>
</li>
</ul>
</div>
<p>An attempt to load <code class="literal">NULL</code> into a <code class="literal">NOT NULL</code> column causes assignment of the implicit default value for the column&rsquo;s data type and a warning, or an error in strict SQL mode. Implicit default values are discussed in <a title="10.1.4.&amp;amp;nbsp;Data Type Default Values" href="http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html" >Section 10.1.4, â€œData Type Default Valuesâ€</a>. </p>
<p>Some cases are not supported by <code class="literal">LOAD DATA INFILE</code>: </p>
<div class="itemizedlist">
<ul>
<li>
<p>Fixed-size rows (<code class="literal">FIELDS TERMINATED BY</code> and <code class="literal">FIELDS ENCLOSED BY</code> both empty) and <code class="literal">BLOB</code> or <code class="literal">TEXT</code> columns. </p>
<li>
<p>If you specify one separator that is the same as or a prefix of another, <code class="literal">LOAD DATA INFILE</code> cannot interpret the input properly. For example, the following <code class="literal">FIELDS</code> clause would cause problems: </p>
<pre class="programlisting">FIELDS TERMINATED BY &rsquo;&quot;&rsquo; ENCLOSED BY &rsquo;&quot;&rsquo;
</pre>
<li>
<p>If <code class="literal">FIELDS ESCAPED BY</code> is empty, a field value that contains an occurrence of <code class="literal">FIELDS ENCLOSED BY</code> or <code class="literal">LINES TERMINATED BY</code> followed by the <code class="literal">FIELDS TERMINATED BY</code> value causes <code class="literal">LOAD DATA INFILE</code> to stop reading a field or line too early. This happens because <code class="literal">LOAD DATA INFILE</code> cannot properly determine where the field or line value ends. </p>
</li>
</ul>
</div>
<p>The following example loads all columns of the <code class="literal">persondata</code> table: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;persondata.txt&rsquo; INTO TABLE persondata;
</pre>
<p>By default, when no column list is provided at the end of the <code class="literal">LOAD DATA INFILE</code> statement, input lines are expected to contain a field for each table column. If you want to load only some of a table&rsquo;s columns, specify a column list: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;persondata.txt&rsquo; INTO TABLE persondata (col1,col2,...);
</pre>
<p>You must also specify a column list if the order of the fields in the input file differs from the order of the columns in the table. Otherwise, MySQL cannot tell how to match input fields with table columns. </p>
<p>Before MySQL 5.0.3, the column list must contain only names of columns in the table being loaded, and the <code class="literal">SET</code> clause is not supported. As of MySQL 5.0.3, the column list can contain either column names or user variables. With user variables, the <code class="literal">SET</code> clause enables you to perform transformations on their values before assigning the result to columns. </p>
<p>User variables in the <code class="literal">SET</code> clause can be used in several ways. The following example uses the first input column directly for the value of <code class="literal">t1.column1</code>, and assigns the second input column to a user variable that is subjected to a division operation before being used for the value of <code class="literal">t1.column2</code>: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;file.txt&rsquo;
  INTO TABLE t1
  (column1, @var1)
  SET column2 = @var1/100;
</pre>
<p>The <code class="literal">SET</code> clause can be used to supply values not derived from the input file. The following statement sets <code class="literal">column3</code> to the current date and time: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;file.txt&rsquo;
  INTO TABLE t1
  (column1, column2)
  SET column3 = CURRENT_TIMESTAMP;
</pre>
<p>You can also discard an input value by assigning it to a user variable and not assigning the variable to a table column: </p>
<pre class="programlisting">LOAD DATA INFILE &rsquo;file.txt&rsquo;
  INTO TABLE t1
  (column1, @dummy, column2, @dummy, column3);
</pre>
<p>Use of the column/variable list and <code class="literal">SET</code> clause is subject to the following restrictions: </p>
<div class="itemizedlist">
<ul>
<li>
<p>Assignments in the <code class="literal">SET</code> clause should have only column names on the left hand side of assignment operators. </p>
<li>
<p>You can use subqueries in the right hand side of <code class="literal">SET</code> assignments. A subquery that returns a value to be assigned to a column may be a scalar subquery only. Also, you cannot use a subquery to select from the table that is being loaded. </p>
<li>
<p>Lines ignored by an <code class="literal">IGNORE</code> clause are not processed for the column/variable list or <code class="literal">SET</code> clause. </p>
<li>
<p>User variables cannot be used when loading data with fixed-row format because user variables do not have a display width. </p>
</li>
</ul>
</div>
<p>When processing an input line, <code class="literal">LOAD DATA</code> splits it into fields and uses the values according to the column/variable list and the <code class="literal">SET</code> clause, if they are present. Then the resulting row is inserted into the table. If there are <code class="literal">BEFORE INSERT</code> or <code class="literal">AFTER INSERT</code> triggers for the table, they are activated before or after inserting the row, respectively. </p>
<p>If an input line has too many fields, the extra fields are ignored and the number of warnings is incremented. </p>
<p>If an input line has too few fields, the table columns for which input fields are missing are set to their default values. Default value assignment is described in <a title="10.1.4.&amp;amp;nbsp;Data Type Default Values" href="http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html" >Section 10.1.4, â€œData Type Default Valuesâ€</a>. </p>
<p>An empty field value is interpreted differently than if the field value is missing: </p>
<div class="itemizedlist">
<ul>
<li>
<p>For string types, the column is set to the empty string. </p>
<li>
<p>For numeric types, the column is set to <code class="literal">0</code>. </p>
<li>
<p>For date and time types, the column is set to the appropriate â€œ<span class="quote">zero</span>â€ value for the type. See <a title="10.3.&amp;amp;nbsp;Date and Time Types" href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html" >Section 10.3, â€œDate and Time Typesâ€</a>. </p>
</li>
</ul>
</div>
<p>These are the same values that result if you assign an empty string explicitly to a string, numeric, or date or time type explicitly in an <code class="literal">INSERT</code> or <code class="literal">UPDATE</code> statement. </p>
<p><code class="literal">TIMESTAMP</code> columns are set to the current date and time only if there is a <code class="literal">NULL</code> value for the column (that is, <code class="literal">&rsquo;N</code>) and the column is not declared to allow <code class="literal">NULL</code> values, or if the <code class="literal">TIMESTAMP</code> column&rsquo;s default value is the current timestamp and it is omitted from the field list when a field list is specified. </p>
<p><code class="literal">LOAD DATA INFILE</code> regards all input as strings, so you cannot use numeric values for <code class="literal">ENUM</code> or <code class="literal">SET</code> columns the way you can with <code class="literal">INSERT</code> statements. All <code class="literal">ENUM</code> and <code class="literal">SET</code> values must be specified as strings. </p>
<p><code class="literal">BIT</code> values cannot be loaded using binary notation (for example, <code class="literal">b&rsquo;011010&rsquo;</code>). To work around this, specify the values as regular integers and use the <code class="literal">SET</code> clause to convert them so that MySQL performs a numeric type conversion and loads them into the <code class="literal">BIT</code> column properly: </p>
<pre class="programlisting">shell&gt; <strong class="userinput"><code>cat /tmp/bit_test.txt</code></strong>
2
127
shell&gt; <strong class="userinput"><code>mysql test</code></strong>
mysql&gt; <strong class="userinput"><code>LOAD DATA INFILE &rsquo;/tmp/bit_test.txt&rsquo;</code></strong>
    -&gt; <strong class="userinput"><code>INTO TABLE bit_test (@var1) SET b= CAST(@var1 AS UNSIGNED);</code></strong>
Query OK, 2 rows affected (0.00 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 0

mysql&gt; <strong class="userinput"><code>SELECT BIN(b+0) FROM bit_test;</code></strong>
+----------+
| bin(b+0) |
+----------+
| 10       |
| 1111111  |
+----------+
2 rows in set (0.00 sec)
</pre>
<p>When the <code class="literal">LOAD DATA INFILE</code> statement finishes, it returns an information string in the following format: </p>
<pre class="programlisting">Records: 1  Deleted: 0  Skipped: 0  Warnings: 0
</pre>
<p>If you are using the C API, you can get information about the statement by calling the <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-info.html" title="23.2.3.35.&nbsp;mysql_info()"><code class="literal">mysql_info()</code></a> function. See <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-info.html" title="23.2.3.35.&nbsp;mysql_info()">Section 23.2.3.35, â€œ<code class="literal">mysql_info()</code>â€</a>. </p>
<p>Warnings occur under the same circumstances as when values are inserted via the <code class="literal">INSERT</code> statement (see <a title="12.2.4.&amp;amp;nbsp;INSERT Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/insert.html" >Section 12.2.4, â€œ<code class="literal">INSERT</code> Syntaxâ€</a>), except that <code class="literal">LOAD DATA INFILE</code> also generates warnings when there are too few or too many fields in the input row. The warnings are not stored anywhere; the number of warnings can be used only as an indication of whether everything went well. </p>
<p>You can use <code class="literal">SHOW WARNINGS</code> to get a list of the first <code class="literal">max_error_count</code> warnings as information about what went wrong. See <a title="12.5.4.28.&amp;amp;nbsp;SHOW WARNINGS Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html" >Section 12.5.4.28, â€œ<code class="literal">SHOW WARNINGS</code> Syntaxâ€</a>. </p>
</div>
<p><!--UdmComment--></p>
<div id="docnav"><a title="12.2.4.3 INSERT ... ON DUPLICATE KEY UPDATE Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html" rel="prev" >Previous</a> / <a title="12.2.6 REPLACE Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/replace.html" rel="next" >Next</a> / <a title="12.2 Data Manipulation Statements" href="http://dev.mysql.com/doc/refman/5.0/en/data-manipulation.html" rel="up" >Up</a> / <a href="http://dev.mysql.com/doc/refman/5.0/en/index.html" rel="contents" >Table of Contents</a></div>
<p><!--/UdmComment--><br class="clear"><!--UdmComment--></p>
<div id="comments">
<h2>User Comments</h2>
<table width="100%" summary="" class="commentdetails" id="c6866" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>Posted by Nathan Huebner on November 16 2005 7:56pm</td>
<td align="right">[<a href="http://dev.mysql.com/doc/mysql/comment.php?id=6866&#038;action=delete">Delete</a>] [<a href="http://dev.mysql.com/doc/mysql/comment.php?id=6866">Edit</a>]</td>
</tr>
</tbody>
</table>
<p class="commenttext">I just recently had to figure out how to get a database with rows that look like this, into MySQL:</p>
<p>0001GB000020000300050006700070008000100020040050060007008</p>
<p>Believe it or not, there&rsquo;s like 9 columns in that row. The data from our vendor comes like this.</p>
<p>I am hoping someone finds this post useful. HOW I GOT IT INTO MYSQL:</p>
<p>1. When you setup your MySQL table, make sure it&rsquo;s a compatible format. If your LOAD DATA INFILE is spitting back &rsquo;too long for column&rsquo;, then there&rsquo;s something wrong. First check to make sure your Fixed-Width is correct, then check your Table Format. I had to use latin1_general_ci to get the data to load. It would not accept my LOAD DATA INFILE with utf8_general_ci. So that should save some hairs on your head when you pull them out from the frustration.</p>
<p>Here is the code to load the data:</p>
<p>LOAD DATA INFILE C:/bobsfile.txt&rsquo; INTO TABLE mydatabase.mytable <br />FIELDS TERMINATED BY &rsquo;&rsquo; <br />FIELDS ENCLOSED BY &rsquo;&rsquo;; </p>
<p>I hope this helps someone. It could have helped me, the documentation was poor on mentioning WILL NOT WORK IF YOU USE SPECIFIC TABLE FORMATS. a nice list of acceptable or prohibited formats would have been nice.</p>
<p>! <img src="http://dimas.ubhara.id/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<p>Nathan</p>
<table width="100%" summary="" class="commentdetails" id="c6963" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>Posted by Robert Lee on December 7 2005 3:33pm</td>
<td align="right">[<a href="http://dev.mysql.com/doc/mysql/comment.php?id=6963&#038;action=delete">Delete</a>] [<a href="http://dev.mysql.com/doc/mysql/comment.php?id=6963">Edit</a>]</td>
</tr>
</tbody>
</table>
<p class="commenttext">I tried to import the ISO/DIS 639-3 code table (This lists languages) into MySQL. I got a data to long error, because the character set in the ISO table ISO, ISO-8859-1,<br />which should be latin1, did not work. By changing the character set to binary. I did get the table to laod.</p>
<p>CREATE TABLE ISO_639_3<br />(<br />ID CHAR(3) NOT NULL, # The three-letter 639-3 identifier<br />Part2 CHAR(3) NULL, # Equivalent 639-2/T identifier, if there is one<br />Part1 CHAR(2) NULL, # Equivalent 639-1 identifier, if there is one <br />Scope CHAR(1) NOT NULL, # I(ndividual), M(acrolanguage)<br />Type CHAR(1) NOT NULL, # A(ncient), C(onstructed), <br /># E(xtinct), H(istorical), L(iving)<br />Name VARCHAR(255) NOT NULL) # Language name (inverted form)<br />DEFAULT CHARACTER SET binary;<br />TRUNCATE ISO_639_3;<br />LOAD DATA INFILE &rsquo;ISO_639_3x.tab&rsquo; INTO TABLE ISO_639_3 <br />IGNORE 1 LINES;</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://dimas.ubhara.id/2008/04/from-excel-to-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
