@echo off rem 将工作路径切换到当前脚本所在目录 cd /d %~dp0 rem 开始安装mysql echo ----1.start installing Mysql ---->>../log.txt "%cd%\mysqld.exe" --initialize-insecure --user=mysql --console cd .. set "mysqlpath=%cd%">>../log.txt set basedir=%cd% set basedir=%basedir:\=/% >my.ini echo [mysqld] >>my.ini echo port=54027 >>my.ini echo basedir=%basedir% >>my.ini echo datadir=%basedir%/Data >>my.ini echo max_connections=200 >>my.ini echo max_connect_errors=10 >>my.ini echo character-set-server=utf8mb4 >>my.ini echo default-storage-engine=INNODB >>my.ini echo local_infile=ON >>my.ini echo. >>my.ini echo [mysql] >>my.ini echo default-character-set=utf8mb4 >>my.ini echo local_infile=ON >>my.ini echo. >>my.ini echo [client] >>my.ini echo port=54027 >>my.ini echo default-character-set=utf8mb4 cd bin "%mysqlpath%\bin\mysqld.exe" install psychological --defaults-file="%mysqlpath%\my.ini" rem 设置mysql开机自启 echo ----2. start Mysql service---- >>../log.txt rem pause net start psychological sc config psychological start= auto net stop psychological net start psychological rem 设置mysql环境变量,并进行创建数据库初始化 echo ----3.setting Mysql environment ---->>../log.txt cd .. "%cd%\bin\mysqladmin" -u root password Mysql@.2020 "%cd%\bin\mysql.exe" -uroot -pMysql@.2020 psychological_lan < "%cd%\sql\grant.sql" echo %Path% echo %Path%|find /i "%mysqlpath%" && set IsNull=true || set IsNull=false echo %IsNull% if not %IsNull%==true ( wmic ENVIRONMENT create name="MYSQL_HOME",username="",VariableValue="%mysqlpath%" rem 追加path变量 wmic ENVIRONMENT where "name='PATH' and username=''" set VariableValue="%path%;%%MYSQL_HOME%%\bin;" echo ----4. Mysql environment create/append success---->>/log.txt ) pause >nul