@echo off
If not Defined MYSQL_HOME (
set "error_msg=MYSQL_HOME 变量不存在,请先设置MYSQL_HOME环境变量"
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 创建mysql配置文件成功
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 安装mysql服务成功
goto :eof