Execute SQL query from Command Line

mysql-newbie posted 2 months ago in Running SQL scripts

Is there a way to execute a SQL query from command line. For instance I use:

heidisql.exe -d=mysession "c:\test.sql"

And it opens heidisql and opens the query in the query tab but I want it to execute the query as well. Even better yet, if it could execute the query and then close heidisql that would be awesome.

Any help is much appreciated.

ansgar posted 2 months ago

You should use mysqldump for such purposes. See here for an example.

mysql-newbie posted 2 months ago

I don't have mysql installed on my local machine. I'm connecting from across the internet via SSH is there a way to do that or do I need a different program?

ansgar posted 2 months ago

Ok, then you could use an SSH client (Putty for example), connect to your MySQL server and then pass the commands you want to execute.

mysql-newbie posted 2 months ago

Will do. Thanks for the help!

ducpham posted 1 month ago

Ok, then you could use an SSH client ([Putty] connect to your MySQL server and then pass the commands you want to execute.

Thanks for the help @Ansgar. A stupid question, once the SQL command is executed on the server via SSH client, how do we get the output files back to our computer?

In this case I am automating some SELECT INTO OUTFILE lines.

Thanks!

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