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?
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)?