DOSQLCLONE.PL - Clone a MySQL table from one database to another

Download this program

SYNOPSIS

  dosqlclone.pl cars  savecars
  dosqlclone.pl mydb cars yourdb =
  dosqlclone.pl mydb cars = savecars
  dosqlclone.pl mydb cars yourdb savecars


DESCRIPTION

This program allows you to clone a table from one MySQL database to another. You can optionally change the name of the table that is created.

You must always provide the table name to be cloned and the name of the table to be created. The default input database is that associated with the option -inrealm (same as your userid). The default output database is that associated with -outrealm (same as your userid). Thus the minimal command is:

dosqlclone.pl cars savecars

which copies the table 'cars' from the database associated with a realm equal to your userid to the same database and renames the table as 'savecars'.

dosqlclone.pl mydb cars yourdb =

copies the table 'cars' from the database 'mydb' using the access associated with a realm equal to your userid to the database 'yourdb' as 'cars'.

dosqlclone.pl mydb cars yourdb savecars

copies the table 'cars' from the database 'mydb' using the access associated with a realm equal to your userid to the database 'yourdb' as 'savecars'.

Use the -inrealm and -outrealm options to control the realms associated with the input and output database.


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

-dumponly

Specifies the dump file should be viewed with your default editor (i.e. the program from your environment variable EDITOR. If you want to save this file for debugging, you can copy or save it elsewhere.

-help

Generates this output.

-inrealm name

Specifies the realm name to be used for reading the table. This defaults to the userid executing this command.

-nopasswd

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.

-noprompt

Specifies you do not want to be prompted to confirm the table cloning. The default is to ask the user to confirm the action to be taken.

-outrealm name

Specifies the realm name to be used for write the new table. This 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 commands.


PARAMETERS

[indatabase]

Specifies the name of the input database. If this field is not provided, the database associated with the option -inrealm will be used.

intable

Specifies the name of the input table to be cloned. This field is required.

[outdatabase]

Specifies the name of the output database. If this field is not provided, the database associated with the option -outrealm will be used. You may use '=' to mean the same as indatabase.

outtable

Specifies the name of the output table to be created. You may use '=' to mean the same as intable. This field is required.


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.