Solved

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

Posted on 2004-04-19
2
724 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Creating and Managing Databases with phpMyAdmin in cPanel.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now