2012-01-12 215 views
3

我已經搜索了幾個小時,有很多帖子或教程,但我無法運行我的批處理腳本。通過批處理腳本運行mysql腳本

在DOS提示符下此代碼工作正常:

-u root -h localhost -p******** siir_07 dumper.sql 

但是這給錯誤與批處理:

"c:\program files\mysql\mysql server 5.5\bin\mysql.exe" "-u root -h localhost -p******** siir_07 dumper.sql" 

的錯誤是:

ERROR 1045(28000):訪問拒絕用戶'root -h localhost -p * * siir_07 dumper.s'@'localhost」(使用密碼:NO)

回答

4

Z:\ test.bat的:

Z:\webserver\mysql\bin\mysql.exe -u test -p test < test.sql 

當我從命令行中運行它,一切沒問題。因此,請嘗試使用<刪除引號和重定向輸入。

+0

感謝您的回答。它現在效果很好 – nikel 2012-01-12 08:03:24

0

它認爲這是你的用戶名

' root -h localhost -p** siir_07 dumper.s' 

試圖改變周圍的報價在你的批處理腳本

+0

感謝您的回覆。它只輸出mysql幫助文本。在我進行反覆試驗時,我曾看到過這一點。 – nikel 2012-01-12 06:52:43

1

你應該使用<文件重定向輸入,刪除多餘的空格:

mysql -uroot -p*** < dumper.sql 

我也建議把用戶名密碼,以及最probabry字符集參數在一個單獨的INI文件,並使用它,如下所示:

mysql --defaults-extra-file=myconf.ini < dumper.sql 
+0

感謝您的回覆。我通過刪除最後兩個引號來修復它。 – nikel 2012-01-12 08:02:43

2

您也可以使用源代碼來執行sql腳本 例如

mysql -u%DBUSERNAME% -p%USERPASSWD% -D%DBNAME% -e "source something.sql;" 
0

該解決方案爲我工作:

mysql -u my_username -D my_database -p < test.sql 

這之後,我得到了一個提示輸入我的密碼,我沒有和一切正常。