[英]running mysql scripts from windows 7 batch files
Can someone show me how to successfully run the batch file below from the windows cmd command prompt? 有人可以告诉我如何从Windows cmd命令提示符下成功运行下面的批处理文件? I need to perform operations on a MySQL database installed in my computer.
我需要在我的计算机上安装的MySQL数据库上执行操作。 Here is the batch file:
这是批处理文件:
::
:: Database connection parameters
:: Please edit these variables to reflect your environment
::
set MYSQL_HOME="C:\pathto\MySQL\MySQL Server 5.6\bin\mysqld"
set user=root
set password=mypassword
set host_name=localhost
set db_name=mydatabase
set max_error_count=0
ATTRIB +R %logfile%
echo ----------------------------------------echo Starting ...
echo ----------------------------------------
echo. %MYSQL_HOME%\bin\mysql -u %user% -p%password% -h%host_name% --local-infile=1 %db_name% < Table_scripts_mysql_rxn.sql >> mysql.log 2>&1
%MYSQL_HOME%\bin\mysql -u %user% -p%password% -h%host_name% --local-infile=1 %db_name% < Load_scripts_mysql_rxn_win.sql >> mysql.log 2>&1
echo
echo ----------------------------------------
echo Finished
echo ----------------------------------------
But I am getting access denied messages, as indicated by the following history from the command line: 但是我收到了拒绝访问的消息,如命令行中的以下历史记录所示:
C:\mypath>Populate_mysql_rxn
C:\mypath>set MYSQL_HOME="C:\mypath\MySQL\MySQL Server 5.6"
C:\mypath>set user=root
C:\mypath>set password=mypassword
C:\mypath>set host_name=localhost
C:\mypath>set db_name=mydatabase
C:\mypath>set max_error_count=0
C:\mypath>ATTRIB +R
C:\mypath>echo ----------------------------------------echo Starting ...
----------------------------------------echo Starting ...
C:\mypath>echo ----------------------------------------
----------------------------------------
C:\mypath>echo.
C:\mypath>"C:\mypath\MySQL\MySQL Server 5.6"\bin\mysql -u root -pmypassword
-hlocalhost --local-infile=1 mydatabase 0<Table_scripts_mysql_rxn.sql 1>>mysql.log 2>&1
Access is denied.
C:\mypath>"C:\mypath\MySQL\MySQL Server 5.6"\bin\mysql -u root -pmypassword
-hlocalhost --local-infile=1 mydatabase 0<Load_scripts_mysql_rxn_win.sql 1>>mysql.log 2>&1
Access is denied.
C:\mypath>echo
ECHO is on.
C:\mypath>echo ----------------------------------------
----------------------------------------
C:\mypath>echo Finished
Finished
C:\mypath>echo ----------------------------------------
----------------------------------------
C:\mypath>
You have a few errors in that file... looks like a corrupt copy&paste example. 您在该文件中有一些错误...看起来像一个损坏的复制和粘贴示例。
First.. I recommend to start the Populate_mysql_rxn2.bat
file with: 首先..我建议使用以下命令启动
Populate_mysql_rxn2.bat
文件:
@echo off
setlocal EnableDelayedExpansion
Then, your address var end's up with: ...\\bin\\mysqld
and when you call the var, you add %MYSQL_HOME%\\bin\\mysql
That give you the first error... 然后,你的地址var结束了:
...\\bin\\mysqld
,当你调用var时,你添加%MYSQL_HOME%\\bin\\mysql
这给你第一个错误......
The consecutive errors is not recognized as an internal or external command
are for the reason already gave.. 由于已经给出的原因,连续错误
is not recognized as an internal or external command
。
you could concatenate if you don't now how to do it in multiple lines ie 你可以连接,如果你现在不怎么做多行,即
set user=root && set password=mypassword && set allthis=sameline
finally.. the Access is denied.
最后..
Access is denied.
is obvius... mysql
address is wrong, and the connection var are not properly set... plus : 是obvius ...
mysql
地址是错误的,连接var没有正确设置... 加 :
... -p%password% -h%host_name% ...
must be: 一定是:
... -p %password% -h %host_name% ...
Now.. for the edition problems you have.. try to start a completly new file
and write yourself the code, don't copy & paste... many web sites have symbols that are copied and may corrupt your file. 现在..对于您的版本问题..尝试启动一个完整的
completly new file
并自己编写代码,不要复制和粘贴...许多网站都有复制的符号,可能会损坏您的文件。 (your code is fully spaced) (你的代码是完全间隔的)
Note: I din't check your code actually work.. just see and try to correct some visible mistakes in your example code 注意:我不会检查你的代码实际工作..只是看看并尝试纠正示例代码中的一些可见错误
Have to end up with something like: 必须得到类似的东西:
@echo off
setlocal EnableDelayedExpansion
set MYSQL_HOME="C:\pathto\MySQL\MySQL Server 5.6\bin\mysql"
set user=root
set password=mypassword
set host_name=localhost
set db_name=mydatabase
set max_error_count=0
ATTRIB +R %logfile%
echo ----------------------------------------
echo Starting
echo ----------------------------------------
%MYSQL_HOME% -u %user% -p %password% -h %host_name% --local-infile=1 %db_name% < Table_scripts_mysql_rxn.sql >> mysql.log 2>&1
%MYSQL_HOME% -u %user% -p %password% -h %host_name% --local-infile=1 %db_name% < Load_scripts_mysql_rxn_win.sql >> mysql.log 2>&1
echo ----------------------------------------
echo Finished
echo ----------------------------------------
If you are running mysql under Windows and have some special characters in the file that cause problems, you can do this:
如果您在Windows下运行mysql并在文件中有一些导致问题的特殊字符,您可以这样做:
C:> mysql -e "source batch-file"
C:> mysql -e“source batch-file”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.