While importing mysqldump file ERROR 1064 (42000) near ' ■/ ' at line 1

丶灬走出姿态 提交于 2019-12-03 03:52:54

问题


Cannot import the below dump file created by mysqldump.exe in command line of windows

/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `attachment_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `DESCRIPTION` varchar(50) DEFAULT NULL,
  `COMMENTS` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `UK_ATTACHMENT_TYPES___DESCRIPTION` (`DESCRIPTION`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

While importing the file in command line

mysql --user=root --password=root < mysqldumpfile.sql

It throws error

ERROR 1064 (42000) near ' ■/ ' at line 1

Somebody please help me.


回答1:


Finally I got a solution

We need two options

  • --default-character-set=utf8: This insures UTF8 is used for each field
  • --result-file=file.sql: This option prevents the dump data from passing through the Operating System which likely does not use UTF8. Instead it passes the dump data directly to the file specified.

Using these new options your dump command would look something like this:

mysqldump -u root -p --default-character-set=utf8 --result-file=database1.backup.sql database1

While Importing you can optionally use:

mysql --user=root --password=root --default_character_set utf8 < database1.backup.sql

Source:http://nathan.rambeck.org/blog/1-preventing-encoding-issues-mysqldump




回答2:


It seems that the input file (mysqldumpfile.sql) was created in UTF-8 encoding so these first 3 bytes "at line 1" invisible to you in the .SQL file is the byte order mark (BOM) sequence

So try to change default character set to UTF-8

mysql --user=root --password=root --default_character_set utf8 < mysqldumpfile.sql



回答3:


This is the import command I required on Windows:

mysql --user=root --password=root --default_character_set utf8 database2 < database1.backup.sql

Needed database to import into



来源:https://stackoverflow.com/questions/21752550/while-importing-mysqldump-file-error-1064-42000-near-at-line-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!