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
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.
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.
To export:
mysqldump -u mysql_user -p DATABASE_NAME > backup.sql
To import:
mysqldump -u mysql_user -p DATABASE_NAME < backup.sql
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With