So I'm hacking around with the latest stable MySQL, my first time trying to use this.

Install went flawless, services are cranking in Win 2000, used mysql.exe (monitor program I think it is called) to make myself a test database, made a table, looked up the command to suck in a delimited text file to get me some data to play with, all without a hitch.

Then I yearned for automating some tasks. I'm sure this is a stupid question, but before I throw Perl or other scripting langs in the mix, I wanted to start with baby steps.

I have a text file with some commands that contains the following lines:

USE products;
SHOW TABLES;
SHOW COLUMNS FROM products;
SELECT * FROM buoys;

I can get into mysql and type

mysql> source c:/mysql/scripts/display.sql

The output from the command file processes and appears as expected... life is good...type exit and bye.

Now, I would like to call mysql from the command line (or a batch file), and have it pipe the display.sql as an argument into the source command for me.

mysql --help shows the following command that looks promising:

-e, Execute command and quit. (Output like with --batch)

So, I try to do the following right from the command line to kick this thing off automatically:

C:\mysql\bin>mysql -e source c:/mysql/scripts/display.sql

Alas, I get the following error:

ERROR 1102: Incorrect database name 'c:/mysql/scripts/display.sql'

Huh, the argument for -e is a command that you could have typed yourself in mysql> prompt, isn't it? I tried enclosing the source c:/mysql/scripts/display.sql in quotes in case the space between source and c:/ was throwing off the command-line parameters for mysql.

Can anyone shed some light on auto-executing a file full of commands for mysql monitor?

Any help would be appreciated.

Also, I would swear there was a MySQL site I was browsing that had a specific forum for Win32 Help, but I guess it never made it to my bookmarks list because I can't find it tonight. I would have posted this question there, so as not to bother any of you 'nix only folks.

Thanks,

Tormentor

    I gave up and posted this question here and on DevShed too fast....found the answer in an old GeoCrawler question by looking through Google responses.

    DUH....So, it is double quotes instead of single, or none.

    mysql -e"source c:/mysql/scripts/display.sql"

    works where

    mysql -e'source c:/mysql/scripts/display.sql'

    or

    mysql -e source c:/mysql/scripts/display.sql

    just doesn't cut it.

    Thanks,

    Tormentor

      mysql < c:/mysql/scripts/display.sql

      works too

        Write a Reply...