DOSQL.PL - Front end to Invoke the MySQL Shells

Download this program

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

SYNOPSIS for mysqlshow command -mysqlshow           # Show tables in database -mysqlshow  payroll  # Describe table payroll -mysqlshow -read inrealm [mysqlshow parameters]


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.


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


-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.


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.


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


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.


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

PARAMETERS for mysql shell


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.


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


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