cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
swiftqb
Level 3

Run SQL Script

Hi,

Hopefully this is a simple and quick query but I have been struggling to get this working for a while now. All I need to do is to get a command to run an SQL script against a MySQL database within InstallAnywhere 2011. The command is below:

C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe --user=root --password=root < C:\createqb.sql

I know this is a valid command as it runs nicely using the actual command line.

Any response will be much appreciated.

Thanks in advance

AB
Labels (1)
0 Kudos
(8) Replies
TomCarey
Level 4

Don't know if it is the proper way or not, documentation is terrible for this product. And there is no way to debug it :confused:
But I had some luck doing the following:
(1) Use Modify text file to create a .bat file in the $USER_INSTALL_DIR$ say db.bat
The text in the bat file would be your command - don't forget to put quotes around it since the path has spaces:

Note: this would all be on one line:
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe" --user=root --password=root < C:\createqb.sql

(2) Execute Command with:
cmd /c $USER_INSTALL_DIR$\db.bat

(3) delete the bat file.
0 Kudos
pv7721
Level 20

Or you could use a ready made custom code: http://www.flexerasoftware.com/products/installanywhere/files-utilities.htm
Database Action: http://www.flexerasoftware.com/downloads/customcode/DataBaseCustomCode.zip
DatabaseAction
The custom code action connects to a database, reads SQL from a file, executes the queries, and closes the database.
Posted by: Flexera Software. Source included.
0 Kudos
swiftqb
Level 3

Hi,

Thanks for the replies, I dont want to go down the custom code route and TomCarey, Ive tried your suggestion without success. Surely this should be a simple task. Anyone else?

Thanks again
0 Kudos
Macintosh
Level 5

I am not sure what and how exactly you would like to implement the execution of SQL script in your project.

How I would do is that first I will add the required database in Organization --> Hosts, then configure the database strings and finally in install phase add "Run SQL Script" action to run the required SQL file. That's all.

If you want I can post the sample project to you but I think you can do this by yourself if that is the requirement.

Does it answer your question?

-- Mac
0 Kudos
swiftqb
Level 3

Thanks for your reply.

What makes it more complicated is that the mysql database server is installed as part of the installation script. I looked into your solution but as the database doesnt exist until the end of the install it obviously wont work.
0 Kudos
pv7721
Level 20

In this case maybe you need to run your script in post-install (I've developed a similar setup).
0 Kudos
swiftqb
Level 3

Ive tried adding the action to post install and that doesnt work either.

pv7721 please enlighten me into how you got it to work.

Thanks in advance
0 Kudos
pv7721
Level 20

It might not be easy to debug what happens in your case: it depends both on your setup and your SQL script. You install MySQL all right, but does your setup launch it as well? Have you added something to check the connection?
0 Kudos