Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1272243
  • 博文数量: 185
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 3934
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-11 13:11
个人简介

iihero@ChinaUnix, ehero.[iihero] 数据库技术的痴迷爱好者. 您可以通过iihero AT qq.com联系到我 以下是我的三本图书: Sybase ASE in Action, Oracle Spatial及OCI高级编程, Java2网络协议内幕

文章分类

全部博文(185)

文章存档

2014年(4)

2013年(181)

分类: Mysql/postgreSQL

2013-07-22 14:20:35

个人劳动,还请尊重,如若转载请注明出处。iihero@CSDN

 看到有些朋友老问这个非安装版与安装版有什么区别(当然是windows平台)

干脆写了一个脚本自动为其创建iihero-<主版本号>的mysql服务。

 

脚本如下,将其放到解压以后的目录里边执行即可。

  1. @echo off  
  2. echo "This is a demo script for auto installation of noninstall version of MySQL on Windows.  "  
  3. echo "Copyright: iihero@CSDN, when you distribute it, please copy this section above the head."  
  4. echo "================================iiihero@hotmail.com====================================="  
  5. set MYSQL_HOME=%~dp0  
  6. echo MYSQL_HOME=%MYSQL_HOME%  
  7. del /F my.ini  
  8. echo [client] >> my.ini  
  9. echo port = 3306 >> my.ini  
  10. echo default_character_set=gbk >> my.ini  
  11. echo [mysqld] >> my.ini  
  12. echo default_character_set=utf8 >> my.ini  
  13. echo default_storage_engine=InnoDB >> my.ini  
  14. echo basedir=%MYSQL_HOME%>>my.ini  
  15. echo datadir=%MYSQL_HOME%data>> my.ini  
  16. echo innodb_data_file=ibdata1:50M;ibdata2:10M:autoextend >> my.ini  
  17. echo transaction-isolation=READ-COMMITTED >> my.ini  
  18. echo port=3306 >> my.ini  
  19. echo max_allowed_packet = 64M >> my.ini  
  20. echo "my.ini in %MYSQL_HOME% created."  
  21. set PATH=%MYSQL_HOME%/bin;%PATH%  
  22. if exist "%MYSQL_HOME%/bin/mysqld-nt.exe" call mysqld-nt --install-manual mysql55 --defaults-file="%MYSQL_HOME%/my.ini"  
  23. if not exist "%MYSQL_HOME%/bin/mysqld-nt.exe" call mysqld --install-manual mysql55 --defaults-file="%MYSQL_HOME%/my.ini"  

 

继续整理:

 

随然前边写了一篇用于命令行下安装mysql非安装版。但总觉不够。
我承认自己很懒,每次下载,并手动配置一些东西,很浪费时间。于是做了这么一个东东。
直接将mysql_install_auto.zip解压到某盘,如d://mysql_install_auto下边。
然后进到d:/mysql_install_auto下边,使用命令行执行:
mysql_install.bat [arch] [ROOTDIR] [server_port]


参数:
     fullversion,  必须指定, 如5.6.14, 5.1.72, 4.1.22, 5.5.34, 6.0.11-alpha等等
     arch, 可选,不指定时,为win32, 有效值可以是win32或者winx64
     ROOTDIR, 可选,安装的最终根目录,默认值为d:, 不用带后边的"\".此目录必须事先存在或创建好
     server_port, 可选,默认值为3306.
     
最终生成的服务名为: iihero-<主版本号>


如果你想卸载,也非常简单,先用sc delete iihero-<主版本号>
接着进到%ROOTDIR%\%MYSQL_HOME%, 直接删除整个目录就可以了. 非常方便。


有什么问题,欢迎联系:iiihero AT hotmail.com
http://blog.csdn.net/iihero
http://blog.chinaunix.net/uid/40286.html
http://blog.chinaunix.net/topic/hexiong/

确定一个完整的版本号,比如:5.6.14, 5.1.72, 5.5.34, 如何确定,
访问网址:
主版本号>/ (主版本号为5.1, 5.6, 5.5之类)
找到win32.zip, 或者winx64.zip结尾的文件名,比如:mysql-5.5.34-win32.zip, 中间的串:5.5.34就是
完整的版本号.


