I need some help. I want to get the database name in MySQL to make it as directory name. But my code is not correct . it fails.
e.g
DATABASE NAME
- sample
- sample_test
i want to create a directory with the same name as database name.
my code is:
@echo off
SET path=C:\Users\neca\Desktop
cd C:\wamp\bin\mysql\mysql5.5.24\bin
SET UserName=root
SET UserPass=root
mysql -u%UserName% -r%UserPass% -N -B -e "SHOW DATABASES LIKE '%%sample%%'" |
FOR /F %%D IN ('C:\Windows\System32\findstr /V "information_schema performance_schema"') DO @echo %%D
IF exist %path%\%%D (echo %%D exist)
ELSE (mkdir %path%\%%D && echo %%D created)
i got this result: i add pause command to pause the terminal and the display is
sample IF exist C:\Users\neca\Desktop\sample (echo sample exist)
ELSE (mkdir C:\Users\neca\Desktop\sample sample created)
Press any key to continue . . .
when i test it just like this the output is correct
@echo off
SET path=C:\Users\neca\Desktop
cd C:\wamp\bin\mysql\mysql5.5.24\bin
SET UserName=root
mysql -uroot -N -B -e "SHOW DATABASES LIKE '%%sample%%'"
pause
output:
sample
sample_test
Press any key to continue . . .
pathvariable not even temporarily; use another variable name, e.g.SET "pathX=C:\Users\neca\Desktop"and read again Loop command: against the results of another command. Then you could tryFOR /F "usebackq tokens=*" %%G IN (``command with apostrophes here``) DO (code snippet)and note that code snippet in parentheses could consist of more than one command lines (only one backquote, I can't escape it!)echo ONand provide full output from thatmysql ..."command (including echoed one). Alonemysql ...without next|piped one. Insertpauseimmediately behind it instead. Copy a result from CLI window, edit your question and paste it there.