0

I'm using below script to update a table in mysql db which is installed in my local machine.

update.sql

use test;
update test.stockcurrent set units='0' where units<'0';

update.bat

@ECHO OFF
SET MYSQL_EXE="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe"
SET DB_USER=root
SET DB_PWD=password

CALL %MYSQL_EXE% --user=%DB_USER% --password=%DB_PWD% < update.sql
IF %ERRORLEVEL% NEQ 0 ECHO Error executing SQL file

Above code is working fine in if mysql is running locally in my machine.

But Now I need to connect to mysql which is running remotely and I need to execute the script from my local machine. How can I do this?

1 Answer 1

1

change your script as per below, need to add -h in your script.

@ECHO OFF
SET MYSQL_EXE="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe"
SET DB_USER=root
SET DB_PWD=password

CALL %MYSQL_EXE% -h <your_server_ip> --user=%DB_USER% --password=%DB_PWD% < update.sql >> C:\log\error.txt 2>&1
IF %ERRORLEVEL% NEQ 0 ECHO Error executing SQL file

Note: user should have rights on remote server from your local machine.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your reply. My local machine should have mysql.exe?
yes mysql.exe utility should be in your machine at the path as you mentioned in your script.
even you can keep this utility at any path and change that path in your script.
But I should not install any mysql stuff in my local machine. How can I connect to remote mysql and run commands without installing mydql utility locally?
just copy mysql.exe from any other machine where mysql installed and copy at the path you mentioned in script. it will work. Without this client you can't connect remote server.
|

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.