snippetMinor
mysqldump generates incorrect create view queries
Viewed 0 times
generatesincorrectcreatemysqldumpviewqueries
Problem
I use mysqlpump to backup database:
My DB contains several views, and some of them are exported with totally incorrect SELECTs in the CREATE VIEW queries like this one:
Why is it happening and how can I fix that?
mysqlpump --single-transaction --add-drop-database --skip-definer \
--databases mydatabase --result-file /opt/myservice/backup/export.sqlMy DB contains several views, and some of them are exported with totally incorrect SELECTs in the CREATE VIEW queries like this one:
CREATE VIEW `careerpulse-staging`.`user_view` AS SELECT
1 AS `id`,
1 AS `name`,
1 AS `department`,
1 AS `manager_id`
;Why is it happening and how can I fix that?
Solution
When dumping / pumping MySQL databases, the output script generates this as a temporary structure first, and later below at the end of the script, it drops this and create the actual view itself, something like this:
If you end up with the final view still selecting 1s, it would be probably because database name mismatch, when you use --databases option in the mysqldump , the script will output
in multiple places (not only at the top of the script), and specifically there is one before the DROP and Recreating the actual view.
This happened to me when exporting and importing databases with different name.
...DROP VIEW IF EXISTS myview ... If you end up with the final view still selecting 1s, it would be probably because database name mismatch, when you use --databases option in the mysqldump , the script will output
USE database_namein multiple places (not only at the top of the script), and specifically there is one before the DROP and Recreating the actual view.
This happened to me when exporting and importing databases with different name.
Context
StackExchange Database Administrators Q#210423, answer score: 5
Revisions (0)
No revisions yet.