Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export dump file from MySql

I want to create a dump file of a table in the database. So database --> king, tablename --> castle So what I want to do is create a dump file.. and then the next part is to import it in my local host. database name --> king_local. Any ideas on how to go about this!! Thanks

like image 681
frazman Avatar asked Sep 14 '11 22:09

frazman


People also ask

What is MySQL dump file?

4.5.4 mysqldump — A Database Backup Program. The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another SQL server.

How do I export a MySQL database to a text file?

The best tool for exporting a MySQL database to a text file is mysqldump . To use mysqldump , you will need to know the login credentials of an appropriate MySQL user that has the necessary privileges to export the database in question. The options in use are: The -u flag indicates that the MySQL username will follow.


2 Answers

To export:

 mysqldump -u mysql_user -p DATABASE_NAME > backup.sql 

To import:

 mysqldump -u mysql_user -p DATABASE_NAME < backup.sql 
like image 95
Mohit Jain Avatar answered Oct 12 '22 01:10

Mohit Jain


Since you now seem to want to export the data from within the MySQL monitor, you want to look at the documentation from MySQL on SELECT ... INTO OUTFILE:

http://dev.mysql.com/doc/refman/5.0/en/select.html

The INTO OUTFILE stuff is what you'd use to dump data in to said "outfile", and you'd want to specify the full path to a location that MySQL can write to, for example /tmp/dump.sql.

You'll then want to pay attention to the docs so you can specify how to end lines, delimit fields etc:

FIELDS TERMINATED BY, ENCLOSED BY, ESCAPED BY, LINES TERMINATED

And then to load it back in, LOAD DATA INFILE seems to be what you want. Go to that URL I posted, it has everything you seem to want.

like image 44
Kenny Avatar answered Oct 12 '22 01:10

Kenny