在同一个表中同时插入 MySQL:如何? [英] Simultaneous MySQL insertions in the same table: how to?
问题描述
首先,我的问题与这个.
当查询一个 MySQL 数据库进行插入时:假设多个用户同时尝试在同一个数据库表上插入行:当一个插入正在进行时,MySQL RDBMS 是否锁定插入过程?还是允许同时插入多个?
我问这个问题是因为我使用时间戳命名用户插入的图像.但是,时间戳使用秒.因此,如果 50 个用户在同一秒内插入图像:MySQL 将如何处理它们?我会有 50 张同名的图片吗?
First of all, my question has nothing to do with this one.
When querying a MySQL database for insertion: suppose several users try to insert rows on the same time on the same database table: does MySQL RDBMS lock the insertion process when one insertion is in progress ? Or does it allow multiple insertions at the same time ?
I ask this question because I am naming images inserted by users using the timestamp. However, timestamp uses seconds. So if 50 users insert images in the same seconds: how MySQL will treat them ? Will I have 50 images with the same name ?
推荐答案
是的,您(几乎可以肯定)会获得多个具有相同时间戳的图像.
Yes, you will (almost certainly) get multiple images with the same timestamp.
您可以使用AUTO_INCREMENT,UUID(),或另一种生成唯一性的方法值,但时间戳(甚至微秒精度)不是唯一的.
You can use AUTO_INCREMENT, UUID(), or another approach to generate unique values, but timestamps (even microsecond precision ones) are not unique.
这篇关于在同一个表中同时插入 MySQL:如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!