MySQL如何处理并发插入? [英] How does MySQL handle concurrent inserts?

查看:1223
本文介绍了MySQL如何处理并发插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道MySQL中并发SELECT和INSERT存在一个问题.但是,我的问题是我是否要与MySQL建立两个连接并继续使用这两个连接来加载数据,MySQL是同时获取数据还是在加载另一个之前等待一个完成?

I know there is one issue in MySQL with concurrent SELECT and INSERT. However, my question is if I open up two connections with MySQL and keep loading data using both of them, does MySQL takes data concurrently or waits for one to finish before loading another?

我想知道MySQL在这两种情况下的表现.就像我尝试打开单独的连接时尝试同时在同一张表或不同表中加载数据时一样.

I’d like to know how MySQL behaves in both cases. Like when I am trying to load data in the same table or different tables concurrently when opening separate connections.

推荐答案

如果您将创建与数据库的新连接并从两个链接中执行插入,那么从数据库的角度来看,它仍将是顺序的.

If you will create a new connection to the database and perform inserts from both the links, then from the database's perspective, it will still be sequential.

MySQL上并发插入的文档文档页面上说:

The documentation of Concurrent Inserts on the MySQL's documentation page says:

如果有多个INSERT语句,它们将与SELECT语句同时排队并按顺序执行.

If there are multiple INSERT statements, they are queued and performed in sequence, concurrently with the SELECT statements.

请注意,无法控制两个并发插入的顺序.并发中的顺序受许多不同因素的影响.为了确保顺序,默认情况下,您将不得不牺牲并发性.

Mind that there is no control over the order in which two concurrent inserts will take place. The order in this concurrency is at the mercy of a lot of different factors. To ensure order, by default you will have to sacrifice concurrency.

这篇关于MySQL如何处理并发插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