automatically running SQL scripts from starting HeidiSQL from command line

michael_sl posted 2 years ago in Running SQL scripts

Hi, I am beginning using mySQL and want to solve this task:

Using HeidiSQL a batch on windows task planner is to open a connection to a HeidiSQL-session using a script for updating a table.

At the moment the batch is working fine, starting the session and opening the script.

Is it possible, to make HeidiSQL automatically start the script and after having finished the script close the connection and HeidiSQL itself?

Thanks very much in advance.

ansgar posted 2 years ago

No, closing a connection and/or HeidiSQL itself is not doable per command line currently.

HeidiSQL accepts some connection based command line parameters, and opening SQL files. But that's far from being scriptable. I think for doing something after opening the connection, HeidiSQL would need some scripting solution, which can do things dependently on each other.

michael_sl posted 2 years ago

Hi ansgar, thank you for your help and have a good new year 2017!

ramanm posted 2 years ago

Hi, I am beginning using mySQL and want to solve this task:

Using HeidiSQL a batch on windows task planner is to open a connection to a HeidiSQL-session using a script for updating a table.

At the moment the batch is working fine, starting the session and opening the script.

Is it possible, to make HeidiSQL automatically start the script and after having finished the script close the connection and HeidiSQL itself?

Thanks very much in advance.

** Hi Michael, I am trying to achieve the same task. Could you please help me with the code you have enterted in your batch file? Mine does not connect to HeidiSQL. Below is the code in my batch file:

@ECHO OFF

setlocal

:PROMPT SET /P AREYOUSURE=Update Bauer end of month table? (Y/[N])? IF /I "%AreYouSure%" NEQ "Y" GOTO END

SET MYSQL_EXE="C:\Program Files\HeidiSQL\heidisql.exe"
SET DB_USER=user SET DB_PWD=password

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

pause

  • **

Please login to leave a reply, or register at first.