Archive: Issues executing MySQL sql file


Issues executing MySQL sql file
I've got an installer which installs MySQL (and other programs). Part of the installer installs a pre-setup database. If the user installs it on another drive besides C:, I need to modify several paths. I've written a MySQL .sql file to modify the database, but it seems MySQL 5 doesn't properly execute it. Instead, it just displays the default command line page.

Any ideas why?


Section MySQL SecMySQL
SetOutPath $INSTDIR\mysql
SetOverwrite on
File /r C:\mysql\*
;Create shortcuts
SetShellVarContext All
CreateDirectory "$SMPROGRAMS\MySQL\MySQL Server 5.0"
CreateShortcut "$SMPROGRAMS\MySQL\MySQL Server 5.0\MySQL Server Instance Config Wizard.lnk" "$INSTDIR\mysql\bin\MySQLInstanceConfig.exe"
CreateShortcut "$SMPROGRAMS\MySQL\MySQL Server 5.0\MySQL Manual.lnk" "$INSTDIR\mysql\docs\manual.chm"

;Write registry entires
;ommited

SetOutPath $IISDIR\cacti\log
;Install mysql service
ExecDos::exec /TIMEOUT=${EXECTIMEOUT} '"$INSTDIR\mysql\bin\mysqld-nt.exe" --install MySQL --defaults-file="$INSTDIR\MySQL\my.ini' "" "$IISDIR\cacti\log\mysql_service.log"
;Start MySQL service
ExecDos::exec /TIMEOUT=${EXECTIMEOUT} '"net" start MySQL' "" "$IISDIR\cacti\log\net_start_mysql.log"

;Modify file paths if not C:
SetOutPath $TEMP
${If} $INSTDIR != "c:"
;Change forward slashes to backwards
Push $INSTDIR
Push "\"
Call StrSlash
Pop $R0
StrCpy $R9 $R0
Push $IISDIR
Push "\"
Call StrSlash
Pop $R0
StrCpy $R8 $R0
Push $WINDIR
Push "\"
Call StrSlash
Pop $R0
StrCpy $R7 $R0
FileOpen $0 batch.txt w
FileWrite $0 "update settings set name='path_rrdtool', value='$R9/rrdtool/rrdtool.exe' where name='path_rrdtool';$\r$\n"
FileWrite $0 "update settings set name='path_rrdtool_default_font', value='$R7/fonts/VeraMono.ttf' where name='path_rrdtool_default_font';$\r$\n"
FileWrite $0 "update settings set name='path_php_binary', value='$R9/php/php.exe' where name='path_php_binary';$\r$\n"
FileWrite $0 "update settings set name='path_snmpwalk', value='$R9/net-snmp/bin/snmpwalk.exe' where name='path_snmpwalk';$\r$\n"
FileWrite $0 "update settings set name='path_snmpget', value='$R9/net-snmp/bin/snmpget.exe' where name='path_snmpget';$\r$\n"
FileWrite $0 "update settings set name='path_snmpbulkwalk', value='$R9/net-snmp/bin/snmpbulkwalk.exe' where name='path_snmpbulkwalk';$\r$\n"
FileWrite $0 "update settings set name='path_snmpgetnext', value='$R9/net-snmp/bin/snmpgetnext.exe' where name='path_snmpgetnext';$\r$\n"
FileWrite $0 "update settings set name='path_cactilog', value='$R8/cacti/log/cacti.log' where name='path_cactilog';$\r$\n"
FileWrite $0 "update settings set name='path_Spike', value='$R9/Spike/Spike.exe' where name='path_Spike';$\r$\n"
FileWrite $0 "update settings set name='path_webroot', value='$R8/cacti' where name='path_webroot';$\r$\n"
${EndIf}
;Modify rrdtool font path for win2k, since installer path based on XP
${If} $OS == "Windows2000"
;Change forward slashes to backwards
Push $WINDIR
Push "\"
Call StrSlash
Pop $R0
StrCpy $R7 $R0
FileOpen $1 batch.txt a
FileWrite $1 "update settings set name='path_rrdtool_default_font', value='$R7/fonts/VeraMono.ttf' where name='path_rrdtool_default_font';$\r$\n"
FileWrite $1 "exit$\r$\n"
${EndIf}
FileWrite $0 "exit$\r$\n"
FileClose $1
FileClose $0
ExecCmd::exec /TIMEOUT=${EXECTIMEOUT} '$INSTDIR\mysql\bin\mysql.exe --user=root --password=cacti --database=cacti < "$TEMP\batch.txt"' ""
ExecDOS::exec /TIMEOUT=${EXECTIMEOUT} '$INSTDIR\mysql\bin\mysql.exe --user=root --password=cacti --database=cacti < "$TEMP\batch.txt"' "" "$IISDIR\cacti\log\mysql_batch.txt"
Delete /REBOOTOK $TEMP\batch.txt

Hereafter is the way I managed to make it right:

ExecWait '"$1\bin\mysql" --user=$mysql_user --password=$mysql_password --execute="source $0"' $2

with $0 the full path to my file that has been slashified first(you need a '\' => '/' function).