使用mysqldump忽略mysql db backup中的'views'

[英]Ignore 'views' in mysql db backup using mysqldump


I need to ignore all view in my database and take backup using mysqldump. Currently i am using below option.

我需要忽略数据库中的所有视图并使用mysqldump进行备份。目前我正在使用以下选项。

--ignore-table=view1 --ignore-table=view2 --ignore-table=view3

Is there any way to take backup omitting all views without specifying all 'view' names.?

有没有办法在不指定所有“视图”名称的情况下省略所有视图的备份。

3 个解决方案

#1


5  

Try this query:

试试这个查询:

SELECT CONCAT('mysqldump -u username -ppassword -h host [some options here] `',`TABLE_SCHEMA`,'` `',
`TABLE_NAME`,'` > ',`TABLE_NAME`,'.sql') AS `sql` 
FROM `INFORMATION_SCHEMA`.`TABLES` 
WHERE `TABLE_TYPE` != 'VIEW'
AND `TABLE_SCHEMA` NOT IN ('INFORMATION_SCHEMA', 'PERFORMANCE_SCHEMA','mysql');

#2


5  

Usage

用法

php mysqldump.php mydatabase myusername mypassword > myoutputfile.sql

This is a pretty old script of mine. Someone could easily adapt this to use PDO if you do not have access to the mysql functions.

这是我的一个非常古老的剧本。如果您无法访问mysql函数,则有人可以轻松地将其调整为使用PDO。

<?php

if (is_array($argv) && count($argv)>3) {
    $database=$argv[1];
    $user=$argv[2];
    $password=$argv[3];
}
else {
    echo "Usage php mysqdump.php <database> <user> <password>\n";
    exit;
}

$link = mysql_connect('localhost', $user, $password);


if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$source = mysql_select_db('$database', $link);
$sql = "SHOW FULL TABLES IN `$database` WHERE TABLE_TYPE LIKE 'VIEW';";
$result = mysql_query($sql);
$views=array();
while ($row = mysql_fetch_row($result)) {
   $views[]="--ignore-table={$database}.".$row[0];
}
    //no views or triggers please
system("mysqldump -u root --password=\"$password\" $database --skip-triggers ".implode(" ",$views));

?>

#3


5  

If the MySQL user you're using doesn't have access to read Views, then just putting an -f flag on the mysqldump command will skip them. Unfortunately, it prints a warning which might be annoying, but it will otherwise complete the dump.

如果您正在使用的MySQL用户无权读取视图,那么只需在mysqldump命令上放置-f标志就会跳过它们。不幸的是,它打印出一个可能令人讨厌的警告,否则它将完成转储。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2011/12/15/18638cf87cfcdd1f1b5ad4cfdcbdc52f.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号