解压版 不做自启 用作备用数据库 端口3366 使用 : echo 2. 进入mysql 2 免密登录 在 mysql根目录放一个 my.ini 文件 👇

  • 主要是设置一些初始配置

navicat 连接设置

echo 2. 进入mysql 2 免密登录 alter user ‘root’@’localhost’ identified with mysql_native_password by ‘root’; flush privileges;

mysql-8.0.23-winx64.zip

mysqlStartUp.bat

  1. @echo off & setlocal
  2. :loop
  3. set /p mysqlPath=mysql路径(D:\mysql-8-winx64\)
  4. #set mysqlPath=C:\Users\WDAGUtilityAccount\Desktop\mysql\mysql-8.0.23-winx64\mysql-8.0.23-winx64
  5. set setMysql=mysqld
  6. set fileName=%setMysql%.exe
  7. :mysqlFunction
  8. echo ================ 选择mysql功能 ===============
  9. echo.
  10. set currentDir=%mysqlPath%\bin
  11. set drives=%mysqlPath:~0,2%
  12. set dataFolder=%mysqlPath%\data
  13. echo %currentDir%
  14. echo %drives%
  15. echo %dataFolder%
  16. echo.
  17. echo -------------------------------------
  18. echo 1. 启动mysql 1
  19. echo 2. 进入mysql 2
  20. echo 3. 结束进程mysql 3
  21. echo ==========PRESS '0' TO QUIT==========
  22. echo.
  23. echo.
  24. set input=
  25. set /p input=Please select a number:
  26. if /i '%input%'=='1' goto startMysql
  27. if /i '%input%'=='2' goto goMysql
  28. if /i '%input%'=='3' goto killMysql
  29. if /i '%input%'=='0' goto end
  30. echo.
  31. echo.
  32. rem 输入错误跳回 input
  33. echo wrong number, try it again&&goto mysqlFunction
  34. :startMysql
  35. echo.
  36. call taskkill /f /im %fileName%
  37. if %errorlevel% == 0 (
  38.  echo 杀死%setMysql%进程成功
  39. ) else (
  40.  echo 杀死%setMysql%进程失败
  41. )
  42. echo.
  43. echo Starting %setMysql% ...
  44. if exist %dataFolder% (
  45. rem 目录data已存在,无需创建
  46. echo 目录%dataFolder%目录已存在,无需创建!
  47. goto startMysqlSucceed
  48. ) else (
  49. rem 创建data目录,使用复制方法
  50. echo %dataFolder%目录不存在,已创建该目录!
  51. md %dataFolder%
  52. rem 3秒创建文件夹
  53. timeout /T 3 /NOBREAK
  54. rem 睡醒了
  55. cd /d %currentDir%
  56. call %setMysql% --initialize-insecure --console && (goto startMysqlSucceed) || goto startMysqlFailed
  57. )
  58. :startMysqlSucceed
  59. rem 睡三秒
  60. timeout /T 3 /NOBREAK
  61. cd /d %currentDir%
  62. echo 当前路径 %cd%
  63. start %fileName%
  64. echo 启动%setMysql%成功
  65. echo.
  66. echo.
  67. goto loop
  68. :startMysqlFailed
  69. echo 初始化失败 删除文件夹
  70. rd /s /q %dataFolder%
  71. goto end
  72. :goMysql
  73. echo.
  74. echo.
  75. cd /d %currentDir%
  76. echo 当前路径 %cd%
  77. mysqld --console --skip-grant-tables --shared-memory
  78. call mysql -uroot
  79. if %errorlevel% == 0 (
  80.  echo 启动%setMysql%命令行成功
  81. ) else (
  82.  echo 启动%setMysql%命令行失败
  83. )
  84. echo.
  85. echo.
  86. goto loop
  87. :killMysql
  88. echo.
  89. echo 当前路径 %cd%
  90. echo.
  91. call taskkill /f /im %fileName%
  92. if %errorlevel% == 0 (
  93.  echo 杀死%setMysql%进程成功
  94. ) else (
  95.  echo 杀死%setMysql%进程失败
  96. )
  97. echo.
  98. echo.
  99. goto loop
  100. goto end
  101. :no
  102. :end
  103. echo Good-bye!
  104. pause

my.ini

  1. [mysql]
  2. #设置mysql客户端默认字符编码形式
  3. default-character-set=utf8mb4
  4. [mysqld]
  5. #设置端口号,默认3366
  6. port = 3366
  7. #设置最大连接数
  8. max_connections=200
  9. #允许连接失败的次数
  10. max_connect_errors=10
  11. #服务端使用的字符集默认为utf8mb4
  12. character-set-server=utf8mb4
  13. #创建新表时将使用的默认存储引擎
  14. default-storage-engine=INNODB
  15. #默认使用“mysql_native_password”插件认证
  16. #mysql_native_password
  17. default_authentication_plugin=mysql_native_password
  18. [client]
  19. #设置mysql客户端连接服务端时默认使用的端口
  20. port=3366
  21. default-character-set=utf8mb4