First set the environment variable of MYSQL_HOME
Then execute the following batch
@echo off If not Defined MYSQL_HOME ( set "error_msg=MYSQL_HOME variable does not exist, please set MYSQL_HOME environment variable first" goto :error ) call :create_mysql_ini call :install_mysql_server :error echo %error_msg% pause exit :create_mysql_ini set "unit_mysql_home=%MYSQL_HOME::\=:/%" echo "%unit_mysql_home%" set "my_ini_dir=%unit_mysql_home%\my.ini" echo [mysqld] > %my_ini_dir% echo port = 3306 >> %my_ini_dir% echo basedir = %unit_mysql_home% >> %my_ini_dir% echo datadir = %unit_mysql_home%\data >> %my_ini_dir% echo character_set_server = utf8 >> %my_ini_dir% echo max_allowed_packet = 1M >> %my_ini_dir% echo. >> %my_ini_dir% echo [client] >> %my_ini_dir% echo port = 3306 >> %my_ini_dir% echo default-character-set = utf-8 >> %my_ini_dir% echo created mysql configuration file successfully goto:eof :install_mysql_server net stop MySQL echo 1 sc delete MySQL echo 1 mysqld --install MySQL --defaults-file=%my_ini_dir% set "mysql_server_excute_path="%MYSQL_HOME%\bin\mysqld" --defaults-file=%my_ini_dir% MYSQL" echo %mysql_server_excute_path% reg add HKLM\SYSTEM\CurrentControlSet\Services\MySQL /v ImagePath /t REG_EXPAND_SZ /d "%mysql_server_excute_path%" /f echo 1 net start MySQL echo install mysql service successfully goto :eof