MySQL错误1366不正确的字符串值

时间:2013-10-03 18:50:30

标签: mysql string

我一直在寻找答案,但我还没有找到解决方案。 背景: 我在我的计算机上运行了一个MySQL Server 5.5来测试数据,这些数据最终将被加载到我公司的Production Server中。我在MySQL Workbench中创建了数据库,并在适当时编辑它以适应我加载时的数据。我的数据远远不够干净,所以在大多数情况下我使用VARCHAR作为我的字段,因为可以将大量随机内容放入字段中。我尝试过更改多项内容,我不再确定我所做的任何事情是否已经修复甚至帮助消除了这个问题。

我的代码: 数据库创建:

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';

SET NAMES utf8;

DROP SCHEMA IF EXISTS `mydb` ;
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`Customer_Account`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Customer_Account` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Customer_Account` (
  `idCustomer_Account` VARCHAR(20) NOT NULL,
  `Name` VARCHAR(130) NOT NULL,
  `Billing_Street` VARCHAR(150) NULL,
  `Billing_City` VARCHAR(30) NULL,
  `Billing_StateProvince` VARCHAR(25) NULL,
  `Billing_PostalCode` VARCHAR(15) NULL,
  `Billing_Country` VARCHAR(20) NULL,
  `Location_Type` VARCHAR(15) NULL,
  `Parent_ID` VARCHAR(20) NULL,
  `Parent_Name` VARCHAR(130) NULL,
  PRIMARY KEY (`idCustomer_Account`),
  UNIQUE INDEX `idCustomer_Account_UNIQUE` (`idCustomer_Account` ASC))
ENGINE = InnoDB DEFAULT CHARSET=utf8;

  'CONSTRAINT `Parent_ID`
    FOREIGN KEY (`idCustomer_Account`)
    REFERENCES `mydb`.`Customer_Account` (`idCustomer_Account`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)'

-- -----------------------------------------------------
-- Table `mydb`.`Customer_Address`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Customer_Address` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Customer_Address` (
  `idCustomer_Address` VARCHAR(20) NOT NULL,
  `Name` VARCHAR(50) NOT NULL,
  `Name_Int` INT,
  `Address` VARCHAR(80) NULL,
  `City` VARCHAR(30) NULL,
  `State` VARCHAR(5) NULL,
  `ZIP` VARCHAR(15) NULL,
  `LinkedAccount_Name` VARCHAR(100) NULL,
  `LinkedAccount_ID` VARCHAR(20) NULL,
  `CADD` INT,
  PRIMARY KEY (`idCustomer_Address`),
  UNIQUE INDEX `idCustomer_Address_UNIQUE` (`idCustomer_Address` ASC))
ENGINE = InnoDB DEFAULT CHARSET=utf8;

-- -----------------------------------------------------
-- Table `mydb`.`Contacts`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Contacts` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Contacts` (
  `idContacts` VARCHAR(20) NOT NULL,
  `Name` VARCHAR(50) NOT NULL,
  `Title` VARCHAR(130) NULL,
  `Mailing_Street` VARCHAR(110) NULL,
  `Mailing_City` VARCHAR(30) NULL,
  `Mailing_State` VARCHAR(25) NULL,
  `Mailing_PostalCode` VARCHAR(20) NULL,
  `Phone` VARCHAR(50) NULL,
  `Account_ID` VARCHAR(20) NULL,
  `Account_Name` VARCHAR(100) NULL,
  PRIMARY KEY (`idContacts`),
  UNIQUE INDEX `idContacts_UNIQUE` (`idContacts` ASC))
ENGINE = InnoDB DEFAULT CHARSET=utf8;


