1. 程式人生 > >windows下安裝 綠色版mysql服務的批處理

windows下安裝 綠色版mysql服務的批處理

@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