Solved

Command-line Mysql: Need to automatically exit after running a script via the "source" command in DOS

Posted on 2004-04-19
2
730 Views
Last Modified: 2006-11-17
All,

The goal is to make a script as easy as possible for an end user to run because they are very non-technical.  They want to be able to quickly run a query I created via a dos prompt (because it uses stored procedures).   After the user types in "source c:\myquery.sql", I want it to run, and then exit automatically.  Trouble is, there seems to be no way to do this within the source script.  In other words, the user will have to remember to type in "exit" when the script completes.  Please confirm if there is any way to achieved the automatic exit.  It would be great to have MySQL exit back to the .bat file which originally invoked it.

BTW, I am currently assigned to a very low-tech project and a non-functional requirement is to keep config to a minimum for the next person who takes over.
0
Comment
Question by:lhalkapeel
2 Comments
 
LVL 9

Accepted Solution

by:
Alf666 earned 200 total points
ID: 10870428
Just use one of the following :

dos> mysql < batch-file

If you are running mysql under Windows and have some special characters in the file that cause problems, you can do this:

dos> mysql -e "source batch-file"

If you need to specify connection parameters on the command line, the command might look like this:

dos> mysql -h host -u user -p < batch-file
Enter password: ********

Or, having the password on the command line :

dos> mysql -h host -u user -ppassword < batch-file

(the "-p" and the password must be stuck).


0
 
LVL 17

Expert Comment

by:leannonn
ID: 10875613
>  Please confirm if there is any way to achieved the automatic exit.

Yes, there is. Write all your commands and end the file with \q
---
use your_database;
select count(*) from your_table;
...
\q
---

Please note that it has to be in lower case.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question