将mysql安装至windows系统服务

安装service

使用windows系统下的XAMPP集成包安装mysql服务时,发现运行services.msc 后并不能找到mysql的服务,需要使用如下代码,安装service服务。

@echo off 

if "%OS%" == "Windows_NT" goto WinNT 

:Win9X 
echo Don't be stupid! Win9x don't know Services 
echo Please use mysql_start.bat instead 
goto exit 

:WinNT 
if exist %windir%\my.ini GOTO CopyINI 
if exist c:\my.cnf GOTO CopyCNF 
if not exist %windir%\my.ini GOTO MainNT 
if not exist c:\my.cnf GOTO MainNT 

:CopyINI 
echo Safe the %windir%\my.ini as %windir%\my.ini.old! 
copy %windir%\my.ini /-y %windir%\my.ini.old 
del %windir%\my.ini 
GOTO WinNT 

:CopyCNF 
echo Safe the c:\my.cnf as c:\my.cnf.old! 
copy c:\my.cnf /-y c:\my.cnf.old 
del c:\my.cnf 
GOTO WinNT 

:MainNT 
echo Installing MySQL as an Service 
::copy "%cd%\bin\my.cnf" /-y %windir%\my.ini
echo %cd%

mysqld --install mysql --defaults-file="%cd%\bin\my.ini"
echo Try to start the MySQL deamon as service ... 
net start MySQL 

:exit 
pause

将上述代码保存为bat文件,放在mysql目录下,与bin同级, 同时右键以管理员身份运行。

运行

运行mysql

net start mysql

终止mysql

net stop mysql

你可能感兴趣的:(软件使用)