-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_db.bat
More file actions
63 lines (52 loc) · 2.12 KB
/
Copy pathcreate_db.bat
File metadata and controls
63 lines (52 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@echo off
chcp 65001 >nul
setlocal
REM If "mysql" is not in PATH, uncomment and edit the line below (remove "REM " and set your path):
REM set "MYSQL_EXE=C:\xampp\mysql\bin\mysql.exe"
set "MYSQL_EXE="
if defined MYSQL_EXE goto :got_mysql
where mysql >nul 2>&1
if %errorlevel% equ 0 (
set "MYSQL_EXE=mysql"
goto :got_mysql
)
if exist "C:\xampp\mysql\bin\mysql.exe" set "MYSQL_EXE=C:\xampp\mysql\bin\mysql.exe"
if exist "C:\OpenServer\modules\database\MySQL-8.0\bin\mysql.exe" set "MYSQL_EXE=C:\OpenServer\modules\database\MySQL-8.0\bin\mysql.exe"
if exist "C:\OpenServer\modules\database\MySQL-5.7\bin\mysql.exe" set "MYSQL_EXE=C:\OpenServer\modules\database\MySQL-5.7\bin\mysql.exe"
if exist "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe" set "MYSQL_EXE=C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe"
if exist "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" set "MYSQL_EXE=C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe"
if exist "C:\Program Files (x86)\MySQL\MySQL Server 8.0\bin\mysql.exe" set "MYSQL_EXE=C:\Program Files (x86)\MySQL\MySQL Server 8.0\bin\mysql.exe"
if exist "C:\Program Files\MariaDB 10.6\bin\mysql.exe" set "MYSQL_EXE=C:\Program Files\MariaDB 10.6\bin\mysql.exe"
if exist "C:\mysql\bin\mysql.exe" set "MYSQL_EXE=C:\mysql\bin\mysql.exe"
if defined MYSQL_EXE goto :got_mysql
echo MySQL not found in PATH and in standard folders.
echo.
set /p MYSQL_EXE="Enter full path to mysql.exe (e.g. C:\xampp\mysql\bin\mysql.exe): "
set "MYSQL_EXE=%MYSQL_EXE:""=%"
if not exist "%MYSQL_EXE%" (
echo File not found: %MYSQL_EXE%
pause
exit /b 1
)
:got_mysql
echo Creating database habitforge_db from schema.sql...
echo.
if not exist "schema.sql" (
echo ERROR: schema.sql not found. Run this script from Habit_Forge folder.
pause
exit /b 1
)
set /p MYSQL_PASS="MySQL root password (press Enter if no password): "
if "%MYSQL_PASS%"=="" (
"%MYSQL_EXE%" -u root < schema.sql
) else (
"%MYSQL_EXE%" -u root -p%MYSQL_PASS% < schema.sql
)
if %errorlevel% equ 0 (
echo.
echo Database created successfully.
) else (
echo.
echo Failed. Check: 1^) MySQL server is running 2^) Password is correct.
)
pause