mysql 批量插入
我正在进行批量插入,每批插入 80k 条记录和 1200 条记录。 查询执行良好。问题是我正在从 mssql 服务器获取数据并从中创建一个批处理数组。因此,由于某种原因,其中一个批量插入失败,导致发生了变化。
但是,当批量插入失败时,该特定批次的所有 1200 条记录都会失败。
那么,有没有办法找出如何从批量插入失败的那批1200条记录中获取准确的记录。
还有一个问题。
在进行这些插入时,网站会因更新而关闭。
有什么办法可以让网站在这段时间不宕机吗?
任何帮助将不胜感激。
谢谢
I am doing batch insert for inserting 80k records and 1200 records per batch.
The query is executing fine. The problem is that I am getting data from mssql server and creating a batch array out of it. So there are changes are due to some reason one of the batch insert fails.
But when a batch insert fails, it does for all 1200 records of that particular batch.
So, is there any way to find out how to get the exact records from the batch of 1200 records that failed the batch insertion.
And one more question.
While doing these insertion, the web site goes down for the time of updation.
Is there any way that during this time as well the site is not down.
Any help will be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有任何工具可以为您提供更高的性能,因为您的瓶颈是您的服务器......
降低服务器负载的方法是使用事务或使用“延迟插入”。
事务: [ http://dev.mysql.com/doc/ refman/4.1/...-commands.html]
如果您的数据库支持它(mysql可能需要特定的后端来支持它,具体取决于mysql版本),您可以通过发送“start tansaction”来启动事务,然后一个接一个地发送所有插入,并用“完成事务”提交”或“回滚”。
这种方法有一个很大的优点,即数据库知道在提交之前它不必重新计算索引。
延迟插入:[ http://dev.mysql.com/ doc/refman/4.1/...t-delayed.html]
这是一个特殊的 mysql 命令,可让您向数据库提供有关插入重要性的提示。
当数据库不会被占用做其他事情时,延迟插入总是会被处理,与标准插入/更新相比,它的优先级较低。
No tools will give you more performance, as your bottleneck is your server...
what you can do to lower the server load is either to use transactions, or use "insert delayed".
Transaction: [ http://dev.mysql.com/doc/refman/4.1/...-commands.html ]
If your db support it (mysql may need a specific backend to support it, depending of mysql version), you start a transaction by sending "start tansaction", then send all your insert one after the other, and finish the transaction with a "commit" or a "rollback".
This method have the great advantage that the db knows that it don't have to re-compute the indexes before you do the commit.
insert delayed: [ http://dev.mysql.com/doc/refman/4.1/...t-delayed.html ]
This is a special mysql command, that let you give a hint on the db about the importance of the insert.
An insert delayed will always be processed when the db will not be occupied doing something else, it have a low priority comparing to standard insert/update.