Archive: Help w/ mysql script


Help w/ mysql script
Hi,

On a previous thread, there was information about execting a .sql script against mysql. I'm trying this, but having no luck.

I'm running the installer on WindowsME, so I've changed from cmd to command. Also, I've always run mysqld.exe, rather than mysql.exe, so I changed the path to point to that. I confirm that I am executing the statement that I expect to run the script, but basically, nothing happens. Can anyone help? Here's my code:

; unpack the mysql update
SetOutPath "$INSTDIR"
File "schema.sql"

; execute the update against mysql
StrCpy $mySQLEXE "C:\mysql\bin\mysqld.exe"
StrCpy $dbUser "root"
StrCpy $dbPassword "rootpass"
StrCpy $dbHost "localhost"
StrCpy $dbPort "3306"
MessageBox MB_OK "pre exec"
nsExec::ExecToStack 'command /C "$mySQLEXE" -u$dbUser -p$dbPassword -h$dbHost -P$dbPort < "$INSTDIR\schema.sql"'
MessageBox MB_OK "post exec"

Thanks!
Stan


I thought that mysqld.exe is the server and mysql.exe is the client. Running the server isn't going to do anything but start mySQL again. I use mysql.exe because I need a client application to run scripts against a server that is already running.

But if I'm wrong do these two things. First, run it from the command line to ensure it works there. Second, try it without all the variables. What I mean is spell out all those variables such as:

nsExec::ExecToStack 'command /C "C:\mysql\bin\mysqld.exe" -u$root -prootpass -hlocalhost -P3306 < "$INSTDIR\schema.sql"'

Good luck


Hi,

I started out trying to execute mysql.exe, both before and after I had launched mysqld.exe. It makes sense though that it's client and server - I thought mysql.exe was the non-debug version (it's been almost 2 years since I looked at a local install of mysql - it took me 10 minutes to figure out how to shut it down last night :) ).

I'll go try it from the command line and see what happens.

Stan


Working from the command line, I found several issues - one was my user was not set up correctly in mysql, and the schema doc itself needed a fix.

Now, it works fine from the command line, like this:

C:\mysql\bin\>mysql.exe -utheuser -pthepass -hlocalhost -P3306 < C:\INSTEST\schema.sql

However, this doesn't work:

nsExec::ExecToLog 'command /C C:\mysql\bin\mysql.exe -utheuser -pthepass -hlocalhost -P3306 < "$INSTDIR\schema.sql"'

Nor does this:

nsExec::ExecToLog 'command /C C:\mysql\bin\mysql.exe -utheuser -pthepass -hlocalhost -P3306 < $INSTDIR\schema.sql'

$INSTDIR is set to C:\INSTEST.

Does anyone have more suggestions?

Thanks,
Stan


There have been several topics about this subject, please use the search.

< is a feature of the console and not a normal command line syntax.


Hi Joost,

I had read several of the previous posts. I may not have gotten the point, but I did read them :).

I went back and read some more, and here is what I found I needed to do to make it work (on WindowME anyway) - I had to add this line:

ExpandEnvStrings $0 "%COMSPEC%"

to get the actual path to 'command' into $0, and then I quoted that in the statement, like this:

nsExec::ExecToLog '"$0" /C "C:\mysql\bin\mysql.exe" -utheuser -pthepass -hlocalhost -P3306 < "$INSTDIR\schema.sql"'

My question now is, will this form work on all versions of windows?

Thanks for everyone's help.
Stan


Yes, that should work.


Very good.

Thanks again!
Stan


Just a clarification here, for future archive searchers.

This line:

nsExec::ExecToLog '"$0" /C "C:\mysql\bin\mysql.exe" -utheuser -pthepass -hlocalhost -P3306 < "$INSTDIR\schema.sql"'

Did not work on Windows XP. The problem seemed to be quoting the path to the executable. It gave an error of 'The filename, directory name or volume label syntax is incorrect'. The working version would be:

nsExec::ExecToLog '"$0" /C C:\mysql\bin\mysql.exe -utheuser -pthepass -hlocalhost -P3306 < "$INSTDIR\schema.sql"'

Enjoy!
Stan