---
title: "mysql  临时表"
author: "chengwang"
date: "2012-07-25T17:41:46Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2012-07-25T17:41:46Z"
id: 1606827
url: "https://chengwang.iteye.com/blog/1606827"
---

```java
create TEMPORARY table temp1  (select * from heat_all c where UNIX_TIMESTAMP('2012-05-28 15:44:19')<=UNIX_TIMESTAMP(c.nowtime)  and UNIX_TIMESTAMP(c.nowtime)<=UNIX_TIMESTAMP('2012-05-28 16:44:55') and c.read_status = '1') 
```


创建临时表关键字 TEMPORARY 。 该表只存在当前连接，所以要确保查询该表时使用的connection与创建的connect是同一个，否则会出现No operations allowed after connection closed 错误。

使用临时表时，最好单独建立connection，记得使用完关闭该connection。