[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mysql and Windows Script

Posted on 2005-04-19
3
Medium Priority
?
318 Views
Last Modified: 2012-05-05
here my bat file:

C:\mysql\bin>type cb.bat
c:\mysql\bin\mysql < cb.sql %1 %2 %3 %4

here the cb.file:

C:\mysql\bin>type cb.sql
create database %1;
grant all privileges on %1.* to '%2'@'%3' identified by '%4';
flush privileges;

i type: cb colector root 192.168.0.35 linuxx but say me some errors see:

C:\mysql\bin>cb colector root 192.168.0.35 linuxx

C:\mysql\bin>c:\mysql\bin\mysql  colector root 192.168.0.35 linuxx 0<cb.sql
c:\mysql\bin\mysql  Ver 11.18 Distrib 3.23.55, for Win95/Win98 (i32)
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Usage: c:\mysql\bin\mysql [OPTIONS] [database]

  -?, --help            Display this help and exit.
  -A, --no-auto-rehash  No automatic rehashing. One has to use 'rehash' to
                        get table and field completion. This gives a quicker
                        start of mysql and disables rehashing on reconnect.
  -B, --batch           Print results with a tab as separator, each row on
                        a new line. Doesn't use history file.
  --character-sets-dir=...
                        Directory where character sets are located.
  -C, --compress        Use compression in server/client protocol.
  -D, --database=..     Database to use.
  --default-character-set=...
                        Set the default character set.
  -e, --execute=...     Execute command and quit. (Output like with --batch)
  -E, --vertical        Print the output of a query (rows) vertically.
  -f, --force           Continue even if we get an sql error.
  -g, --no-named-commands
                        Named commands are disabled. Use \* form only, or
                        use named commands only in the beginning of a line
                        ending with a semicolon (;) Since version 10.9 the
                        client now starts with this option ENABLED by
                        default! Disable with '-G'. Long format commands
                        still work from the first line.
  -G, --enable-named-commands
                        Named commands are enabled. Opposite to -g.
  -i, --ignore-spaces   Ignore spaces after function names.
  -h, --host=...        Connect to host.
  -H, --html            Produce HTML output.
  --local-infile=[1|0]  Enable/disable LOAD DATA LOCAL INFILE
  -L, --skip-line-numbers
                        Don't write line number for errors.
  --no-tee              Disable outfile. See interactive help (\h) also.
  -n, --unbuffered      Flush buffer after each query.
  -N, --skip-column-names
                        Don't write column names in results.
  -O, --set-variable var=option
                        Give a variable an value. --help lists variables.
  -o, --one-database    Only update the default database. This is useful
                        for skipping updates to other database in the update
                        log.
  -p[password], --password[=...]
                        Password to use when connecting to server
                        If password is not given it's asked from the tty.
  -W, --pipe            Use named pipes to connect to server

  -P, --port=...        Port number to use for connection.
  -q, --quick           Don't cache result, print it row by row. This may
                        slow down the server if the output is suspended.
                        Doesn't use history file.
  -r, --raw             Write fields without conversion. Used with --batch
  -s, --silent          Be more silent.
  -S  --socket=...      Socket file to use for connection.
  -t, --table           Output in table format.
  -T, --debug-info      Print some debug info at exit.
  --tee=...             Append everything into outfile. See interactive help
                        (\h) also. Does not work in batch mode.
  -u, --user=#          User for login if not current user.
  -U, --safe-updates[=#], --i-am-a-dummy[=#]
                        Only allow UPDATE and DELETE that uses keys.
  -v, --verbose         Write more. (-v -v -v gives the table output format)
  -V, --version         Output version information and exit.
  -w, --wait            Wait and retry if connection is down.

Default options are read from the following files in the given order:
C:\WINDOWS\my.ini C:\my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit
--no-defaults           Don't read default options from any options file
--defaults-file=#       Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read

Possible variables for option --set-variable (-O) are:
connect_timeout       current value: 0
max_allowed_packet    current value: 16777216
net_buffer_length     current value: 16384
select_limit          current value: 1000
max_join_size         current value: 1000000

C:\mysql\bin>



any advice??? thanks
0
Comment
Question by:jamiguel
1 Comment
 
LVL 22

Accepted Solution

by:
JesterToo earned 200 total points
ID: 13892120
There are 2 problems with the way you're trying to do this...

1.  The format of this line is incorrect:   c:\mysql\bin\mysql < cb.sql %1 %2 %3 %4
 
     It should look like this:  c:\mysql\bin\mysql --database=%1  --user=%2  %3  --password=%4  < cb.sql

2.  There isn't any facility present in "mysql.exe" to substitute symbols into the sql script... i.e. the %n mechanism is a Command Shell feature, not a mysql.exe feature.

The equvalent of what you're trying to do would be fairly trivial to code in VBScript (or just about any other scripting language). however.  It's a bit less trivial (the code is longer but not more complex) to support oarameter values that might have embedded spaces within them.

If you're interested in pursuing that option just let me know... earlier today I created a VBScript to create two tables with a FK relationship between them and populate both tables from two text files.  The code was about 100 lines including comments and blank lines to increase readability.  There were no command line parameters and no "parameter substitution logic" in it and that might add another 50-100 lines of code to it.

Additinally, there might be another utility with "parameter substitution" features freely available on the web.

HTH,
Lynn
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 article, we’ll look at how to deploy ProxySQL.
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…
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 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