DISQUS

DISQUS Hello! Tech-Recipes is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Tech-Recipes

Cookbook of Tech Tutorials
Jump to original thread »
Author

Import CSV file directly into MySQL | MySQL | Tech-Recipes

Started by qdideas · 9 months ago

No excerpt available. Jump to website »

17 comments

  • Thank you. Short and sweet. Very straight to the point.
  • Thanks, buddy!
  • thanks pal! finally somethin' working :)
  • Thank you!!! it really works !!!

    Copied the csv file into /var/lib/mysql/mydb at my ubuntu box.

    *mydb is the name of my database
  • Thank you Thank you. Very nice.
  • very very superb 1 line query.. i love it !!!!!!!!!!!!!!
  • help!! can this be possible??
    (idnum,username,md5(password))
    how about if i used md5 in my password??
    and i want my password field converted into md5.
    email me pls. ir_bs756@yahoo.com
  • hey
    please send full code of importing file into mysql database. at my email (ashish@tiainterweb.com)
    thanks
  • the above code is can do it. You need to specify the url of the csv file with / slash and not \ .
  • Can MySQL automatically assign the column names using the column headers from the csv file?
  • where to place the csv file...
  • Thank you very much.
  • Comment removed.
  • @ir:
    If the passwords in your CSV file are not already MD5() then just import them as per the instructions above then run this query:

    UPDATE `users` SET `password` = MD5(`password`);

    @ashish:
    That is the "full code". There is no more. The only step you have to do before this is to create a table that matches the CSV file you already have. No one can tell you how to do that without having your CSV file. Don't forget to modify the query above to match the table you have just created.

    @zlid:
    No it can't. Fields are given names and types at the same time when the table is created. To assign the names automatically, MySQL would have to also assign the column types automatically which would mean scanning down through the entire CSV file to make sure that there were no letters in a column that started with numbers and finding the longest string in a column that started with a string and so on. There are too many options in table creation to allow it to be left up to software. NULL or NOT NULL ? DATE, DATETIME, TIME, CHAR, VARCHAR or TEXT ? What if you have a column full of numbers but one Excel error message that looks like "#value" ?

    You will have to create the table yourself before importing the CSV file.
  • thanks very much
  • Ok, I must be missing something here. Are there more explicit instructions for this? Do I paste this code using phpmyadmin and putting it into the sql box? I'm a little lost here.
  • I wanted to add the fact that I already have my database set up in MySQL with all the appropriate tables. I created a test CSV file and messed around with it a bit but wasn't sure where and how I was supposed to implement it using the code you have given.

Add New Comment

Returning? Login