简体   繁体   English

分块导入 sql 数据

[英]Import sql data in chunks

I have a large size of sql file.我有一个大尺寸的 sql 文件。 I have to import data but when i import only 10-20 records then inserting data in database correctly but when i tried with whole file then having no data in database.我必须导入数据,但是当我只导入 10-20 条记录时,然后正确地将数据插入数据库中,但是当我尝试使用整个文件时,数据库中没有数据。 May be there is some data issue So I want to insert data in chunks but could not find any right solutions.可能存在一些数据问题所以我想分块插入数据但找不到任何正确的解决方案。 Is their any another possible solution?他们还有其他可能的解决方案吗?

Thanks in advance提前致谢

As explain Henning Koch in this card the best way to import a dump safely is正如这张卡片中的 Henning Koch 所解释的,安全导入转储的最佳方法是

mysql -uroot -p --default-character-set=utf8mb4 database
mysql> SET names 'utf8'
mysql> SOURCE utf8.dump

And as Henning says正如亨宁所说

Note that when your MySQL server is not set to UTF-8 you need to do mysqldump --default-character-set=latin1 (.) to get a correctly encoded dump, In that case you will also need to remove the SET NAMES='latin1' comment at the top of the dump.请注意,当您的 MySQL 服务器未设置为 UTF-8 时,您需要执行 mysqldump --default-character-set=latin1 (.) 以获得正确编码的转储,在这种情况下,您还需要删除 SET NAMES='latin1 ' 转储顶部的评论。 so the target machine won't change its UTF-8 charset when sourcing.因此目标机器在采购时不会更改其 UTF-8 字符集。

Is important check the server configuration because you can get corrupted data if the charsets no match.检查服务器配置很重要,因为如果字符集不匹配,您可能会得到损坏的数据。 In this post Mathias explain how to get full support for unicode on mysql.在这篇文章中,Mathias 解释了如何在 mysql 上获得对 unicode 的全面支持。 The important part in this post for you is the way to check the server configuration这篇文章对你来说重要的部分是检查服务器配置的方法

mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8mb4            |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8mb4            |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+
10 rows in set (0.00 sec)

You must use the right charsets for you case.您必须为您的情况使用正确的字符集。 Check too if you target server was configured properly.还要检查您的目标服务器是否配置正确。

If you need modify the server configuration go to /etc/my.cnf, or if you use windows go to the server installation directory (ex. C:\Program Files\MySQL\MySQL Server 5.6) and locate the my.ini file. If you need modify the server configuration go to /etc/my.cnf, or if you use windows go to the server installation directory (ex. C:\Program Files\MySQL\MySQL Server 5.6) and locate the my.ini file. If the file not exists copy my-default.ini into my.ini如果文件不存在,将 my-default.ini 复制到 my.ini

By Mathias通过马蒂亚斯

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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