<?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>Christian Riesen &#187; Backup</title>
	<atom:link href="http://christianriesen.com/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://christianriesen.com</link>
	<description>Life and work in the information and communication age</description>
	<lastBuildDate>Fri, 24 Feb 2012 09:55:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating a MySQL dump in CSV format</title>
		<link>http://christianriesen.com/2009/06/creating-a-mysql-dump-in-csv-format/</link>
		<comments>http://christianriesen.com/2009/06/creating-a-mysql-dump-in-csv-format/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 07:33:47 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=39</guid>
		<description><![CDATA[Mostly, a dump of a db is wanted in SQL. In case of emergency import file. But some people do not comprehend SQL or their SQL doesn&#8217;t like your SQL and everything goes down the drain. So there is the CSV or Comma-separated values file. As the name says, it separates the values by commas [...]]]></description>
			<content:encoded><![CDATA[<p>Mostly, a dump of a db is wanted in SQL. In case of emergency import file. But some people do not comprehend SQL or their SQL doesn&#8217;t like your SQL and everything goes down the drain. So there is the CSV or Comma-separated values file. As the name says, it separates the values by commas (and more if needed). Since it&#8217;s so dead simple, you will get a lot of different tools and program languages that will make life easy for you to re-import or just search in it. Microsoft Excel and Openoffice Calc both can handle the format as well, so for a quick look, this will do very nicely.</p>
<p>But there is no simple &#8211;csv switch in mysqldump, your weapon of choice for these tasks. So here the command that will allow you to do what you are after:</p>
<p><code>mysqldump -p -u USER -T DIRECTORY --fields-enclosed-by=\" --fields-terminated-by=, DATABASE</code></p>
<p>So this is the short version, and here what it all means:</p>
<ul>
<li>-p : Asks for a password, as most users have one. If you don&#8217;t specify this on a database with a user/password, it will error</li>
<li>-u USER : Replace USER with your actual username to connect to the database.</li>
<li>-T DIRECTORY : This creates a tab delimited file. Not what we wanted but it&#8217;s the base we need.</li>
<li>&#8211;fields-enclosed-by=\&#8221; : Will add &#8221; characters around the fields. This will allow CSV implementations to find everything that fits together. You will need that backslash or it wont run.</li>
<li>&#8211;fields-terminated-by=, : The so much sought after comma. This replaces the tab and puts a comma in its place, which, you guessed it, creates the CSV file.</li>
<li>DATABASE : Well you know, the thing this is all about&#8230;</li>
</ul>
<p>To actually be able to do it though, you will need the FILE privilege on this database. Armed with this, you should be able to do your CSV exports easy now.</p>
 <p><a href="http://christianriesen.com/?flattrss_redirect&amp;id=39&amp;md5=45cf11dd9c0565cfa10736e9dc366b87" title="Flattr" target="_blank"><img src="http://christianriesen.com/wp-content/plugins/flattrss/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/06/creating-a-mysql-dump-in-csv-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=756&amp;url=http%3A%2F%2Fchristianriesen.com%2F2009%2F06%2Fcreating-a-mysql-dump-in-csv-format%2F&amp;language=en_GB&amp;category=text&amp;title=Creating+a+MySQL+dump+in+CSV+format&amp;description=Mostly%2C+a+dump+of+a+db+is+wanted+in+SQL.+In+case+of+emergency+import+file.+But+some+people+do+not+comprehend+SQL+or+their+SQL+doesn%27t+like+your+SQL+and+everything+goes+down+the+drain.+So+there+is+the+CSV+or+Comma-separated+values+file.+As+the+name+says%2C+it+separates+the+values+by+commas+%28and+more+if+needed%29.+Since+it%27s+so+dead+simple%2C+you+will+get+a+lot+of+different+tools+and+program+languages+that+will+make+life+easy+for+you+to+re-import+or+just+search+in+it.+Microsoft+Excel+and+Openoffice+Calc+both+can+handle+the+format+as+well%2C+so+for+a+quick+look%2C+this+will+do+very+nicely.%0D%0A%0D%0ABut+there+is+no+simple+--csv+switch+in+mysqldump%2C+your+weapon+of+choice+for+these+tasks.+So+here+the+command+that+will+allow+you+to+do+what+you+are+after%3A%0D%0A%0D%0Amysqldump+-p+-u+USER+-T+DIRECTORY+--fields-enclosed-by%3D%5C%22+--fields-terminated-by%3D%2C+DATABASE%0D%0A%0D%0ASo+this+is+the+short+version%2C+and+here+what+it+all+means%3A%0D%0A%0D%0A%09-p+%3A+Asks+for+a+password%2C+as+most+users+have+one.+If+you+don%27t+specify+this+on+a+database+with+a+user%2Fpassword%2C+it+will+error%0D%0A%09-u+USER+%3A+Replace+USER+with+your+actual+username+to+connect+to+the+database.%0D%0A%09-T+DIRECTORY+%3A+This+creates+a+tab+delimited+file.+Not+what+we+wanted+but+it%27s+the+base+we+need.%0D%0A%09--fields-enclosed-by%3D%5C%22+%3A+Will+add+%22+characters+around+the+fields.+This+will+allow+CSV+implementations+to+find+everything+that+fits+together.+You+will+need+that+backslash+or+it+wont+run.%0D%0A%09--fields-terminated-by%3D%2C+%3A+The+so+much+sought+after+comma.+This+replaces+the+tab+and+puts+a+comma+in+its+place%2C+which%2C+you+guessed+it%2C+creates+the+CSV+file.%0D%0A%09DATABASE+%3A+Well+you+know%2C+the+thing+this+is+all+about...%0D%0A%0D%0A%0D%0ATo+actually+be+able+to+do+it+though%2C+you+will+need+the+FILE+privilege+on+this+database.+Armed+with+this%2C+you+should+be+able+to+do+your+CSV+exports+easy+now.&amp;tags=Backup%2Cmysqldump%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>

