frazman
frazman

Reputation: 33213

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

Upvotes: 33

Views: 100880

Answers (4)

Mohit Jain
Mohit Jain

Reputation: 43919

To export:

 mysqldump -u mysql_user -p DATABASE_NAME > backup.sql

To import (note not mysqldump but mysql:

 mysql -u mysql_user -p DATABASE_NAME < backup.sql

Upvotes: 136

Senthilkumar Ramasamy
Senthilkumar Ramasamy

Reputation: 101

For example, to dump table definitions and data separately use these commands:

mysqldump -u mysql_user -p --no-data test > dump-defs.sql
mysqldump -u mysql_user -p --no-create-info test > dump-data.sql

Upvotes: 1

manian
manian

Reputation: 1438

For Exporting a database from WAMP in windows, please follow the below steps
1. Open Command Prompt
2. Change Directory to the bin folder of mysql(eg., CD C:\wamp64\bin\mysql\mysql5.7.14\bin)
3. Run the below command where 'password' is your mysql root password, 'dbname' is your database name & path within the doubles quotes is your directory where you want to save your file.

Command:

mysqldump -u root -p password dbname > "D:\db\db_backup.sql"

Upvotes: 0

Kenny
Kenny

Reputation: 1090

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.

Upvotes: 2

Related Questions