Sample Header Ad - 728x90

MariaDB (MySQL) : Cannot create view as already existing after database duplication

0 votes
2 answers
88 views
For some project, I **duplicated an existing MariaDB (MySQL) database** and altered its records to make it a demo dataset. The database duplication was done through phpMyAdmin. The original database and its copy have **views that are used by the project**. After the copy, the views in the duplicated database are unfortunately **pointing to the tables in the original database**, instead of those in its copy. --- Edit: A **solution could be found**, detailed below in this same thread: https://dba.stackexchange.com/a/345283/193688 --- __Description of the problem before the solution was found__ For each view, SHOW CREATE VIEW command returns something like: CREATE ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER VIEW some_view AS SELECT original_database.some_view.column1 AS column1, original_database.some_view.column2 AS column2 from original_database.some_view UNION ALL (...) In the copied database, I could delete each VIEW but **when trying to create again each VIEW** that points to the tables of the copied database, **the following error comes**: #1050 - Table 'some_view' already exists. I tried adding USE copied_database; but this didn't change anything ; it is like the namespace of view names is shared among all databases. USE copied_database; DROP TABLE IF EXISTS some_view; CREATE ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER VIEW some_view AS SELECT copied_database.some_view.column1 AS column1, copied_database.some_view.column2 AS column2 from copied_database.some_view UNION ALL (...) **I need each VIEW keeping the same name in both the original and the copied database**, so that the code still works. What should I do? Version of MariaDB installed on localhost: 10.4.8 Version of phpMyAdmin: 4.9.1
Asked by OuzoPower (141 rep)
Feb 13, 2025, 12:48 PM
Last activity: Mar 1, 2025, 06:13 PM