Solved

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

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

Suggested Solutions

Title # Comments Views Activity
php mysql if then statement syntax 4 41
Whether to use true/false, yes/no or 0/1 11 60
Need Wordpress help to link from outside to image item number. 6 38
category table 2 25
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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