YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#define USAGETEXT \ "mysql_install_db.exe Ver 1.00 for Windows\n" \ "Copyright (C) 2010-2011 Monty Program Ab & Vladislav Vaintroub\n" \ "This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n" \ "and you are welcome to modify and redistribute it under the GPL v2 license\n" \ "Usage: mysql_install_db.exe [OPTIONS]\n" \ "OPTIONS:"
if ((error= handle_options(&argc, &argv, my_long_options, get_one_option))) exit(error);
if (opt_config != 0 && _access(opt_config, 04) != 0)
{ int err= errno; switch(err)
{ case EACCES:
die("File %s can't be read", opt_config); break; case ENOENT:
die("File %s does not exist", opt_config); break; default:
die("Can't access file %s, errno %d",opt_config, err); break;
}
} if (opt_config)
{
DWORD dwret = GetFullPathName(opt_config, sizeof(full_config_path), full_config_path, NULL); if (dwret == 0)
{
die("GetFullPathName failed, last error %u", GetLastError());
} elseif (dwret > sizeof(full_config_path))
{
die("Can't resolve the config file name, path too large");
}
opt_config= full_config_path;
}
if(opt_datadir)
datadir = opt_datadir;
if (!datadir && opt_config)
{ for(auto section : {"server","mysqld"})
{ auto ret = GetPrivateProfileStringA(section,"datadir", NULL, default_datadir, sizeof(default_datadir)-1, opt_config); if (ret)
{
datadir= default_datadir;
printf("Data directory (from config file) is %s\n",datadir); break;
}
}
}
if (!datadir)
{ /* Figureoutdefaultdatadirectory.It"data"directory,nextto"bin"directory,where mysql_install_db.exeresides.
*/
safe_strcpy(default_datadir, sizeof(default_datadir), self_name);
p = strrchr(default_datadir, FN_LIBCHAR); if (p)
{
*p= 0;
p= strrchr(default_datadir, FN_LIBCHAR); if (p)
*p= 0;
} if (!p)
{
die("--datadir option not provided, and default datadir not found");
my_print_help(my_long_options);
}
strcat_s(default_datadir, "\\data");
datadir= default_datadir;
printf("Default data directory is %s\n",datadir);
}
DBUG_ASSERT(datadir);
/* Workaround WiX bug (strip possible quote character at the end of path) */
size_t len= strlen(datadir); if (len > 0)
{ if (datadir[len-1] == '"')
{
datadir[len-1]= 0;
} if (datadir[0] == '"')
{
datadir++;
}
}
GetFullPathName(datadir, FN_REFLEN, datadir_buffer, NULL);
datadir= datadir_buffer;
if (create_db_instance(datadir))
{
die("database creation failed");
}
printf("Creation of the database was successful\n"); return0;
}
char path_buf[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path_buf);
snprintf(my_ini_path,sizeof(my_ini_path), "%s\\my.ini", path_buf); if (opt_config)
{ if (!CopyFile(opt_config, my_ini_path,TRUE))
{
die("Can't copy %s to my.ini , last error %lu", opt_config, GetLastError());
}
}
/* Write out server settings. */
convert_slashes(path_buf,'/');
write_myini_str("datadir",path_buf);
if (opt_skip_networking)
{
write_myini_str("skip-networking","ON"); if (!opt_socket)
opt_socket= opt_service;
}
enable_named_pipe= (my_bool)
((opt_socket && opt_socket[0]) || opt_skip_networking);
if (enable_named_pipe)
{
write_myini_str("named-pipe","ON");
}
if (opt_socket && opt_socket[0])
{
write_myini_str("socket", opt_socket);
} if (opt_port)
{
write_myini_int("port", opt_port);
} if (opt_innodb_page_size != DEFAULT_INNODB_PAGE_SIZE)
{
write_myini_int("innodb-page-size", opt_innodb_page_size);
} if (opt_large_pages)
{
write_myini_str("large-pages","ON");
}
/* Write out client settings. */
/* Used for named pipes */ if (opt_socket && opt_socket[0])
write_myini_str("socket",opt_socket,"client"); if (opt_skip_networking)
write_myini_str("protocol", "pipe", "client"); elseif (opt_port)
write_myini_int("port",opt_port,"client");
static constexpr char remove_default_user_cmd[]= "DELETE FROM mysql.user where User='';\n"; static constexpr char allow_remote_root_access_cmd[]= "CREATE TEMPORARY TABLE tmp_user LIKE global_priv;\n" "INSERT INTO tmp_user SELECT * from global_priv where user='root' " " AND host='localhost';\n" "UPDATE tmp_user SET host='%';\n" "INSERT INTO global_priv SELECT * FROM tmp_user;\n" "DROP TABLE tmp_user;\n"; staticconstchar end_of_script[]="-- end.";
/* Get a handle to the SCM database. */
sc_manager= OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!sc_manager)
{
die("OpenSCManager failed (%u)\n", GetLastError());
}
SHFILEOPSTRUCT fileop;
fileop.hwnd= NULL; /* no status display */
fileop.wFunc= FO_DELETE; /* delete operation */
fileop.pFrom= dir2; /* source file name as double null terminated string */
fileop.pTo= NULL; /* no destination needed */
fileop.fFlags= FOF_NOCONFIRMATION|FOF_SILENT; /* do not prompt the user */
/* Create datadir and datadir/mysql, if they do not already exist. */
if (CreateDirectory(datadir, NULL))
{
created_datadir= true;
} elseif (GetLastError() != ERROR_ALREADY_EXISTS)
{
last_error = GetLastError(); switch(last_error)
{ case ERROR_ACCESS_DENIED:
die("Can't create data directory '%s' (access denied)\n",
datadir); break; case ERROR_PATH_NOT_FOUND:
die("Can't create data directory '%s' " "(one or more intermediate directories do not exist)\n",
datadir); break; default:
die("Can't create data directory '%s', last error %u\n",
datadir, last_error); break;
}
}
if (!SetCurrentDirectory(datadir))
{
last_error = GetLastError(); switch (last_error)
{ case ERROR_DIRECTORY:
die("Can't set current directory to '%s', the path is not a valid directory \n",
datadir); break; default:
die("Can' set current directory to '%s', last error %u\n",
datadir, last_error); break;
}
}
if (!PathIsDirectoryEmpty(datadir))
{
fprintf(stderr, "ERROR : Data directory %s is not empty." " Only new or empty existing directories are accepted for --datadir\n", datadir); exit(1);
}
std::string service_user; /* Register service if requested. */ if (opt_service && opt_service[0])
{ /* Run service under virtual account NT SERVICE\service_name.*/
service_user.append("NT SERVICE\\").append(opt_service);
ret = register_service(datadir, service_user.c_str(), NULL); if (ret) goto end;
service_created = true;
}
set_permissions(datadir, service_user.c_str());
if (opt_large_pages)
{
handle_user_privileges(service_user.c_str(), L"SeLockMemoryPrivilege", true);
}
if (setvbuf(in, NULL, _IONBF, 0))
{
verbose("WARNING: Can't disable buffering on mysqld's stdin");
} staticconstchar *pre_bootstrap_sql[] = { "create database mysql;\n","use mysql;\n"}; for (auto cmd : pre_bootstrap_sql)
{ /* Write the bootstrap script to stdin. */ if (fwrite(cmd, strlen(cmd), 1, in) != 1)
{
verbose("ERROR: Can't write to mysqld's stdin");
ret= 1; goto end;
}
}
for (int i= 0; mysql_bootstrap_sql[i]; i++)
{ auto cmd = mysql_bootstrap_sql[i]; /* Write the bootstrap script to stdin. */ if (fwrite(cmd, strlen(cmd), 1, in) != 1)
{
verbose("ERROR: Can't write to mysqld's stdin");
ret= 1; goto end;
}
}
/* Remove default user, if requested. */ if (!opt_default_user)
{
verbose("Removing default user",remove_default_user_cmd);
fputs(remove_default_user_cmd, in);
fflush(in);
}
if (opt_allow_remote_root_access)
{
verbose("Allowing remote access for user root",remove_default_user_cmd);
fputs(allow_remote_root_access_cmd,in);
fflush(in);
}
/* Check if bootstrap has completed successfully. */
ret= pclose(in); if (ret)
{
verbose("mysqld returned error %d in pclose",ret); goto end;
}
end: if (!ret) return ret;
/* Cleanup after error.*/ if (created_datadir)
{
SetCurrentDirectory(cwd);
clean_directory(datadir);
}
if (service_created)
{ auto sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (sc_manager)
{ auto sc_handle= OpenService(sc_manager,opt_service, DELETE); if (sc_handle)
{
DeleteService(sc_handle);
CloseServiceHandle(sc_handle);
}
CloseServiceHandle(sc_manager);
}
/*Remove all service user privileges for the user.*/ if(strncmp(service_user.c_str(), "NT SERVICE\\", sizeof("NT SERVICE\\")-1))
{
handle_user_privileges(service_user.c_str(), 0, false);
} if (created_datadir)
RemoveDirectory(opt_datadir);
} return ret;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.