Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to export multi table in mysql?

i have 10+ tables, i want to export them to another datebase. how could i do that? i tried select * from table_a, table_b into ourfile "/tmp/tmp.data", but it joined the two tables.

like image 497
shanqn Avatar asked Mar 04 '11 03:03

shanqn


People also ask

How do I export a table from MySQL?

MySQL workbench tool can be used to export the data from the table. Open the MySQL database wizard & select the table you want to export. Right-click on the table name & select the table data export wizard option.


2 Answers

It's probably too late, but for the record:

Export an entire database:

mysqldump -u user -p database_name > filename.sql

Export only one table of the database:

mysqldump -u user -p database_name table_name > filename.sql

Export multiple tables of the database

Just like exporting one table, but keep on writing table names after the first table name (with one space between each name). Example exporting 3 tables:

mysqldump -u user -p database_name table_1 table_2 table_3 > filename.sql

Notes:

The tables are exported (i.e. written in the file) in the order in which they are written down in the command.

All of the examples above export the structure and the data of the database or table. To export only the structure, use no-data. Example exporting only one table of the database, but with no-data:

mysqldump -u user -p --no-data database_name table_name > filename.sql
like image 110
Francisco QV Avatar answered Oct 11 '22 14:10

Francisco QV


Export mysqldump -u user -p mydatabasename > filename.sql

Import mysql -u user -p anotherdatabase < filename.sql

like image 24
Zepplock Avatar answered Oct 11 '22 15:10

Zepplock