Solved

When importing from CSV, why is MySQL raising a 'Data truncated' warning?

Posted on 2009-05-11
3
649 Views
Last Modified: 2012-05-06
When running a simple SQL command to import some CSV data, I'm receiving warnings on a particular column on seemingly random rows:
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 2
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 3
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 5
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 6
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 8

Here is the schema of the DB:
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| IdxId       | double       | NO   |     | NULL    |       |
| YrGrpId     | double       | NO   |     | NULL    |       |
| GroupNum    | double       | NO   |     | NULL    |       |
| LineNum     | int(11)      | NO   |     | NULL    |       |
| LogicalMod  | int(11)      | YES  |     | NULL    |       |
| Application | varchar(255) | YES  |     | NULL    |       |
| SubGroupNum | double       | YES  |     | NULL    |       |
| SubCategory | varchar(2)   | YES  |     | NULL    |       |
| PTypeNum    | char(3)      | YES  |     | NULL    |       |
| IntchNum    | char(5)      | YES  |     | NULL    |       |
| AlphaExt    | char(2)      | YES  |     | NULL    |       |
| LRFlag      | char(1)      | YES  |     | NULL    |       |
+-------------+--------------+------+-----+---------+-------+

Any insight as to what I need to change?
load data local infile 'Idx_App.txt' into table `Idx_App`
fields terminated by ','
enclosed by ''''
lines terminated by '\r\n'
(IdxId, YrGrpId, GroupNum, LineNum, LogicalMod, Application, SubGroupNum, SubCategory, PTypeNum, IntchNum, AlphaExt, LRFlag)
;

Open in new window

Idx-App.txt
0
Comment
Question by:fluffyx
3 Comments
 
LVL 6

Expert Comment

by:bull_rider
ID: 24361078
What I observed is if teh subgroupname is not provided that row fails. Can you check the datatype or may be the column in the database is accepting NULL or blank values or not?
0
 
LVL 6

Accepted Solution

by:
BALMUKUND KESHAV earned 250 total points
ID: 24361406
problem is where is subgroup has no data, and its showing like ,,,
if you have checked your subgroup fields type accepting null or 0,then if its varchar type then try to change your txt fields format like this
fields enclosed with " " sepereated with , and ensure where is no data it shows ""
then use this command

 load data local infile 'Idx_App.txt' into table `Idx_App`
fields terminated by ","
enclosed by ""
lines terminated by '\r\n'
(IdxId, YrGrpId, GroupNum, LineNum, LogicalMod, Application, SubGroupNum, SubCategory, PTypeNum, IntchNum, AlphaExt, LRFlag)

bm keshav

 
0
 

Author Closing Comment

by:fluffyx
ID: 31580376
That's causing it! Now comes the challenge of modifying the 80MB TXT file :-).
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now