我从人口普查下载了一些数据库 - Fact Finder:
开始使用加州住房数据库,使用CVed我拿出了我不需要的所有列,然后继续在MySQL Workbench中创建一个模型,后来我通过命令行变成了数据库:
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema Census
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema Census
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `Census` DEFAULT CHARACTER SET utf8 ;
USE `Census` ;
-- -----------------------------------------------------
-- Table `Census`.`Housing`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Census`.`Housing` (
`SERIALNO` BIGINT(13) NOT NULL,
`DIVISION` INT(9) NULL,
`PUMA` INT(4) NULL,
`REGION` INT(1) NULL,
`ST` INT(1) NULL,
`ADJHSG` INT(7) NULL,
`ADJINC` INT(7) NULL,
`FINCP` INT(6) NULL,
`HINCP` INT(6) NULL,
`R60` INT(1) NULL,
`R65` INT(1) NULL,
PRIMARY KEY (`SERIALNO`))
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
创建数据库后,我继续导入数据:
LOAD DATA INFILE "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/Housing_California.csv"
INTO TABLE housing
CHARACTER SET latin1
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n';
但它不起作用,因为出现此错误消息:ERROR 1366(HY000):不正确的整数值:''对于第15行的列'FINCP'
现在,我现在在那一行,我有一个空白值,该列指的是家庭收入,在某些情况下是0,所以人口普查将其留空:
2012000000135,9,6515,4,6,1045360,1056030,,43100,1,0
我可以将所有空白单元格更改为0,但我觉得必须有更好的处理方法。
希望你能给点小费。
答案 0 :(得分:0)
这可以帮到你 您可以更改导入
,而不是更改表定义以这种方式,FINCP的val在插入之前存储在var中,您可以检查是否有正确的结果 在mi建议中,如果将null指定给''但你可以指定你喜欢的(适当的)值
LOAD DATA INFILE "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/Housing_California.csv"
INTO TABLE housing
CHARACTER SET latin1
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
( `SERIALNO`, `DIVISION`, `PUMA`, `REGION`,
`ST`, `ADJHSG`, `ADJINC`, @var_fincp,
`HINCP`, `R60`, `R65`)
set `FINCP` = nullif(@var_fincp,'')
;
答案 1 :(得分:0)
Kiko Software,
好的,所以我读了你发布的链接,我的命令行最终结束了;
LOAD DATA INFILE "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/Housing_Illinois.csv"
INTO TABLE housing
CHARACTER SET latin1
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
(@SERIALNO, @DIVISION, @PUMA, @REGION, @ST, @ADJHSG, @ADJINC, @FINCP, @HINCP, @R60, @R65)
SET
SERIALNO = nullif(@SERIALNO,''),
DIVISION = nullif(@DIVISION,''),
PUMA = nullif(@PUMA,''),
REGION = nullif(@REGION,''),
ST = nullif(@ST,''),
ADJHSG = nullif(@ADJHSG,''),
ADJINC = nullif(@ADJINC,''),
FINCP = nullif(@FINCP,''),
HINCP = nullif(@HINCP,''),
R60 = nullif(@R60,''),
R65 = nullif(@R65,'');
我得到了这条消息:
'对于第12行的列'R65'整数值:'
这意味着什么?
这是row12:
的数据2012000000318,3,1602,2,17,1045360,1056030 ,,,,
答案 2 :(得分:0)
当您尝试在mysql表中插入数据时,如果设置为要求填充所有字段,则会收到此错误。
如果不发送值,则可以将mysql配置为设置NULL。临时解决方案(直到重新启动服务器)才能运行此查询:SET @@ GLOBAL.sql_mode ='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
或者您可以在my.ini文件中进行设置。以下是模式的详细信息:http://webnetkit.com/error-sqlstatehy000-general-error-1366-incorrect-integer-value-for-column/