DOSQL.PL - Front end to Invoke the MySQL Shells

Download this program

SYNOPSIS

  dosql.pl
  dosql.pl mydb   # Override default realm database with 'mydb'
  dosql.pl -cmd 'select count(*) from cars' mydb
  dosql.pl -cmd "select name from cars where model='chevy'" mydb
  dosql.pl -read inrealm 
  dosql.pl -read inrealm mydb


SYNOPSIS for mysqlshow command


  dosql.pl -mysqlshow           # Show tables in database
  dosql.pl -mysqlshow  payroll  # Describe table payroll
  dosql.pl -mysqlshow -read inrealm [mysqlshow parameters]


DESCRIPTION

This program provides a convenient way to invoke the MySQL shells (e.g. /usr/bin/mysql or /usr/bin/mysqlshow).

It makes use of 'realm' files to get the database connection information. This provides a nice way to avoid the prompt for a password.

Realize, however, that the MySQL shell command line contains your password in clear text and it is possible your password can be seen. Recent versions of the MySQL shell attempt to mask your password to avoid this issue. Depending on your installation, this may or may not be reasonably secure.


REALMS

This program takes advantage of realm files from DBIx::Connector to find the database connection information. You do not, however, need to have this Perl module installed. Rather, just create the directory $HOME/.db_connactions and create the realm files with your favorite text editor. The format of these is quite simple as you can see from this example:

  ~> cd .db_connections/
  ~/.db_connections> cat test
  DBD=mysql
  SERVER=host=ourdhhost.my.company.com
  USER=readonly
  PASS=readable
  DATABASE=payroll


OPTIONS

-cmd SQL-command

Specifies an optional command of SQL to be executed by the shell. If this is specified, the shell will exit upon completion of the command. Your command may use single or double quotes.

-help

Generates this output.

-mysqlopts string

Specifies addition options to be passed to the shell. See 'man mysql' or 'man mysqlshow' (if you specify -mysqlshow) for details.

-mysqlshow

Specifies you want to execute the mysqlshow command and not the default, mysql.

-nopass

If specified this will avoid inserting your password in the command to be executed. This is always the most secure mode. It will cause the MySQL shell to prompt you for a password.

-realm NAME

Specifies the realm name to be used. It defaults to the userid executing this command.

-verbose

If specified this will show you the command to be executed. It will not execute the MySQL shell.


PARAMETERS for mysql shell

[database]

This is the optional name of the database to be used. If you do not specify a database, the database associated with the realm will be used. If you do provide this, this value overrides whatever DATABASE is specified the realm file.


PARAMETERS for mysqlshow command

[database] [table]] [column]]]

These are the parameters expected by mysqlshow. These fields are optional. See 'man mysqlshow' for more details on the behavior of mysqlshow.


EXIT

If no fatal errors are detected, the program exits with a return code of 0. Any error will set a non-zero return code.


AUTHOR

Written by Terry Gliedt <tpg@hps.com> in 2006-2008 and is copyrighted (C) by Terry Gliedt.