mysql 出错 1300和 1366 出错解决方法记录 百万级数据快速导入记录

  • Post author:
  • Post category:mysql


出错:

ERROR 1300 (HY000): Invalid utf8 character string ”

load data infile 'f:/Mysql/data/song.sql' 
into table music 
character set utf8 
fields terminated by "|||"
(mid,name,sid,album); 

不管terminated by换成什么都会出现这个错误,然后百度了一下说需要改表的字符集为gbk或者gb2312,发现这个不能从根本解决问题,因为表内容是用utf8存储的,数据库也是utf8,改这个没有意义,并且后面小改了一下也不能解决问题。

后面在改分隔符的时候提示’??0’不是期望的数据,错误出现在第一行,于是大致定位了出错的原因是换行符。

最后解决了问题的方案是:

修改文件字符集为utf-8无bom格式,换行符为windows cr/lf

出错:

ERROR : 1366 Incorrect integer value

这个出错是出现在修改load data的ENCLOSED BY字符的时候,由于之前的字符是这样

'00000059877', '再唱一首', '1876', '0'

然后数字不能读取,所以需要去掉‘’

00000059877, 再唱一首, 1876, 0

但是有一个问题就是

varchar

字段会出现分隔符:

,

所以需要修改成不常用的字符:

|||


有时字段会出现单个

|

,所以搜索

||||

然后将分割成

| |||

或者

||| |

就可以了。

同样记得改字符集和换行符,然后注意文本开头和结尾的换行符和空格符。

总结一下: 大部分按照正规操作来都不会是设置的问题,大部分是文件编码和格式的问题。

格式化时间内容:

STR_TO_DATE(str,format) is the inverse of the DATE_FORMAT() function.

STR_TO_DATE() returns a DATETIME value.

The following specifiers may be used in the format string.

The ‘%’ character is required before format specifier characters.

Specifier Description

%a  Abbreviated weekday name (Sun..Sat)
%b  Abbreviated month name (Jan..Dec)
%c  Month, numeric (0..12)
%D  Day of the month with English suffix (0th, 1st, 2nd, 3rd, ?-)
%d  Day of the month, numeric (00..31)
%e  Day of the month, numeric (0..31)
%f  Microseconds (000000..999999)
%H  Hour (00..23)
%h  Hour (01..12)
%I  Hour (01..12)
%i  Minutes, numeric (00..59)
%j  Day of year (001..366)
%k  Hour (0..23)
%l  Hour (1..12)
%M  Month name (January..December)
%m  Month, numeric (00..12)
%p  AM or PM
%r  Time, 12-hour (hh:mm:ss followed by AM or PM)
%S  Seconds (00..59)
%s  Seconds (00..59)
%T  Time, 24-hour (hh:mm:ss)
%U  Week (00..53), where Sunday is the first day of the week
%u  Week (00..53), where Monday is the first day of the week
%V  Week (01..53), where Sunday is the first day of the week; used with %X
%v  Week (01..53), where Monday is the first day of the week; used with %x
%W  Weekday name (Sunday..Saturday)
%w  Day of the week (0=Sunday..6=Saturday)
%X  Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x  Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y  Year, numeric, four digits
%y  Year, numeric (two digits)
%%  A literal '%' character
%x  x, for any 'x' not listed above

14.39.STR_TO_DATE

14.39.1. STR_TO_DATE(str,format)

14.39.2. SELECT STR_TO_DATE(‘00/00/0000’, ‘%m/%d/%Y’);

14.39.3. SELECT STR_TO_DATE(‘04/31/2004’, ‘%m/%d/%Y’);

14.39.4. To convert a year-week to a date, then you should also specify the weekday:


https://stackoverflow.com/questions/18927249/how-to-load-date-data-in-mysql-when-using-load-data



http://www.java2s.com/Tutorial/MySQL/0280__Date-Time-Functions/STRTODATEstrformat.htm



版权声明:本文为mistyrain0109原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。