HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to prevent MariaDB mysqldump from prepending database name in CREATE VIEW?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
preventcreatemysqldumpviewprependingdatabasenamehowfrommariadb

Problem

I am having the exact same problem as this person here: How can I prevent mysqldump from prepending the database name in CREATE VIEW?

I am using MariaDB 10.4.7 x64 on Windows. For just ONE of my views, whenever I run mysqldump, it always prepends the database name to each table. I have tried dropping and recreating the view to no avail. This is what the result from mysqldump looks like.

CREATE
    /*[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
    [DEFINER = { user | CURRENT_USER }]
    [SQL SECURITY { DEFINER | INVOKER }]*/
    VIEW `view_x` 
    AS
(
SELECT * FROM
databasename.table1
LEFT JOIN databasename.table2 ON databasename.table2.id = databasename.table1.id
...
);


This is causing an issue when I import the database into a test server using a different database name because the previous database name is hard coded into the view.

Has anyone ever experienced this? I'm afraid my googlefu has failed me.

EDIT: After looking at all of my views, this particular view (and the only view) uses derived tables in the FROM clause. After removing these derived queries and all traces from the SELECT statement and recreating the view, the database name was no longer being prepended to the tables. So...I don't know if this is a bug or expected behavior. I think I will file a bug report.

Solution

Future visitors, follow to the jira ticket on https://jira.mariadb.org/browse/MDEV-22282

It seems to have been fixed on Versions 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4

Another workaround - also seen on that jira ticket - is to monckeypatch the SQL dump. Just to exemplify:
mysqldump --no-data DATABASE_NAME \
| sed "s/\
DATABASE_NAME\\.//g" > DATABASE_NAME.sql

Context

StackExchange Database Administrators Q#265209, answer score: 2

Revisions (0)

No revisions yet.