【问题标题】:showing temporay table doesn't exist why?显示临时表不存在为什么?
【发布时间】:2014-02-18 07:12:39
【问题描述】:

我的尝试, 但收到类似 Table 'dbname.rep3' 的错误消息不存在。

为什么?

DROP TEMPORARY TABLE IF EXISTS rep1;
DROP TEMPORARY TABLE IF EXISTS rep2;
DROP TEMPORARY TABLE IF EXISTS rep3;

CREATE TEMPORARY TABLE `rep1`(SELECT * FROM `config`);
CREATE TEMPORARY TABLE `rep2`(SELECT * FROM `config`);
/*CREATE TEMPORARY TABLE `rep3` SELECT * FROM `rep1` UNION ALL SELECT * FROM `rep2`; 
SELECT * FROM `rep3`; */

CREATE TEMPORARY TABLE `rep3` SELECT * FROM `rep1` UNION ALL SELECT * FROM `rep2`; 
SELECT * FROM `rep3`; 

【问题讨论】:

    标签: mysql database stored-procedures


    【解决方案1】:

    它对我有用

    abdul@xmpp3:~$ mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 334
    Server version: 5.5.29-0ubuntu0.12.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> use world_innodb;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> DROP TEMPORARY TABLE IF EXISTS rep1;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> DROP TEMPORARY TABLE IF EXISTS rep2;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> DROP TEMPORARY TABLE IF EXISTS rep3;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> 
    mysql> CREATE TEMPORARY TABLE `rep1`(SELECT * FROM world_innodb.City);
    Query OK, 4079 rows affected (1.70 sec)
    Records: 4079  Duplicates: 0  Warnings: 0
    
    mysql> CREATE TEMPORARY TABLE `rep2`(SELECT * FROM world_innodb.City);
    Query OK, 4079 rows affected (1.29 sec)
    Records: 4079  Duplicates: 0  Warnings: 0
    
    mysql> 
    mysql> CREATE TEMPORARY TABLE `rep3` SELECT * FROM `rep1` UNION ALL SELECT * FROM `rep2`; 
    Query OK, 8158 rows affected (2.50 sec)
    Records: 8158  Duplicates: 0  Warnings: 0
    
    mysql> SELECT * FROM `rep3` LIMIT 10; 
    +----+----------------+-------------+---------------+------------+
    | ID | Name           | CountryCode | District      | Population |
    +----+----------------+-------------+---------------+------------+
    |  1 | Kabul          | AFG         | Kabol         |    1780000 |
    |  2 | Qandahar       | AFG         | Qandahar      |     237500 |
    |  3 | Herat          | AFG         | Herat         |     186800 |
    |  4 | Mazar-e-Sharif | AFG         | Balkh         |     127800 |
    |  5 | Amsterdam      | NLD         | Noord-Holland |     731200 |
    |  6 | Rotterdam      | NLD         | Zuid-Holland  |     593321 |
    |  7 | Haag           | NLD         | Zuid-Holland  |     440900 |
    |  8 | Utrecht        | NLD         | Utrecht       |     234323 |
    |  9 | Eindhoven      | NLD         | Noord-Brabant |     201843 |
    | 10 | Tilburg        | NLD         | Noord-Brabant |     193238 |
    +----+----------------+-------------+---------------+------------+
    10 rows in set (0.00 sec)
    

    MySQL 中的TEMPORARY TABLES 是基于会话的,您无法从另一个会话访问它们。您是从其他会话访问表吗?您需要在同一个会话中访问它们。

    【讨论】:

    • 你使用的是哪个工具
    • 没有工具,我只是在Linux机器上的MySQL prompt上做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2022-10-15
    • 1970-01-01
    • 2021-03-05
    相关资源
    最近更新 更多