Flexible handling of mysql import data errors

Source: Internet
Author: User
Tags mysql import

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.