I am mikek's Blog

The personal blog of Mike Karthauser, who you may know from Brightstorm Limited or the internet.

Exporting to a text file in mysql

Getting data out of a mysql database into a text file is pretty straight forward using mysqldump

mysqldump5 -u USERNAME -p DATABASE_NAME TABLE_NAMES > /PATH/TO/FILENAME

TABLE_NAMES are optional and need to separated by a space if you are exporting a couple.

A couple of useful additional flags you can add after table names

  • –xml – converts sql output to xml which makes for an easier read
  • –no-create-info – outputs just data and no schema data.
  • –no-data – the opposite of above, which gives you just the schema
  • –complete-insert – to get column names within your insert statements
  • –skip-triggers –compact –no-create-info – for just insert statements
About these ads

Filed under: development, , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

mikek on twitter

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: