gpt4 book ai didi

mysql - 从 Windows 7 批处理文件运行 mysql 脚本

转载 作者:行者123 更新时间:2023-11-29 05:23:57 24 4
gpt4 key购买 nike

有人可以告诉我如何从 Windows cmd 命令提示符成功运行下面的批处理文件吗?我需要对我电脑上安装的MySQL数据库进行操作。这是批处理文件:

::
:: 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 ----------------------------------------

但我收到访问被拒绝的消息,如命令行中的以下历史记录所示:

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>

最佳答案

你在那个文件中有一些错误......看起来像一个损坏的复制和粘贴示例。
首先..我建议使用以下内容启动Populate_mysql_rxn2.bat文件:

@echo off
setlocal EnableDelayedExpansion

然后,您的地址 var 以:...\bin\mysqld 结束,当您调用 var 时,您添加 %MYSQL_HOME%\bin\mysql这给了你第一个错误......

连续的错误 is not recognized as an internal or external command 是因为已经给出的原因..
如果你现在不这样做,你可以连接起来如何在多行中进行即

set user=root && set password=mypassword && set allthis=sameline

最后.. Access is denied. 很明显... mysql 地址错误,连接变量设置不正确... < em>加:

... -p%password% -h%host_name% ...

必须是:

... -p %password% -h %host_name% ...

现在.. 对于您遇到的版本问题.. 尝试启动一个完全新的文件 并自己编写代码,不要复制和粘贴...许多网站都有被复制的符号,可能会损坏您的文件。 (你的代码是全间隔的)

注意:我没有检查您的代码是否确实有效。只是查看并尝试更正示例代码中的一些可见错误

必须以这样的方式结束:

@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:

C:> mysql -e "source batch-file"

来源 -> 3.5 Using mysql in Batch Mode

关于mysql - 从 Windows 7 批处理文件运行 mysql 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22390275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com