简体   繁体   中英

Error while executing SQL script but not when running individually

I am running a script file using following command:

mysql -u root -p MyTable < questions.sql

And getting following error:

ERROR 1366 (HY000) at line 8358: Incorrect string value: '\xD7 4 = ...' for column 'choiceA' at row 1

When I tried to debug, I found that this error was happening because I had special characters like multiplication and divide mathematical symbols. After doing some Googling I found that the character encoding for my database should be UTF-8, I changed that too but still getting the same error.

I am a little bit surprised that if I try to execute the same query manually in SQL prompt, it works fine!! Which means that my db encoding is correct.

I am not able to figure out where can be the issue and seek some exert advice.

The questions.sql file must be UTF-8. Save the file with this encoding.

After doing little bit investigation,I found the solution of the above issue.

In my case, I was generating the sql from a cvs file and somehow some special characters were appearing in the generated sql file and which is stopping mysql to load the data into the database showing the above mentioned error.

As I said above that, SQL workbench was able to parse the sql file properly and was able to load the data into DB. So, I first loaded the data into the database and then using Server > Data Export feature present in Workbench, I exported entire data into a sql file. I was able to successfully execute the workbench generated sql file using following command line:

mysql -u root -p MyTable < questions.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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