dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersmusathik
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » SQL

How to load/migrate data from .CSV file to mySQL table?


Posted Date:     Category: SQL    
Author: Member Level: Gold    Points: 15


Data migration means migrating data from one place to another place. Generally, mySQL queries are used to retrive ,add , update , delete data. We have used mySQL query for migration purpose. I hope this will be useful to all.



 


How to load/migrate data from .CSV file to mySQL table?
Introduction:
This will be useful if you want to migrate large volume of data from .CSV file to mySQL table. In such case, it is not possible to use insert query and migrate data one by one.
This will be the best practice to migrate data in a very short amount of time.
Steps:
You have to follow these steps -
1) In mySQL create a schema as firsttable.
2) Create table by this query -

DROP TABLE IF EXISTS `firsttable`.`MultipleOrdersDetails`;
CREATE TABLE `firsttable`.`MultipleOrdersDetails` (
`MultipleOrdersDetailsid` varchar(45) NOT NULL,
`side` varchar(45) NOT NULL,
`symbol` varchar(45) NOT NULL,
`totalQuantity` varchar(45) NOT NULL,
`totalPrice` varchar(45) NOT NULL,
`createdDateForUsage` varchar(45) NOT NULL
)

It will create table MultipleOrdersDetails.
3) It will load data from .CSV file to table MultipleOrdersDetails. Make sure that .CSV has first line which is nothing but header that means it should be same as that of column names present in the table MultipleOrdersDetails.

LOAD DATA LOCAL INFILE 'D:\\records_for_loading.csv' INTO TABLE firsttable.MultipleOrdersDetails FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' (MultipleOrdersDetailsid, side, symbol, totalQuantity, totalPrice, createdDateForUsage);

4) You can use following select query to see the data has been properly loaded in table or not.

SELECT * FROM firsttable.`MultipleOrdersDetails` ;

Make sure that datatype of columns and data present in .CSV file should be compatible for migration else sometimes data gets truncated while migration process.





Did you like this resource? Share it with your friends and show your love!


Responses to "How to load/migrate data from .CSV file to mySQL table?"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: What is out parameter in sql server? how to use out parameter in stored procedure?
    Previous Resource: T-sql CTE in SQL Server
    Return to Resources
    Post New Resource
    Category: SQL


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.