Windows 7 上可执行文件的 MySQLDump
我尝试通过调用 wsh jscript 文件来转储 mysql 数据库,但它不起作用。
我有这段代码,用 git shell 调用,它工作得很好:
# 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"
我在 WSH 中尝试了几乎相同的代码,但它仅返回转储文件的标头,并且不创建文件。我不知道出了什么问题,也不知道如何调试代码... :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());
我也尝试过使用bat文件和cmd文件,但它们无法处理路径中的空间。
有人可以帮忙吗?
(对我来说,从 git 代码中创建一个可执行文件就足够了,或者让 wsh 工作......完美的解决方案是如果我可以从 netbeans 调用转储,但在生活中没有什么是那么理想......: D)
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 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是用文件关联做到的。
我创建了一个 git.bat 文件:
并将其关联到 .hook 文件。
之后我创建了一个测试 dump.hook 文件:
并且它运行良好。
3天后我收到了!呜呼! :D
注意:*Windows 命令提示符通常会出现路径名中空格和特殊字符的问题,因此使用 git 模拟的 linux 比尝试修复它要容易得多。也可以将 .hook 文件源到预提交 git hook 中,这样它就可以在每次提交时自动转储数据库模式...(也许 git add 不适用于这些文件,我还没有找到自动转储并提交解决方案: git 预提交 + mysqldump:找不到路径,不存在命令)*
I made it with file association.
I created a git.bat file:
And associated it to .hook files.
After that I created a test dump.hook file:
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) *