Solved

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

Posted on 2004-04-19
2
733 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Aleksandar Bradarić
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

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 …
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

695 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