How to take mysql dump from selected table columns

I have a requirement in which I have to take a mysql dump of just one column of a table. Since there are too many columns in this table, I do not want to dump the full table. I have to get this dump table from one server to another. Any idea how I can do this?

+6
source share
3 answers

If you want to use mysql dump, including the schema, you can do this by following these steps:

create a temporary table:

create table temp_table like name_of_the_original_table; 

data duplication in temp_table:

 insert into temp_table select * from name_of_the_original_table; 

deleting unnecessary fields:

 alter table temp_table drop column somecolumn; 

post this, you can start mysqldump by running:

 mysqldump -u <username> -p <password> databasename temp_table 

If you intend to take a data dump (without a schema), you can run the following command:

 select * from sometable into outfile '/tmp/datadump' fields terminated by '\t' lines terminated by '\n'; 
+1
source
 mysql> CREATE TABLE `tempTable` AS SELECT `columnYouWant` from `table`; $> mysqldump yourDB tempTable > temp.sql 

copy temp.sql to the target server and then to the target server

 $> mysql yourDB < temp.sql mysql> RENAME TABLE `table` TO `tableBackup`, `tempTable` TO `table`; 
+1
source

Select a column to file?

 Select col from table into outfile 'fileame' 
0
source

All Articles