Description:
mysqldump produces a faulty script when dealing with a view containing an empty column
name.
Empty column names are allowed in a view (see Bug#27695) but not in a table.
Creating a view with an empty column name works fine, until you try to dump it with
mysqldump and load the script it produced.
mysql> create table t1 (id int);
Query OK, 0 rows affected (0.03 sec)
mysql> create view v1 as select id as '' from t1;
Query OK, 0 rows affected (0.00 sec)
$ mysqldump test > t.sql
$ mysql test < t.sql
ERROR 1051 (42S02): Unknown table 'v2'
How to repeat:
use test;
create table t1 (id int);
create view v1 as select id as '' from t1;
####
mysqldump test > t.sql
mysql test < t.sql
Suggested fix:
The reason for the failure is that mysqldump creates an intermediate table, which is
immediately dropped. The usefulness of this intermediate step is not immediately visible.
This step could be skipped or made more fault tolerant.
--
-- Temporary table structure for view `v1`
--
DROP TABLE IF EXISTS `v1`;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 CREATE TABLE `v1` (
`` int(11)
) */;
--
-- Final view structure for view `v1`
--
/*!50001 DROP TABLE `v2`*/;
/*!50001 DROP VIEW IF EXISTS `v1`*/;