Monday, July 27, 2015



If you have Open source MySQL database. And want to move either all, or some of the data into MongoDB (noSQL Database). There may be any other direct/indirect way to do it,  but you can also achieve this thing from below method (Add on) :) 

Step 1. 
Export all of your MySQL data as a CSV file.

select columns INTO OUTFILE '/path/to/csv
   FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
   LINES TERMINATED BY '\n' from table [where clause]

Step 2.
Import the CSV into MongoDB.

mongoimport -d dbname -c collname --type csv -f fields-sep-by-coma  --drop /path/to/csv 


if your csv file has a header row add --headerline option.


Suppose you have a big table having more than 100 columns then how can you display/show those columns as a comma separated. Here is the way- 

mysql>select GROUP_CONCAT(CONCAT("'",COLUMN_NAME,"'")) 
from INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'your_table_name' AND 
TABLE_SCHEMA = 'your_database_name';

No comments:

Post a Comment