MySQL install and load database on Inno Setup script

后端 未结 2 1643
一整个雨季
一整个雨季 2020-12-29 11:31

I have been reading through a lot of documents on Stack Overflow, you guys are great! I have taken some code that was suggested on another post. The help was great! I was ab

相关标签:
2条回答
  • 2020-12-29 11:35

    After you installed MySQL and got it started, it´s easy to load an MySQL Script file.

    The keypoint is passing the command "source" to mysql.exe -e parameter, so it could load the script file. Passing script name with "<" signal didn´t work for me.

    [Files]
    Source: "script.sql"; DestDir: "{tmp}"; Flags: deleteafterinstall;
    
    [Run]
    Filename: "{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.6,Location}\bin\mysql.exe"; \
     Parameters: "-u root -prootpassword -e ""source {tmp}\script.sql"""; \
     StatusMsg: "Loading MySQL Database Initial Data"; \
     Flags: runhidden waituntilterminated;
    
    0 讨论(0)
  • 2020-12-29 11:41

    I managed find a workaround to this problem. Instead of loading the database directly from the INNO script, I wrote the sql commands into a batch file and executed the .bat from the script.

    Type this into a notepad document and save it as loadDB.bat . The first line sets the path of your directory to where your mysql.exe is installed. Next line creates an empty database.(I don't know why but I can't get mysql to load the database file without creating an empty database on the server first) The last line is the mysql command for loading the database from your database,sql file.

    cd /d C:\Program Files\MySQL\MySQL Server 5.1\bin

    mysql -uroot -padmin -e "create database mydatabase;"

    mysql -uroot -padmin mydatabase < "C:\database.sql"

    Now, in your INNO script below the [FILES] section add the .bat file

    Source: "path-to-file\loadDB.bat"; DestDir: "{app}"; Flags: ignoreversion

    And below the [RUN] section execute the .bat. Note this line should be the last line in the [RUN] section because it should execute only after Mysql server is installed.

    Filename: "{app}\loadDB.bat"

    Now compile and run the setup.

    As a side note : I havent tried it but maybe if you add the mysql commands in the .bat directly into the inno script with the correct parameters, you could load the database without the need of the batch file.

    Hope this solves your problem.

    0 讨论(0)
提交回复
热议问题