Flexible handling of mysql Data Import errors is often used to resolve SQL file import to the database. It may be the restoration of the database from the mysqldump script or the database migration. Such an SQL file usually contains many statements. If an error occurs in a statement, the entire import task is terminated. What should I do in this situation? Prepare an SQL script demo for demonstration. SQL [SQL] SET NAMES UTF8; CREATE TABLE cc ('account _ id' mediumint (9) NOT NULL AUTO_INCREMENT, PRIMARY KEY ('account _ id ')) ENGINE = MyISAM default charset = utf8; insert into cc VALUE (1); insert into cc (2); insert into cc VALUE (3 ); import the SQL file to the database test [plain] # cat demo. SQL | mysql-u root test ERROR 1064 (42000) at line 9: You have an error in your SQL syntax; check the manual that c Orresponds to your MySQL server version for the right syntax to use near '2)' at line 1 reports an error. From the prompt information, we can see that the error statement is 9th rows. Check [plain] # tail-n + 9 demo. SQL | head-1 INSERT INTO cc (2); the plus sign before 9 indicates the 9th rows calculated starting from the file header. A syntax error is found. Use sed to replace a line [plain] # sed-I '9s/. */insert into cc VALUE (2);/'demo. SQL is replaced successfully. Next, import [plain] # tail-n + 9 demo where the error occurred. SQL | mysql-u root test check the database. All data is in the database. The import is successful. [SQL] mysql> select * from cc; + ------------ + | account_id | + ------------ + | 1 | 2 | 3 | + ------------ + 3 rows in set (0.00 sec) Source http://blog.csdn.net/afeiqiang/article/details/8823194