---
title: "select into from 提示 Undeclared variable.....错误的解决办法"
author: "junner"
date: "2015-08-17T15:22:23Z"
tags: []
categories: ["数据库"]
slug: "select-into-from-undeclared-variable"
draft: false
lastmod: "2015-08-17T15:22:23Z"
id: 2236036
url: "https://junner.iteye.com/blog/2236036"
---

在进行数据库表的复制与备份的操作过程中，我们应该都知道有 select into from 和 insert into select 两种方法吧？关于这两种方法的区别和用法，这里就不多说了，有需要的朋友可以参照本站文章： select into from 和 insert into select 的区别和用法 然而作者今天在使用 SELECT INTO FROM 备份mysql数据表的时候，运行相关 sql 语句的时候却一直返回 \[Err] 1327 - Undeclared variable: ...... 这种错误，实在不解，经过查询相关资料才知道，原来 mysql 数据库是不支持 SELECT INTO FROM 这种语句的，但是经过研究是可以通过另外一种变通的方法解决这个问题的，下面就来说说解决这个错误的办法吧！ 进过搜索相关资料以及实验结果证实，可以使用

```
Create table Table2 (Select * from Table1);
```

 这种语句代替

```
SELECT vale1, value2, value3 into Table2 from Table1;
```

 下面看一个本人实际操作中的例子吧！

```
Create table www.phpernote.com (Select A.id,B.id as typeId,A.brand,A.quanpin,A.simple from brands as A,cartype as B where A.type=B.name group by A.brand);
```

 这个是关联两个表得出一个查询结果，然后将结果插入到一个新创建的表中。