installMySQL.bat
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
echo 放在mysql安装根目录位置下
echo 安装mysql的脚本(以管理员运行) by kaiba8
setlocal enabledelayedexpansion
set remain=%path%
::待查找字符串
set toAdd=%~dp0%bin
set currentPath=%~dp0%
::标记,默认没有重复
set finded=false
:loop
for /f "tokens=1* delims=;" %%a in ("%remain%") do (
::如果找到相同的了
if "%toAdd%"=="%%a" (
::直接退出
goto :isFinded
::该表标记,true表示有重复的了
set finded=true
)
rem 将截取剩下的部分赋给变量remain,其实这里可以使用延迟变量开关
set remain=%%b
)
::如果还有剩余,则继续分割
if defined remain goto :loop
::如果没有重复:
if "%finded%"=="false" (
echo 正在修改系统path环境变量...
setx /m "path" "%path%;%toAdd%"
call :installMySQL
goto :end
) else (
:isFinded
echo path环境变量中已经有了该环境变量,无须重复添加.
call :installMySQL
goto :end
)
:installMySQL
echo 创建或者更新配置文件my.ini
::for /f %%i in ('dir /b %currentPath%*.txt') do @echo .>%%i
echo [client]>%currentPath%my.ini
echo port = 3306>>%currentPath%my.ini
echo default-character-set = utf8>>%currentPath%my.ini
echo [mysqld]>>%currentPath%my.ini
echo skip-grant-tables>>%currentPath%my.ini
echo port=3306>>%currentPath%my.ini
echo character_set_server = utf8>>%currentPath%my.ini
echo basedir=%currentPath%>>%currentPath%my.ini
echo datadir=%currentPath%data>>%currentPath%my.ini
echo sql_mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION">>%currentPath%my.ini
echo innodb_large_prefix = ON>>%currentPath%my.ini
echo innodb_file_format = Barracuda>>%currentPath%my.ini
echo innodb_file_per_table = ON>>%currentPath%my.ini
echo [WinMySQLAdmin]>>%currentPath%my.ini
echo %currentPath%bin\mysqld.exe>>%currentPath%my.ini
REM 将引号内部分改成你要查找的服务名称
sc query |find /i "MySQL" >nul 2>nul
echo 如果服务存在,跳转至exist标签
if not errorlevel 1 (goto exist) else goto notexist
goto :eof
:exist
echo 服务存在时删除MySQL服务后重装
net stop mysql
sc delete MySQL
rd /s /Q %~dp0%data
cd %currentPath%bin
mysqld -install MySQL
mysqld --initialize-insecure --user=mysql;
net start mysql
goto :eof
:notexist
echo 服务不存在时安装MySQL服务
rd /s /Q %~dp0%data
cd %currentPath%bin
mysqld -install MySQL
mysqld --initialize-insecure --user=mysql;
net start mysql
goto :eof
:end
pause
installJAVA.bat
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
echo 放在java jdk安装根目录位置下
echo 安装java的脚本(以管理员运行) by kaiba8
setlocal enabledelayedexpansion
set remain=%path%
::待查找字符串
set toAdd=%~dp0%bin
set currentPath=%~dp0%
::标记,默认没有重复
set finded=false
:loop
for /f "tokens=1* delims=;" %%a in ("%remain%") do (
::如果找到相同的了
if "%toAdd%"=="%%a" (
::直接退出
goto :isFinded
::该表标记,true表示有重复的了
set finded=true
)
rem 将截取剩下的部分赋给变量remain,其实这里可以使用延迟变量开关
set remain=%%b
)
::如果还有剩余,则继续分割
if defined remain goto :loop
::如果没有重复:
if "%finded%"=="false" (
echo 正在修改系统path环境变量...
setx /m "path" "%path%;%toAdd%"
goto :end
) else (
:isFinded
echo path环境变量中已经有了该环境变量,无须重复添加.
goto :end
)
:end
pause