Oracle 5.0 Reference Manual page 235

Table of Contents

Advertisement

C:\>
mysql -e "source batch-file"
If you need to specify connection parameters on the command line, the command might look like this:
shell>
mysql -h host -u user -p < batch-file
Enter password:
********
When you use
this way, you are creating a script file, then executing the script.
mysql
If you want the script to continue even if some of the statements in it produce errors, you should use
the
[266]
command-line option.
--force
Why use a script? Here are a few reasons:
• If you run a query repeatedly (say, every day or every week), making it a script enables you to avoid
retyping it each time you execute it.
• You can generate new queries from existing ones that are similar by copying and editing script files.
• Batch mode can also be useful while you're developing a query, particularly for multiple-line
commands or multiple-statement sequences of commands. If you make a mistake, you don't have to
retype everything. Just edit your script to correct the error, then tell
• If you have a query that produces a lot of output, you can run the output through a pager rather than
watching it scroll off the top of your screen:
shell>
mysql < batch-file | more
• You can catch the output in a file for further processing:
shell>
mysql < batch-file > mysql.out
• You can distribute your script to other people so that they can also run the commands.
• Some situations do not allow for interactive use, for example, when you run a query from a
In this case, you must use batch mode.
The default output format is different (more concise) when you run
you use it interactively. For example, the output of
like this when
is run interactively:
mysql
+---------+
| species |
+---------+
| bird
|
| cat
|
| dog
|
| hamster |
| snake
|
+---------+
In batch mode, the output looks like this instead:
species
bird
cat
dog
hamster
snake
If you want to get the interactive output format in batch mode, use
the commands that are executed, use
You can also use scripts from the
mysql>
source filename;
Using
in Batch Mode
mysql
SELECT DISTINCT species FROM pet
mysql
-vvv.
prompt by using the
mysql
215
to execute it again.
mysql
in batch mode than when
mysql
-t. To echo to the output
mysql
command or
source
\.
job.
cron
looks
command:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents