MySQLDump from executable on Windows 7

主宰稳场 提交于 2019-12-23 05:42:10

问题


I tried to dump a mysql database with calling a wsh jscript file, but it doesn't work.

I have this code, called with git shell, and it works perfectly:

# If something fails, exit with status other than 0
set -e

# select dump directory
cd "$(git rev-parse --show-toplevel)"

# first, remove our original schema
rm -f "WebShop\DataBase\backup.sql"

# generate a new schema
exec "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop\DataBase\backup.sql"

I tried almost the same code in WSH, but it returns only with the header of the dump file, and doesn't creates the file. I do not have a clue what is working wrong, or how to debug the code... :S

var shellObj = WScript.CreateObject('WScript.Shell');
var exec = shellObj.Exec(
    '"C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump.exe"'+
    " --skip-comments -u root --password=root webshopdb |sed 's$),($),\\n($g' > " + 
    '"D:\\creation\\software developer\\projects\\webshop-refactoring-project\\document root\\WebShop\\DataBase\\backup.sql"'
);
WScript.Echo(exec.StdOut.ReadAll());

I tried with bat files and cmd files too, but they cannot handle the space in the pathes.

Can anybody help?

(For me it would be enough to make somehow an executable from the git code, or make the wsh work... The perfect solution would be if I could call the dump from netbeans, but in life nothing is so ideal... :D )


回答1:


I made it with file association.

I created a git.bat file:

if not exist %1 exit
set bash=C:\Program Files (x86)\Git\bin\bash.exe
"%bash%" --login -i -c "exec "%1""

And associated it to .hook files.

After that I created a test dump.hook file:

#!/bin/sh
cd "D:/creation/software developer/projects/webshop-refactoring-project/document root/WebShop";
cd "$(git rev-parse --show-toplevel)"
rm -f "WebShop/DataBase/backup.sql"
exec "C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop/DataBase/backup.sql"
exit

And it works perfectly.

After 3 days I got it! Woohoo! :D

note: *Windows command prompt usually has problems with whitespace and special characters in the path name, so it is much easier to use the emulated linux of git, than try to fix it. It is possible to source the .hook file into a pre-commit git hook too, so it can automatically dump the database schema by every commit... (maybe the git add not working by those files, I haven't found an auto dump and commit solution yet: git pre-commit + mysqldump: cannot find path, not existing command) *



来源:https://stackoverflow.com/questions/9254186/mysqldump-from-executable-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!