vbscript - 在没有外部工具的情况下从 mysqldump 中排除数据库

标签 vbscript batch-file mysql

作为主题,我想知道是否可以在 Windows 下使用 mysqldump 排除某些数据库。 我已经用谷歌搜索并找到了这个:

http://datacharmer.blogspot.com/2010/12/excluding-databases-from-mysqldump.html

但我正在寻找不需要外部工具(如 powershell、gnuwin32 等)的 Windows 下的解决方案。谢谢。

最佳答案

这是我的最终剧本。它显然需要 odbc 驱动程序。

set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
Set oShell = WScript.CreateObject("WScript.Shell")
user = "my_user"
password = "my_password"
mysqlPath = "C:\mysql_path\bin\mysqldump.exe"
bkDate = DatePart("yyyy",Date) _
         & Right("0" & DatePart("m",Date), 2) _
         & Right("0" & DatePart("d",Date), 2)
dumpPath = "c:\my_path\dump_" & bkDate & ".txt"
strDbList = ""
cn.connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;User="&user&";Password="&password&";"
cn.open
rs.open "select schema_name from information_schema.schemata where schema_name not in('db1','db2','.....') order by schema_name", cn, 3
rs.MoveFirst
while not rs.eof
    strDbList = strDbList & rs(0) & " "
    rs.movenext
wend
oshell.run "cmd /k " & mysqlPath & " -u" & user & " -p" & password & " --database " & strDbList & "> " & chr(34) & dumpPath & chr(34),0    
cn.close
set oShell = nothing                                                          
set rs = nothing

希望对其他人有所帮助。

关于vbscript - 在没有外部工具的情况下从 mysqldump 中排除数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5331584/

相关文章:

Mysql 将现有列添加到另一个表

google-chrome - 如何使用 UFT 自动化 Chrome 扩展

java - 无法通过bat文件运行java

windows - 如何在命令提示符下查看我的 SYSTEM 环境变量?

php - 清理 PHP 变量,我是否过度使用了它?

PHP计算二叉树中的下线数

windows - 在目录中搜索字符串

windows - 如何使用 BATCH 或 VBS 创建永久系统变量?

vbscript - "Not enough storage is available to complete this operation"对 zip 文件进行 base64 编码时

windows - 循环/D 标志的批处理文件未出现在命令行中