-- -----------------------------------------------------
-- Table `mydb`.`Contact_Details`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Contact_Details` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Contact_Details` (
  `idContact_Details` VARCHAR(20) NOT NULL,
  `Salutation` VARCHAR(70) NULL,
  `First_Name` VARCHAR(30) NULL,
  `Last_Name` VARCHAR(50) NULL,
  `Title` VARCHAR(130) NULL,
  `Mailing_Street` VARCHAR(175) NULL,
  `Mailing_City` VARCHAR(50) NULL,
  `Mailing_StateProvince` VARCHAR(30) NULL,
  `Mailing_PostalCode` VARCHAR(20) NULL,
  `Mailing_Country` VARCHAR(25) NULL,
  `Phone` VARCHAR(50) NULL,
  `Mobile` VARCHAR(35) NULL,
  `Fax` VARCHAR(45) NULL,
  `Email` VARCHAR(75) NULL,
  `Email_OptOut` VARCHAR(1) NULL,
  `Account_Owner` VARCHAR(20) NULL,
  `Account_Name` VARCHAR(125) NULL,
  `Account_ID` VARCHAR(20) NOT NULL,
  `Active` VARCHAR(2) NOT NULL,
  PRIMARY KEY (`idContact_Details`),
  UNIQUE INDEX `idContact_Details_UNIQUE` (`idContact_Details` ASC))
ENGINE = InnoDB DEFAULT CHARSET=utf8;

'INDEX `Account_ID_idx` (`Account_ID` ASC)'

-- -----------------------------------------------------
-- Table `mydb`.`WF1_SR_Accounts`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`WF1_SR_Accounts` ;

CREATE TABLE IF NOT EXISTS `mydb`.`WF1_SR_Accounts` (
  `idWF1_SR_Accounts` VARCHAR(20) NOT NULL,
  `Name` VARCHAR(125) NOT NULL,
  `Billing_Street` VARCHAR(135) NULL,
  `Billing_City` VARCHAR(50) NULL,
  `Billing_State` VARCHAR(20) NULL,
  `Billing_PostalCode` VARCHAR(20) NULL,
  `Billing_Country` VARCHAR(25) NULL,
  `Location_Type` VARCHAR(20) NULL,
  `Parent_ID` VARCHAR(20) NULL,
  `Parent_Name` VARCHAR(125) NULL,
  `SR_Account?` VARCHAR(5) NULL,
  `WF1_Account?` VARCHAR(5) NULL,
  `WF1_AccountNum` VARCHAR(10) NULL,
  `WF1_AccountStatus` VARCHAR(25) NULL,
  `WF1_AccountCreated` VARCHAR(50) NULL,
  `WF1_BU` VARCHAR(10) NULL,
  `WF1_Collector` VARCHAR(20) NULL,
  `WF1_CreditHold` VARCHAR(5) NULL,
  `WF1_CreditLimit` VARCHAR(10) NULL,
  `WF1_CreditRating` VARCHAR(15) NULL,
  `WF1_DVP` VARCHAR(20) NULL,
  `WF1_PaymentTerms` VARCHAR(20) NULL,
  `WF1_RSD` VARCHAR(40) NULL,
  `WF1_TerritoryName` VARCHAR(45) NULL,
  `WF1_TerritoryNumber` VARCHAR(5) NULL,
  `Select_` VARCHAR(5) NULL,
  `New_Select` VARCHAR(5) NULL,
  `CRMFusion_Use` VARCHAR(10) NULL,
  `CRMFusion_Change` VARCHAR(10) NULL,
  PRIMARY KEY (`idWF1_SR_Accounts`),
  UNIQUE INDEX `idWF1_SR_Accounts_UNIQUE` (`idWF1_SR_Accounts` ASC))
ENGINE = InnoDB DEFAULT CHARSET=utf8;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

注意:我还在SET NAMES,DEFUALT CHARSET和CHARACTER_SET_SERVER中将latin1替换为utf8,并尝试制作两种加密类型的.txt文件。

我也跑了

SHOW VARIABLES like 'char%';

这是我的结果:

Variable_name                   Value
character_set_client            latin1
character_set_connection            latin1
character_set_database          utf8
character_set_filesystem            binary
character_set_results           latin1
character_set_server            latin1
character_set_system            utf8
character_sets_dir            C:\Program Files\MySQL\MySQL Server 5.5\share\charsets\

注意:在某一点上,除文件系统和服务器之外的所有内容都是utf8,它也不起作用。

我还更改了excel和notepad ++中的加密类型,并且改变它似乎没有帮助。

1 个答案:

答案 0 :(得分:0)

主键需要从INT更改为VARCHAR(45)数据类型。