6

I want to run bat file in mysql prompt automatically in all computers without setting environment variable path.

I am using Xampp server,but some of my friends using Wampp and MysqlServer. However I want to run my sql commands by running a .bat file.So I want to navigate to the MySql> prompt first.

I tried following CMD command to find the service,

tasklist /svc >mysqld.exe

but I can't navigate to mysql>

Help me if someone has any solution. Thanks.

5
  • 1
    Run tasklist /svc /fi "imagename eq mysqld.exe" you get Mysql service name and after display the details of sc qc MYSQL57 and to get particular details use for /f "tokens=1*delims==" %a in ('wmic service where "name='MYSQ L57'" get pathname /value') do @for /f "delims=" %c in ("%~b") do @echo "%~c" Commented Jan 11, 2016 at 2:48
  • What do you mean by "without setting environment variable?" Do you mean you don't want to permanently change any System or User environment variables? Could you set an environment variable that only lasts for as long as the script runs (without permanently changing any environment variables)? Also, is the path to mysqld.exe identical on all the machines you will run the .bat file on? Finally, when you say you want to "..navigate to the MySql> prompt first," do you mean that you want the batch script to open a MySql prompt, and then execute a command? Could you just pass a command to mysqld? Commented Jan 17, 2016 at 11:48
  • I want to find some way to run mysql commands without configuring settings, if mysqld service running on the system. Consider its username root and no password(defult) Commented Jan 17, 2016 at 15:30
  • If I can find currently running mysqld service path with cmd command , it will be very useful for this task. Commented Jan 17, 2016 at 15:33
  • May be this could solve your problem superuser.com/questions/509042/… Commented Jan 19, 2016 at 4:33

1 Answer 1

1

This would do the trick:

for /f "tokens=3 skip=3" %a in ('tasklist /svc /fi "imagename eq mysqld.exe"') do @cmd /c sc qc %a ^| findstr PATH
Sign up to request clarification or add additional context in comments.

2 Comments

this can find the path, but using this how to navigate to that path?
Write the output to a file, read the path using for and do a cd command. Not near a computer now, so can't give a code example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.