开发者

excluding databases from mysqldump under windows without external tools

开发者 https://www.devze.com 2023-02-17 19:28 出处:网络
As subject I\'d like to know if it\'s possible to use mysqldump excluding some databases under windows.

As subject I'd like to know if it's possible to use mysqldump excluding some databases under windows. I've already googled and I've found this:

http://datacharmer.blogspot.com/2010/12/ex开发者_如何学编程cluding-databases-from-mysqldump.html

but I'm looking for a solution under windows that doesn't require external tool like powershell,gnuwin32 and so on. Thanks.


This is my final script. It obviously requires odbc driver.

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

Hope that it helps someone else.


You could easily write a short piece of code to do the correct output selection in your language of your choice.

0

精彩评论

暂无评论...
验证码 换一张
取 消