mysql圧縮版ワンタッチインストールスクリプト

4175 ワード

インストールスクリプトをbinディレクトリと同じルートディレクトリの下に配置してください
5.0バージョンインストールスクリプト
@echo off

if  %~dp0 == %cd%\ ( 
echo             ,           !
set /p in=
exit
)

echo mysql5.0         ...
echo       ...
set /p password=     :

if not defined password (
echo        ,           !
set /p in=
exit
)


rem          
set path=%~dp0
rem       
cd /d %path%
rem           
set ini=my.ini
rem   data   
mkdir data

rem  my.ini      
echo [Client] >> %ini%
echo.
echo port = 3306 >> %ini%
echo.
echo [mysqld] >> %ini%
echo.
echo port = 3306 >> %ini%
echo.
echo basedir=%path% >> %ini%
echo.
echo datadir=%path%\data >> %ini%
echo.
echo max_connections=200 >> %ini%
echo.
echo character-set-server=utf8 >> %ini%
echo.
echo default-storage-engine=InnoDB >> %ini%
echo.
echo sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES >> %ini%
echo.
echo skip-grant-tables >> %ini%
echo.
echo [mysql] >> %ini%
echo.
echo default-character-set=utf8 >> %ini%

rem   bin  
cd /d %path%\bin
rem   mysql    
start /b /wait mysqld -install
rem   mysql     
start /b /wait mysqld --initialize --console
rem   mysql  
start /b /wait net start mysql
rem   root    
start /b /wait mysql -uroot -pnon -e "update mysql.user set authentication_string=PASSWORD('%password%') where user='root' and host='localhost';"
rem   mysql  
start /b /wait net stop mysql
rem      
cd /d %path%
rem   my.ini  
CD. > %ini%
rem  my.ini      
echo [Client] >> %ini%
echo.
echo port = 3306 >> %ini%
echo.
echo [mysqld] >> %ini%
echo.
echo port = 3306 >> %ini%
echo.
echo basedir=%path% >> %ini%
echo.
echo datadir=%path%\data >> %ini%
echo.
echo max_connections=200 >> %ini%
echo.
echo character-set-server=utf8 >> %ini%
echo.
echo default-storage-engine=InnoDB >> %ini%
echo.
echo sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES >> %ini%
echo.
echo [mysql] >> %ini%
echo.
echo default-character-set=utf8 >> %ini%

rem   mysql  
start /b /wait net start mysql

pause>nul

バージョン8.0
注意:
1、管理者でinstallを実行する.bat 2、mysqld--console--skip-grant-tables--shared-memory 3を実行し、パスワードを入力せずにmysqlにログインした後、それぞれ以下の文flush privilegesを実行します.ALTER USER 'root'@'localhost' IDENTIFIED BY 'ok' PASSWORD EXPIRE NEVER; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ok'; flush privileges;
4、すべてのcmdウィンドウを閉じ、net start mysql起動サービスを実行すれば、正常に使用できる.
install.batは以下の通り
@echo off

set sysPath=%cd%

if  %~dp0 == %cd%\ ( 
echo             ,           !
set /p in=
exit
)


echo mysql8.0         ...
echo       ...

set /p password=     :
if not defined password (
echo        ,           !
set /p in=
exit
)

set /p serviceName=       :
if not defined serviceName (
echo          ,           !
set /p in=
exit
)

set /p port=      :
if not defined port (
echo         ,           !
set /p in=
exit
)


rem          
set path=%~dp0
rem       
cd /d %path%
rem           
set ini=my.ini
rem   data   
mkdir data

rem  my.ini      
echo [Client] >> %ini%
echo.
echo port = %port% >> %ini%
echo.
echo [mysqld] >> %ini%
echo.
echo port = %port% >> %ini%
echo.
echo basedir=%path% >> %ini%
echo.
echo datadir=%path%\data >> %ini%
echo.
echo max_connections=200 >> %ini%
echo.
echo character-set-server=utf8 >> %ini%
echo.
echo default-storage-engine=InnoDB >> %ini%
echo.
echo sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES >> %ini%
echo.
echo [mysql] >> %ini%
echo.
echo default-character-set=utf8 >> %ini%

rem   bin  
cd /d %path%\bin

rem   mysql    
start /b /wait mysqld -install %serviceName% --defaults-file=“%path%\my.ini”

cd /d %sysPath%
start /b /wait reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%serviceName%" /v ImagePath /t REG_EXPAND_SZ /d "%path%\bin\mysqld %serviceName%" /f


cd /d %path%\bin


rem   mysql     
start /b /wait mysqld --defaults-file=%path%\my.ini --initialize --console


pause>nul