mysql_init.bat 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. @echo off
  2. rem 将工作路径切换到当前脚本所在目录
  3. cd /d %~dp0
  4. rem 开始安装mysql
  5. echo ----1.start installing Mysql ---->>../log.txt
  6. "%cd%\mysqld.exe" --initialize-insecure --user=mysql --console
  7. cd ..
  8. set "mysqlpath=%cd%">>../log.txt
  9. set basedir=%cd%
  10. set basedir=%basedir:\=/%
  11. >my.ini echo [mysqld]
  12. >>my.ini echo port=54027
  13. >>my.ini echo basedir=%basedir%
  14. >>my.ini echo datadir=%basedir%/Data
  15. >>my.ini echo max_connections=200
  16. >>my.ini echo max_connect_errors=10
  17. >>my.ini echo character-set-server=utf8mb4
  18. >>my.ini echo default-storage-engine=INNODB
  19. >>my.ini echo local_infile=ON
  20. >>my.ini echo.
  21. >>my.ini echo [mysql]
  22. >>my.ini echo default-character-set=utf8mb4
  23. >>my.ini echo local_infile=ON
  24. >>my.ini echo.
  25. >>my.ini echo [client]
  26. >>my.ini echo port=54027
  27. >>my.ini echo default-character-set=utf8mb4
  28. cd bin
  29. "%mysqlpath%\bin\mysqld.exe" install psychological --defaults-file="%mysqlpath%\my.ini"
  30. rem 设置mysql开机自启
  31. echo ----2. start Mysql service---- >>../log.txt
  32. rem pause
  33. net start psychological
  34. sc config psychological start= auto
  35. net stop psychological
  36. net start psychological
  37. rem 设置mysql环境变量,并进行创建数据库初始化
  38. echo ----3.setting Mysql environment ---->>../log.txt
  39. cd ..
  40. "%cd%\bin\mysqladmin" -u root password Mysql@.2020
  41. "%cd%\bin\mysql.exe" -uroot -pMysql@.2020 psychological_lan < "%cd%\sql\grant.sql"
  42. echo %Path%
  43. echo %Path%|find /i "%mysqlpath%" && set IsNull=true || set IsNull=false
  44. echo %IsNull%
  45. if not %IsNull%==true (
  46. wmic ENVIRONMENT create name="MYSQL_HOME",username="<system>",VariableValue="%mysqlpath%"
  47. rem 追加path变量
  48. wmic ENVIRONMENT where "name='PATH' and username='<system>'" set VariableValue="%path%;%%MYSQL_HOME%%\bin;"
  49. echo ----4. Mysql environment create/append success---->>/log.txt
  50. )
  51. pause >nul