@echo off chcp 65001 >nul color 0B title Reset MySQL Root Password cls echo ========================================== echo Reset MySQL Root Password echo ========================================== echo. echo This script will reset root password and grant 127.0.0.1 access echo. echo IMPORTANT: Close any running MySQL windows first! echo. pause set MYSQL_HOME=%cd% set password=njcnpqs echo. echo [1] Stopping MySQL... taskkill /F /IM mysqld.exe >nul 2>&1 timeout /t 2 >nul echo Done. echo. echo [2] Creating init file... ( echo ALTER USER IF EXISTS 'root'@'localhost' IDENTIFIED BY '%password%'; echo CREATE USER IF NOT EXISTS 'root'@'127.0.0.1' IDENTIFIED BY '%password%'; echo GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION; echo CREATE USER IF NOT EXISTS 'root'@'%%' IDENTIFIED BY '%password%'; echo GRANT ALL PRIVILEGES ON *.* TO 'root'@'%%' WITH GRANT OPTION; echo FLUSH PRIVILEGES; ) > "%MYSQL_HOME%\reset-init.sql" echo Done. echo. echo [3] Starting MySQL with init-file... echo This will take about 30 seconds... echo. cd /d "%MYSQL_HOME%" "%MYSQL_HOME%\bin\mysqld.exe" --defaults-file="%MYSQL_HOME%\my.ini" --init-file="%MYSQL_HOME%\reset-init.sql" --console REM The above command runs in foreground and will exit when you press Ctrl+C echo. echo MySQL has stopped. echo. if exist "%MYSQL_HOME%\reset-init.sql" del "%MYSQL_HOME%\reset-init.sql" echo. echo ========================================== echo Password reset completed! echo ========================================== echo. echo Connection info: echo Host: 127.0.0.1 echo Port: 3306 echo User: root echo Password: %password% echo. echo Now you can run startup.bat to start MySQL normally echo. pause