选定是32位的, 还是64位的,32位用win32, 64位的用winx64, 默认为32位。

由于网站空间实在有限,没地方放附件。我将附件放到CSDN上了,有兴趣的可以去下载试用一下。

下载地址:

原来的那个包:,需要修改一些东西才能用。

针对刚上传的包,似乎发现了一些小问题,又改了改,下载完以后,修改: mysql_install.bat 以及my_ini_gen.bat,它们的内容分别如下:

mysql_install.bat:


  1. @echo off  
  2. set fullversion=%1  
  3. set fullname=""  
  4. set server_default_character_set=default_character_set  
  5. set arch=%2  
  6. set ROOTDIR=%3  
  7. set server_port=%4  
  8. set mysql_dir=""  
  9.   
  10. :: example:  
  11. :: mysql_install.bat 4.1.22  
  12. :: mysql_install.bat 5.0.95 winx64  
  13. :: mysql_install.bat 5.6.14 winx64  
  14. :: mysql_install.bat 5.1.72 winx64  
  15. :: mysql_install.bat 5.5.34 winx64  
  16. :: mysql_install.bat 6.0.11-alpha win32  
  17.   
  18. if "[%fullversion%]" == "[]" goto HELP  
  19. if not "[%fullversion%]" == "[]" goto TOINSTALL  
  20. :HELP  
  21.     echo mysql_install.bat ^ [arch] [ROOTDIR] [server_port]  
  22.     echo valid ^ :4.1.22, 5.1.xx, 5.5.xx, e.g. 5.1.72, 5.6.14, 6.0.11-alpha etc.  
  23.     echo valid xx, you can open ^ to find it.  
  24.     echo e.g. to get the target fullversion of 5.1, you can open:  
  25.     echo 5.1 to get the full name end with winx64.zip or win32.zip.  
  26.     echo valid value of arch:  win32,  winx64  
  27.     echo ROOTDIR,  the root directory of mysql installation. The default value is d:  It should be already existed/created.  
  28.     echo default server_port is 3306  
  29.     echo Please input valid value of the fullversion.  
  30.     goto END  
  31.       
  32. :TOINSTALL      
  33. if "%arch%" == "" set arch=win32  
  34. if "%server_port%" == "" set server_port=3306  
  35. if "[%ROOTDIR%]" == "[]" echo ROOTDIR is not set, will be using default value. && set ROOTDIR=d:  
  36. set version=%fullversion:~0,3%  
  37. echo The major version is: %version%  
  38. set version_arch=%fullversion%-%arch%  
  39. echo The full version with arch is: %version_arch%  
  40. :: 4.1版本只有32位的  
  41. if "%version%" == "4.1" (  
  42.     set fullname="mysql-noinstall-%version_arch%"  
  43.     set mysql_dir="%ROOTDIR%\mysql-%version_arch%"  
  44.     echo You will fetch %fullname% ......  
  45.     goto DOWNLOAD  
  46. )  
  47.   
  48. if "%version%" == "5.0" (  
  49.     set fullname="mysql-noinstall-%version_arch%"  
  50.     set mysql_dir="%ROOTDIR%\mysql-%version_arch%"  
  51.     echo You will fetch %fullname% ......  
  52.     goto DOWNLOAD  
  53. )  
  54.   
  55. if "%version%" == "5.1" (  
  56.     set fullname="mysql-noinstall-%version_arch%"  
  57.     set mysql_dir="%ROOTDIR%\mysql-%version_arch%"  
  58.     echo You will fetch %fullname% ......  
  59.     goto DOWNLOAD  
  60. )  
  61.   
  62. if "%version%" == "5.5" (  
  63.     set fullname="mysql-%version_arch%"  
  64.     set mysql_dir="%ROOTDIR%\mysql-%version_arch%"  
  65.     set server_default_character_set=character_set_server  
  66.     echo You will fetch %fullname% ......  
  67.     goto DOWNLOAD  
  68. )  
  69.   
  70. if "%version%" == "5.6" (  
  71.     set fullname="mysql-%version_arch%"  
  72.     set mysql_dir="%ROOTDIR%\mysql-%version_arch%"  
  73.     set server_default_character_set=character_set_server  
  74.     echo You will fetch %fullname% ......  
  75.     goto DOWNLOAD  
  76. )  
  77.   
  78. if "%version%" == "6.0" (  
  79.     set fullname="mysql-noinstall-%version_arch%"  
  80.     set mysql_dir="%ROOTDIR%\mysql-%version_arch%"  
  81.     set server_default_character_set=character_set_server  
  82.     echo You will fetch %fullname% ......  
  83.     goto DOWNLOAD  
  84. )  
  85.   
  86. :ERROR  
  87.     echo the version should be 4.1, 5.0, 5.1, 5.5, 5.6, 6.0 for now!!  
  88.   
  89. :DOWNLOAD  
  90. if not exist %fullname%.zip (  
  91.     wget %version%/%fullname%.zip  
  92.     if not exist %fullname%.zip (  
  93.         echo download %fullname% error!!  
  94.         goto EOF  
  95.     )  
  96. )  
  97. if not exist %mysql_dir% (  
  98.     7z x -y -o%ROOTDIR%\ -x!*\data\ib* %fullname%.zip  
  99. )  
  100. copy /Y my_ini_gen.bat %mysql_dir%  
  101. cd /d %mysql_dir%  
  102. :: copy /Y ..\my_ini_gen.bat .  
  103. call my_ini_gen.bat  
  104. :EOF  
  105. echo The installation finished....  
  106. :END  
  107. @echo on  




my_ini_gen.bat:


  1. @echo off  
  2. echo "This is a demo script for auto installation of noninstall version of MySQL on Windows.  "  
  3. echo "Copyright: iihero, when you distribute it, please copy this section above the head."  
  4. echo "================================iihero.com====================================="  
  5. set MYSQL_HOME=%~dp0  
  6. echo MYSQL_HOME=%MYSQL_HOME%  
  7. del /F my.ini  
  8. echo [client] >> my.ini  
  9. echo port = %server_port% >> my.ini  
  10. echo default_character_set=gbk >> my.ini  
  11. echo [mysqld] >> my.ini  
  12. echo %server_default_character_set%=utf8 >> my.ini  
  13. echo default_storage_engine=InnoDB >> my.ini  
  14. echo basedir=%MYSQL_HOME%>>my.ini  
  15. echo datadir=%MYSQL_HOME%data>> my.ini  
  16. :: echo innodb_data_file_path=%MYSQL_HOME%data>> my.ini  
  17. echo innodb_data_file=ibdata1:50M;ibdata2:10M:autoextend >> my.ini  
  18. echo transaction-isolation=READ-COMMITTED >> my.ini  
  19. echo port=%server_port% >> my.ini  
  20. echo max_allowed_packet = 64M >> my.ini  
  21. echo "my.ini in %MYSQL_HOME% created."  
  22. set PATH=%MYSQL_HOME%\bin;%PATH%  
  23. echo Forcely delete the service iihero-%version% if existing.  
  24. sc delete iihero-%version%  
  25. if exist "%MYSQL_HOME%\bin\mysqld-nt.exe" call %MYSQL_HOME%\bin\mysqld-nt --install-manual "iihero-%version%" --defaults-file="%MYSQL_HOME%my.ini"  
  26. if not exist "%MYSQL_HOME%\bin\mysqld-nt.exe" call %MYSQL_HOME%\bin\mysqld --install-manual "iihero-%version%" --defaults-file="%MYSQL_HOME%\my.ini"  
  27.   
  28.   
  29. echo .........................................................................................  
  30. echo Finished creating service "iihero-%version%" for mysql-%version_arch%. Please check it in the service panel.  
  31. echo You can use net start iihero-%version% to start the mysql service. Good luck.  
  32. echo If you want to delete the install, just do as below:  
  33. echo 1. If you have started the service, just run: net stop iihero-%version% to stop it.  
  34. echo 2. sc delete iihero-%version% to delete the service  
  35. echo 3. Delete the whole directory of %MYSQL_HOME%  
  36. echo .........................................................................................  

将上述两个文件的内容覆盖一下就好。主要是修复路径以及版本号的错误, 支持4.1, 5.0, 5.1, 5.5, 5.6, 6.0主版本的下载及安装。
修改后的脚本,重新上传到:

有什么问题,欢迎发邮件给我。
















阅读(3162) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~