简体   繁体   中英

MySQL: LOAD DATA INFILE producing incorrect table results

I am trying to use LOAD DATA INFILE to load my data into tables.

My table:

Alcohol name varchar(45)
Type varchar(45)
ABV FLOAT
Brewery INT(11)
Average Price DOUBLE
Description VARCHAR(1000)

My CSV file looks like:

Alcohol name,Type,ABV,Brewery,Average Price,Description
Hocus Pocus,Beer,4.5,812,0,"Our take on a classic summer ale.  A toast to weeds, rays, and summer haze.  A light, crisp ale for mowing lawns, hitting lazy fly balls, and communing with nature, Hocus Pocus is offered up as a summer sacrifice to clodless days.Its malty sweetness finishes tart and crisp and is best apprediated with a wedge of orange."
Grimbergen Blonde,Beer,6.699999809,264,0,None
Widdershins Barleywine,Beer,9.100000381,779,0,None
Lucifer,Beer,8.5,287,0,None
Bitter,Beer,4,1056,0,None
Winter Warmer,Beer,5.199999809,1385,0,None
Winter Welcome 2007-2008,Beer,6,1099,0,None

etc....

My LOAD Command looks like:

LOAD DATA LOCAL INFILE '/home/leo/CS336/Tables/beers.csv' INTO TABLE Alcohol FIELDS TERMINATED BY ',' IGNORE 1 LINES; 

The garbage table I'm getting looks like:

Alcohol name Type  ABV Brewery Average Price Description
Golden Ale  NULL    0   0   NULL NULL   
* 10.5% (2008)  NULL    0   0   NULL NULL       
* 15.5 gallon keg   NULL    0   0       NULL NULL   
* 22 oz. bottles    NULL    0   0   NULL NULL       
* 5.17 gallon keg   NULL    0   0   NULL NULL       
* 9.78% (2007)"     NULL    0   0   NULL NULL   
* Available March through August    NULL    0   0       NULL NULL   
etc...      

I created a table based on your description ( Average_Price I added an underscore)

 create table Alcohol (
   name varchar(45), 
   Type varchar(45), 
   ABV FLOAT, 
   Brewery INT(11), 
   Average_Price DOUBLE, 
   Description VARCHAR(1000)
);

I loaded your example file like this

 LOAD DATA LOCAL INFILE '/tmp/alcohol.csv' INTO TABLE Alcohol FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES; 

And I think I got reasonable results:

 `SELECT * from Alcohol;

+--------------------------+------+------+---------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name                     | Type | ABV  | Brewery | Average_Price | Description                                                                                                                                                                                                                                                                                                                       |
+--------------------------+------+------+---------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Hocus Pocus              | Beer |  4.5 |     812 |             0 | Our take on a classic summer ale.  A toast to weeds, rays, and summer haze.  A light, crisp ale for mowing lawns, hitting lazy fly balls, and communing with nature, Hocus Pocus is offered up as a summer sacrifice to clodless days.Its malty sweetness finishes tart and crisp and is best apprediated with a wedge of orange. |
| Grimbergen Blonde        | Beer |  6.7 |     264 |             0 | None                                                                                                                                                                                                                                                                                                                              |
| Widdershins Barleywine   | Beer |  9.1 |     779 |             0 | None                                                                                                                                                                                                                                                                                                                              |
| Lucifer                  | Beer |  8.5 |     287 |             0 | None                                                                                                                                                                                                                                                                                                                              |
| Bitter                   | Beer |    4 |    1056 |             0 | None                                                                                                                                                                                                                                                                                                                              |
| Winter Warmer            | Beer |  5.2 |    1385 |             0 | None                                                                                                                                                                                                                                                                                                                              |
| Winter Welcome 2007-2008 | Beer |    6 |    1099 |             0 | None                                                                                                                                                                                                                                                                                                                              |
|                          | NULL | NULL |    NULL |          NULL | NULL                                                                                                                                                                                                                                                                                                                              |
+--------------------------+------+------+---------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</code>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM