简体   繁体   English

字符组合无法从文件还原到MySQL

[英]Characters combination can't be restored from file to mySQL

There is a file 1.sql with: 1.sql文件包含:

DROP TABLE IF EXISTS `tbl`;
CREATE TABLE `tbl` (
  `row` varchar(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `tbl` VALUES ('—\'');

This sql works fine when I run it in phpMyAdmin. 当我在phpMyAdmin中运行该sql时,它工作正常。

But when I run it from cmd: 但是当我从cmd运行它时:

mysql -u root -p dtbs < 1.sql

it fails 它失败

ERROR 1064 (42000) at line 6: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''鈥擻'')' at line 1

If you change anything in —\\' , it works. 如果您在“ —\\'任何更改,则可以使用。 If you add letter between and \\' it works: —d\\' 如果您在\\'之间添加字母,则可以使用: —d\\'

What is so special in —\\' ? —\\'什么特别之处? Why I cannot use it from file in cmd (windos7-64). 为什么我不能从cmd(windos7-64)文件中使用它。 It is part of a dump which I am trying to restore. 这是我要还原的转储的一部分。

--default-character-set=utf8

做到了。

mysql -u root -p --default-character-set=utf8 dtbs < 1.sql

Try running the command chcp 850 in cmd before you run your code. 在运行代码之前,请尝试在cmd运行命令chcp 850

That will make the 1.sql file load with correct encoding. 这将使1.sql文件以正确的编码加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM