user755806
user755806

Reputation: 6815

Execute script on remote mysql db?

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?

Upvotes: 0

Views: 1126

Answers (1)

Zafar Malik
Zafar Malik

Reputation: 6844

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.

Upvotes: 1

Related Questions