1

I frequently upload CSV files to a MySQL db.

It is very convenient to use LOAD DATA LOCAL INFILE to upload the data, but I can't use this to create the table itself. As of now, the best method I have is to use PHP to get the field titles from the first row of the file and then put together a CREATE table query. Is there a more convenient way to do this?

1
  • How can you tell from the CSV data what the types of the MySQL fields should be? Commented Mar 22, 2010 at 23:37

1 Answer 1

1

Any automated method would be missing some key information about the table: the types of the columns (although they could be guessed via some heuristics), null/not null, the indexes/primary keys, and foreign key relationships.

If all your columns are VARCHAR, your method is probably the most convenient. Perhaps you could write a wrapper script to automate the process of creating the table and importing the contents (minus the header)?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.