0

我有一个现有的 sql 文件,我想将其导入 MySQL 数据库 5.5 导入后我执行:SELECT * FROM address; 而不是 'Straße' 我得到 'Straße' 导入命令是: mysql -uroot store < C:\PathTo\store.sql 使用 phpMyAdmin 我得到相同的结果。有趣的是,这在一年前就有效(也许与另一个 MySQL DB 版本一起使用)

DROP SCHEMA IF EXISTS store;
CREATE SCHEMA IF NOT EXISTS store DEFAULT CHARACTER SET=latin1;
USE store;

SET sql_mode = 'STRICT_ALL_TABLES';
SET NAMES latin1;
...
DROP TABLE IF EXISTS address;
CREATE  TABLE IF NOT EXISTS address (
  pk_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  zipCode DECIMAL(6,0)  NOT NULL,
  city VARCHAR(32) NOT NULL,
  street VARCHAR(32) NOT NULL,
  number VARCHAR(8) NOT NULL,
  fk_customer INT UNSIGNED NOT NULL,
  PRIMARY KEY (pk_id),
  CONSTRAINT
    FOREIGN KEY (fk_customer) 
    REFERENCES customer(pk_id)
    ON DELETE CASCADE 
    ON UPDATE CASCADE
);
...
insert into address (zipCode, city, street, number, fk_customer) values(111, "MyCity", "Straße", "7", 1);
...
4

1 回答 1

0

我通过添加ALTER DATABASE store DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci;到 sql 脚本文件解决了我的问题。所以它看起来像:

DROP SCHEMA IF EXISTS store;
CREATE SCHEMA IF NOT EXISTS store DEFAULT CHARACTER SET=latin1;
USE store;

ALTER DATABASE `store` DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci;

SET sql_mode = 'STRICT_ALL_TABLES';
SET NAMES latin1;
...
于 2013-05-21T13:42:40.440 回答