MySQL 报错:ERROR 1137 (HY000): Can't reopen table: 'tempId'

1. sql 如下

select
replace(group_concat(distinct tsk.task_name),',' , '\n') as res2
from tempId
join custom_task_rule tskon tsk.task_id = tempId.dependency_job_id
where tempId.dependency_job_id not in (select task_idfrom etl_process_logwhere task_id in(selectdependency_job_idfrom tempId)   and status = 2and logging_time > '2018-11-30 00:00:00'
);
ERROR 1137 (HY000): Can't reopen table: 'tempId'

其中tempId是一个临时表。
执行如上SQL时,得到的结果是Can't reopen table:'tempId',然后仔细检查一遍SQL,除了写的丑了一点儿之外,也没有别的错了啊。于是打开mysql refman手册。

2. 原因

手册中关于 temporary table 的介绍如下:

其中较为关键的提示就是:

You cannot refer to a TEMPORARY table more than once in the same query. For example, the following does not work:
SELECT * FROM temp_table JOIN temp_table AS t2;
The statement produces this error:
ERROR 1137: Can't reopen table: 'temp_table'
The Can’t reopen table error also occurs if you refer to a temporary table multiple times in a stored
function under different aliases, even if the references occur in different statements within the function.
It may occur for temporary tables created outside stored functions and referred to across multiple calling
and callee functions.

在一个查询中能且仅能引用一次 temporary 表。 上述的那个查询中将会不work。这个SQL 将会报ERROR 1137: Can't reopen table: 'temp_table'错误。
如果你在一个函数中以不同的别名多次引用相同的临时表,即使在函数不同的语句中引用,这个错误同时会出现。对于在存储函数之外创建的临时表,但又在多个调用和被调用函数中引用,也可能会出现这种情况。

3. 解决办法

所以我们需要修改这个SQL,使其在一个query中只使用到一次tempId表即可

MySQL 报错:ERROR 1137 (HY000): Can't reopen table: 'tempId'相关推荐

  1. 解决MySQL报错ERROR 2002 (HY000)【转】

    今天在为新的业务线搭架数据库后,在启动的时候报错 root@qsbilldatahis-db01:/usr/local/mysql/bin# ./mysql ERROR 2002 (HY000): C ...

  2. 解决MySQL报错ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)

    解决MySQL报错ERROR 2003 HY000: Can't connect to MySQL server on 'localhost:3306' 10061   笔者在新电脑安装完 MySQL ...

  3. 解决MySQL报错ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)

    解决MySQL报错ERROR 2003 HY000: Can't connect to MySQL server on 'localhost:3306' 10061 笔者在新电脑安装完 MySQL 后 ...

  4. mysql报错-ERROR 1206 (HY000)- The total number of locks exceeds the lock table size-的解决方法

    mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法 问题 ...

  5. 解决Linux MySQL报错ERROR 2002 (HY000)

    ---------------------------------1--------------------------------- 在Linux安装MySQL有时候会出现[mysql]ERROR ...

  6. mysql报错ERROR 1206 (HY000): The total number of locks exceeds the lock table size的解决方法...

    1. 问题背景         InnoDB是新版MySQL(v5.5及以后)默认的存储引擎,之前版本的默认引擎为MyISAM,因此,低于5.5版本的mysql配置文件.my.cnf中,关于InnoD ...

  7. 解决mysql报错ERROR 2002 (HY000)

    解决Mysql报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/my ...

  8. mysql 报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin

    今天在窗口使用命令执行操作时,总是这个报错,一开始感觉莫名其妙 ERROR 1820 (HY000): You must reset your password using ALTER USER st ...

  9. mysql 2002_解决MySQL报错ERROR 2002 (HY000)

    今天在为新的业务线搭架数据库后,在启动的时候报错 root@qsbilldatahis-db01:/usr/local/mysql/bin# ./mysql ERROR 2002 (HY000): C ...

  10. mysql报错ERROR 1366(HY000)

    环境: mysql5.7 + CentOS release 6.5 (Final) 操作: 执行 source /data/sql/one_player_data.sql 现象: 1.执行source ...

最新文章

  1. 浅谈android的事件分发机制
  2. POJ 3034 Whac-a-Mole(DP)
  3. 【算法与数据结构】在n个数中取第k大的数(基础篇)
  4. 总结2020,起航2021,奔向腾讯,实现增长!
  5. MySQL查看及修改字段的字符集
  6. 我的世界局域网联机找不到服务器,我的世界局域网联机显示无效的会话和搜不到主机...
  7. 操作12864(ST7920控制器)
  8. Cef mysql.exe_CEF3.2623使用记录:windows编译
  9. extern和static的区别
  10. 数据结构之优先队列:优先队列的介绍与基础操作实现,Python代码实现——14
  11. 蚂蚁架构师郭援非:分布式数据库是金融机构数字化转型的最佳路径
  12. LeetCode Solutions : Reorder List
  13. 第一百三十一节,JavaScript,封装库--CSS
  14. linux mysql多实例启动_Mysql实例Linux下启动多个mysql服务器例子
  15. mysql数据库优化面试redis持久化_【大厂面试06期】谈一谈你对Redis持久化的理解?...
  16. lldp协议代码阅读_LLDP 链路层发现协议
  17. (知乎)男生 25 岁了,应该明白哪些道理?
  18. 基于C++和opengl实现太阳系动画演示系统 课程论文+项目源码
  19. [转载]三、二、一 …… Geronimo!,第 2 部分: 构建 Geronimo
  20. 双线双IP和BGP双线有什么区别?

热门文章

  1. 全文检索四种技术解决方案
  2. java 查找英语单词相似度,用于单词匹配,法1
  3. 更进一步的提高 SSL 的安全性,支持 Forward Secrecy
  4. MSP430下载程序BSL
  5. obsidian如何修改主题
  6. 面试官说:Spring这几个问题你回答下,月薪3万,下周来上班!
  7. idea 查看源码 /* compiled code*/
  8. vuex 状态管理模式 + 库(大仓库与小仓库)
  9. MMDetection框架入门教程(完全版)
  10. 身份证,银行卡,姓名用*号隐藏中间数字