Q:

MySQL: Obtain Column Head Names From CSV

I have a MySQL database into which I import several large datasets from CSVs for analysis.   Has anyone developed a SQL script that will do these two things? 

Read the first line of the CSV and extract all of the column names, and 
Go through the entire  CSV file and determine the longest field for each column

My thinking is that if I could get this info within MySQL, then I could use that info to create the table with the correct column names and lengths for each column. 
Any ideas? 

A:

There's a tool called sqlizer.io which does exactly what you're after.  Upload your CSV file and leave the "Has Header Row" option ticked.  It will analyse the contents of the CSV file and generate a CREATE TABLE statement with the column names from the top row and the correct data types to be able to import your data. 
It will also create a set of INSERT statements to import your data. 
(Disclaimer: I help run SQLizer)

