Export mysql databases with mysqldump to .sql .csv

## mysqldump is the command to obtain all data and schema from mysql databases, mainly to migrate databases between servers.

mysqldump -u {user} -h {host} {database}  > ~/dump.sql

## export to csv from one table

mysqldump -u {user} -h {host} –fields-terminated-by=”,” –fields-enclosed-by=”” –fields-escaped-by=”” {database} {table}

## sometimes you can get this error

mysqldump: Got error: 1: Can’t create/write to file ‘/home/mike/CHARACTER_SETS.txt’ (Errcode: 13) when executing ‘SELECT INTO OUTFILE’

## To solve this error try to send the file to some path where mysql user can write (ex /tmp) or run as superuser

mysqldump -u {user} -h {host} -T /path/to/write –fields-terminated-by=”,” –fields-enclosed-by=”” –fields-escaped-by=”” {database} {table}

Advertisements

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