作为主题,我想知道是否可以使用mysqldump排除Windows下的某些数据库。 我已经google了,我发现了这个:
http://datacharmer.blogspot.com/2010/12/excluding-databases-from-mysqldump.html
但我正在寻找一个不需要外部工具的Windows下的解决方案,如powershell,gnuwin32等。谢谢。
答案 0 :(得分:3)
这是我的最终剧本。它显然需要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
希望它可以帮助别人。
答案 1 :(得分:1)
您可以轻松编写一小段代码,以您选择的语言进行正确的输出选择。