In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to make mistakes in importing data into mysql". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Importing a database from a SQL file is often used, either by restoring the database from a mysqldump script or by database migration. Often, such SQL files contain many statements, and if a statement goes wrong in the middle of the process, the entire import task will be terminated. How should we deal with such a situation?
First prepare a demonstration SQL script demo.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 into 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 corresponds to your MySQL server version for the right syntax to use near'2)'at line 1
Error reported. As you can see from the prompt, the statement that went wrong is line 9. Check it out.
[plain]
# tail-n + 9 demo.sql | head-1
INSERT INTO cc (2)
The + sign before 9 indicates line 9 calculated from the header of the file. A syntactic error was found. Replace a line with sed
[plain]
# sed-I '9s/.*/INSERT INTO cc VALUE (2); /' demo.sql
Replacement complete. Then continue to import what just went wrong.
[plain]
# tail-nasty 9 demo.sql | mysql-u root test
Look at the database. The data is all there. The import is successful.
[sql]
Mysql > select * from cc
+-+
| | account_id |
+-+
| | 1 |
| | 2 |
| | 3 |
+-+
3 rows in set (0.00 sec)
This is the end of the introduction of "what to do if there is an error in importing data in mysql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.