MySQL临时表是共享资源吗? [英] Is MySQL Temporary table a shared resource?

查看:92
本文介绍了MySQL临时表是共享资源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用临时表的MySQL存储过程.假设我的表名是"temp",我用它来存储一些中间数据.它将在过程开始时创建,并在过程结束时下降.

I have a MySQL stored procedure that uses a temporary table. Assume that my table name is 'temp' and I use it to store some middle data. It will create at the beginning of procedure, and will drop at the end.

CREATE PROCEDURE p()
BEGIN

CREATE TEMPORARY TABLE \`temp\`(...);

INSERT INTO \`temp\` VALUES(...);

DROP TEMPORARY TABLE \`temp\`;

END;

问题在于此存储过程可能由不同的用户同时使用,因此我想知道这是否会引起任何问题(即,临时表中插入数据中的任何冲突).换句话说,临时表是对同一SP的不同调用内的共享资源吗?

The problem is that this stored procedure may be used by different users concurrently, so I want to know if this can cause any problems (i.e. any conflict in inserted data in temp table). In other word is temp table a shared resource within different calls to the same SP?

推荐答案

否,临时表仅限于数据库连接范围.您可以在同一数据库连接期间的后续调用过程中使用临时表,但其他连接无法访问它.他们可以用相同的名称创建一个表,但是每个临时表将是独立的.关闭连接后,临时表会消失.

No, a temp table is limited to the scope of your database connection. You can use the temp table in subsequent calls to the procedure during the same database connection, but other connections cannot access it. They can create a table by the same name, but each temp table will be independent. Temp tables go away when you close your connection.

这篇关于MySQL临时表是共享资源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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