פורסם 2011 ביוני 1314 שנים אני מנסה להכניס קובץ נתונים של תוכנת DOS ישנה (קובץ ASCII נקי, עמודות ברוחב קבוע, ללא מפריד) לטבלת MYSQLקובץ דוגמה (מפושט, אבל אותו מבנה) :44443336666662222666555555iiiiwwwccccccttttxxxaaaaaamysql> create table t (col1 char(4) , col2 char(3) , col3 char (6) ) ;Query OK, 0 rows affected (0.01 sec)mysql> load data infile '/home/ash/1.txt' into table t fields terminated by '' enclosed by '' ;Query OK, 4 rows affected, 8 warnings (0.00 sec)Records: 4 Deleted: 0 Skipped: 0 Warnings: 8mysql> select * from t ;+------+------+------+| col1 | col2 | col3 |+------+------+------+| 4444 | 6 | || 2222 | 5 | || iiii | c | || tttt | a | |+------+------+------+4 rows in set (0.00 sec)איך מייבאים את הקובץ שהוא יצא נכון ?ניסיתי לשנות char / varchar זה לא משנה כלום
פורסם 2011 ביוני 1314 שנים שים לב שהוא אומר שהיו 8 אזהרות. מומלץ לבדוק מה הן.חוץ מזה:http://dev.mysql.com/doc/refman/5.5/en/load-data.htmlNote that fixed-size format does not work if you are using a multi-byte character set. ומתוך ההערות:First check to make sure your Fixed-Width is correct, then check your Table Format. I had to use latin1_general_ci to get the data to load. It would not accept my LOAD DATA INFILE with utf8_general_ci. So that should save some hairs on your head when you pull them out from the frustration.אופציה נוספת היא פשוט לחלק את השורות בעצמך, באמצעות substrTo load a text file with fixed width columns, I used the form:LOAD DATA LOCAL INFILE '<file name>' INTO TABLE <table> (@var1) SET Date=str_to_date(SUBSTR(@var1,3,10),'%m/%d/%Y'), Time=SUBSTR(@var1,14,8), WindVelocity=SUBSTR(@var1,26,5), WindDirection=SUBSTR(@var1,33,3), WindCompass=SUBSTR(@var1,38,3), WindNorth=SUBSTR(@var1,43,6), WindEast=SUBSTR(@var1,51,6), WindSamples=SUBSTR(@var1,61,4);
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.