Hi, there's a problem exporting a database to another one. Using Mysql 8.0 and Heidi 10.2.0
Views get error when exporting "SQL Error 1347: xxxx is not VIEW "
They have been created as tables.
Views have not been exported as "Views"
Image 1
Image 2
Image 3
Problem is in MySQL 8, the changed behaviour of DROP VIEW xyz
. The new behaviour is described here: https://dev.mysql.com/doc/refman/8.0/en/drop-view.html
Though the docs say clearly when using DROP VIEW IF EXISTS xyz
, then just a note returns, not an error. HeidiSQL fires the query due to the checked left checkbox (Drop tables), and fires it with the IF EXISTS
clause, which should avoid the error. Obviously, it still returns with an error if xyz
exists as a table. I am unsure if that's a bug in MySQL or if that's intentionally. The docs are incomplete however, and I have no idea for a workaround.
I believe the root of this issue is not the DROP VIEW IF EXISTS xyz
, but that HeidiSQL is creating the views as tables when moving things from one DB to another.
I attempted to do this on a totally empty DB and HeidiSQL created the views as tables which in turn caused this issue.
A possible solution would be to do the same thing mysqldump does to solve this:
--
-- Temporary view structure for view `xyz`
--
DROP TABLE IF EXISTS `xyz`;
/*!50001 DROP VIEW IF EXISTS `xyz`*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW `xyz` AS SELECT
1 AS `x`,
1 AS `y`,
1 AS `z`*/;
SET character_set_client = @saved_cs_client;
-- Rest of the dump...
--
-- Final view structure for view `xyz`
--
/*!50001 DROP VIEW IF EXISTS `xyz`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`john.doe`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `xyz` AS SELECT x, y, z FROM tbl */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
Most helpful comment
I believe the root of this issue is not the
DROP VIEW IF EXISTS xyz
, but that HeidiSQL is creating the views as tables when moving things from one DB to another.I attempted to do this on a totally empty DB and HeidiSQL created the views as tables which in turn caused this issue.