使用Mysql过程中经常需要使用到免安装版本(绿色版)的Mysql,开始网上搜了一大堆,但还真是不怎么好用。
只好自己琢磨了一番,现在放出来和大家分享下:
//安装启动服务
[cpp] view plain copy
- @ECHO OFF
- if exist "%cd%/my.ini" goto startsrv
- for /f %%i in (‘net start‘) do if %%i==MySQL goto MySQL_IsRunning
- goto MySQL_NotRunning
- :MySQL_IsRunning
- echo "found Server!"
- net stop mysql
- "%cd%"/bin/mysqld.exe -remove
- goto createmyini
- :MySQL_NotRunning
- echo "not found!"
- :createmyini
- rem -------------------------------------------------------
- rem edit my.ini
- setlocal enabledelayedexpansion
- set realpath=
- set replaced=/
- set all=/
- for /f "delims=" %%i in (‘cd‘) do (
- set str=%%i
- set "str=!str:%replaced%=%all%!"
- set realpath=!str!
- )
- echo [client] >>my.ini
- echo default-character-set=utf8 >>my.ini
- echo port=3306 >>my.ini
- echo [server] >>my.ini
- echo default-character-set=utf8 >>my.ini
- echo port=3306 >>my.ini
- echo [mysql] >>my.ini
- echo default-character-set=utf8 >>my.ini
- echo [mysqld] >>my.ini
- echo port=3306 >>my.ini
- rem 下面两句根据实际情况可进行修改
- echo basedir=%realpath%/>>my.ini
- echo datadir=%realpath%/data/>>my.ini
- echo default-character-set=utf8 >>my.ini
- echo default-storage-engine=INNODB >>my.ini
- echo max_connections=100 >>my.ini
- echo query_cache_size=8M >>my.ini
- echo table_cache=256 >>my.ini
- echo tmp_table_size=9M >>my.ini
- echo myisam_max_sort_file_size=100G >>my.ini
- echo myisam_max_extra_sort_file_size=100G >>my.ini
- echo myisam_sort_buffer_size=18M >>my.ini
- echo key_buffer_size=11M >>my.ini
- echo read_buffer_size=64K >>my.ini
- echo read_rnd_buffer_size=256K >>my.ini
- echo sort_buffer_size=256K >>my.ini
- echo innodb_additional_mem_pool_size=2M >>my.ini
- echo innodb_flush_log_at_trx_commit=1 >>my.ini
- echo innodb_log_buffer_size=1M >>my.ini
- echo innodb_buffer_pool_size=18M >>my.ini
- echo innodb_log_file_size=5M >>my.ini
- echo innodb_thread_concurrency=8 >>my.ini
- rem edit my.ini end.
- rem ---------------------------------------------------------------
- "%cd%"/bin/mysqld.exe -install
- :startsrv
- net start MySQL
- Pause
- @ECHO ON
//关闭卸载服务
[cpp] view plain copy
- @ECHO off
- Set CURRENT_DIR=%cd%
- Set MYSQL_HOME=%CURRENT_DIR%
- net stop mysql
- bin/mysqld.exe -remove
- del "%cd%"/my.ini
脚本中关键部分都加有注释,如有问题欢迎大家一起讨论。
同时附上自己已经做好的免安装包(版本为5.1.47),脚本任何版本适用
mysql安装包(CSDN不能传大附件,只好用这个U蛋了,请谨慎下载)
如果你已经有了主文件部分,你也可以直接把bat文件放到mysql主目录下即可
http://blog.csdn.net/blpluto/article/details/5677457
时间: 2024-10-20 10:32:29