?
Solved

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

Posted on 2004-04-19
2
Medium Priority
?
734 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 800 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 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