Bug #44864 | dump only views | ||
---|---|---|---|
Submitted: | 14 May 2009 9:01 | Modified: | 14 May 2009 9:03 |
Reporter: | Susanne Ebrecht | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Command-line Clients | Severity: | S4 (Feature request) |
Version: | 5.0, 5.1, 6.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[14 May 2009 9:01]
Susanne Ebrecht
[19 May 2009 7:39]
Sveta Smirnova
There is bug #44939 which shows a problem with current behavior.
[27 Sep 2022 13:23]
Roland Giesler
(Also me to be a necromancer for a moment :-) ) There is a simple way to do this. Simply specify only the names of the view in the mysqldump comment and then create statements will be in the dump file. For example: mysqldump --user=root --single-transaction --quick DB1 user_view client_view any_view > /mnt/backup/DB1-views.sql will create a dump file that contains the sql to recreate the 3 views mentioned. Maybe someone more proficient and experienced in mysql than me can create a function to create the mysqldump statement by reading the names of the views from the database.
[27 Sep 2022 13:42]
Roland Giesler
Actually, this command will list all the views in a database. mysql -uroot -sNe "SELECT TABLE_NAME,' ' FROM information_schema.tables WHERE TABLE_TYPE LIKE 'VIEW' AND TABLE_SCHEMA = 'DB1';" Use that to construct a mysqldump command.
[27 Sep 2022 14:35]
Roland Giesler
I have created a workaround to achieve this: #!/bin/bash set $var1 = /usr/bin/mysql -uroot -sNe "SELECT TABLE_NAME,' ' FROM information_schema.tables WHERE TABLE_TYPE LIKE 'VIEW' AND TABLE_SCHEMA = 'DB1';" | sed -r 's/\s+//g' | sed -z -e 's/\n/ /g' /usr/bin/mysqldump -uroot --no-data DB1 $var1 > /mnt/backup/DB1-views.sql
[17 Apr 11:36]
Zafar Malik
# We can take backup of only view by below command- mysql -Nse"SET SESSION group_concat_max_len = 100000000; SELECT concat(table_schema,' ',group_concat(table_name order by table_name SEPARATOR ' ')) FROM information_schema.views WHERE TABLE_SCHEMA NOT IN ('mysql','information_schema','performance_schema','sys') group by table_schema order by table_schema" | while read MYVIEW; do echo "use "${MYVIEW} | awk ' { print $1 " "$2";"} ' >> /root/temp/only_view_dump.sql && mysqldump --single-transaction -d ${MYVIEW} >> /root/temp/only_view_dump.sql; done