创建mysql数据库inno setup返回错误代码1

时间:2016-09-03 07:31:51

标签: mysql installation inno-setup

我使用下面的脚本在我的应用程序中安装mysql,但它始终无法创建数据库并加载数据库脚本。调试器返回错误代码1,我找不到关于任何地方失败原因的任何其他消息

当我检查事件查看器时,它看到服务已成功创建并启动,这是真的,但我不明白为什么没有创建数据库。

[Run]
;------------------install service MySQL --------------------------------
;Filename: "{app}\mysql\bin\mysqld.exe"; Parameters: "--install"; WorkingDir: "{app}\mysql\bin";  StatusMsg: "Installing the MySQL";  Description: "Installing MySQL";  Flags: runhidden; Check: MySQL_Is;
Filename: msiexec; Parameters: "/i ""{app}\mysql-5.5.11-win32.msi"" /qn INSTALLDIR=""{app}\mysql"" DATADIR=""{app}\mysql\data"" "; WorkingDir:{app}; StatusMsg: Please wait while we install;  Flags: runhidden

;---------------------CONFIGURING ----------------------------
Filename: {app}\mysql\bin\MySQLInstanceConfig.exe; Parameters:"-i -q ""-l{app}\mysql\mysql_install_log.txt"" ""-nMySQL Server 5.5"" ""-p{app}\mysql"" -v5.5.23 ""-t{app}\mysql\my-template.ini"" ""-c{app}\mysql\mysql.ini"" ServerType=SERVER DatabaseType=MIXED Port=3311 StrictMode=yes ConnectionCount=15 Charset=utf8 ServiceName=MySQL55 AddBinToPath=yes RootPassword=root4u SkipNetworking=no"; WorkingDir: {app}; StatusMsg: Configuring MySQL services; Description: Configuring MySQL Service; Flags: runhidden  


;--------------------- load Database script

;Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-u root -proot4u -h localhost -e ""source {app}\items_db.sql"""; WorkingDir: {app}; StatusMsg: Loading Database Initial Data; Flags: runhidden waituntilterminated;

Filename: {app}\{#AppExeName}; Description: {cm:LaunchProgram,{#AppName}}; Flags: nowait postinstall skipifsilent

[UninstallRun]
Filename: {sys}\net.exe; Parameters: "stop ""MySQL55"""; StatusMsg: "Stopping MySQL Service ..."; Flags: runhidden;
Filename: "{app}\mysql\bin\mysqld.exe"; Parameters: "remove ""MySQL55"""; StatusMsg: "Deleting MySQL Service  ..."; Flags: runhidden;
Filename: msiexec; Parameters: "/x ""{app}\mysql-5.5.11-win32.msi"" ";

=========================数据库脚本==============

/* Tables */
DROP TABLE IF EXISTS clothes;

CREATE TABLE clothes (
  id    int AUTO_INCREMENT NOT NULL,
  name  varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci,
  PRIMARY KEY (id)
) ENGINE = MyISAM;

Insert Into clothes (Id,Name) values (1,"Shirt");

1 个答案:

答案 0 :(得分:0)

因此,经过数小时的调试和搜索网络后,我发现了一种奇怪的行为

从文件中的sql语句执行时,mysql不允许源路径参数中的反冲。

;Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-u root -proot4u -h localhost -e ""source {app}\items_db.sql"""; WorkingDir: {app}; StatusMsg: Loading Database Initial Data; Flags: runhidden waituntilterminated;

所以我开始寻找解决方法

;Filename: "{app}\mysql\bin\mysql.exe"; Parameters: "-u root -proot4u -h localhost -e ""source {app}\{code:GetScriptData}"""; WorkingDir: {app}; StatusMsg: Loading Database Initial Data; Flags: runhidden waituntilterminated;

并在代码部分

[Code]
function GetScriptData(Value: string): string;
begin
  Result := ExpandConstant('{app}') +'/items_db.sql';
  StringChangeEx(Result, '\', '/', True);
end;