<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    App::MysqlUtils - CLI utilities related to MySQL

VERSION
    This document describes version 0.014 of App::MysqlUtils (from Perl
    distribution App-MysqlUtils), released on 2018-12-27.

SYNOPSIS
    This distribution includes the following CLI utilities:

FUNCTIONS
  mysql_copy_rows_adjust_pk
    Usage:

     mysql_copy_rows_adjust_pk(%args) -&gt; [status, msg, payload, meta]

    Copy rows from one table to another, adjust PK column if necessary.

    This utility can be used when you have rows in one table that you want
    to insert to another table, but the PK might clash. When that happens,
    the value of the other columns are inspected. When all the values of the
    other columns match, the row is assumed to be a duplicate and skipped.
    If some values of the other column differ, then the row is assumed to be
    different and a new value of the PK column is chosen (there are several
    choices on how to select the new PK).

    An example:

     % mysql-copy-rows-adjust-pk db1 --from t1 --to t2 --pk-column id --adjust "add 1000"

    Suppose these are the rows in table "t1":

     id    date                 description        user
     --    ----                 -----------        ----
      1    2018-12-03 12:01:01  Created user u1    admin1
      2    2018-12-03 12:44:33  Removed user u1    admin1

    And here are the rows in table "t2":

     id    date                 description        user
     --    ----                 -----------        ----
      1    2018-12-03 12:01:01  Created user u1    admin1
      2    2018-12-03 13:00:45  Rebooted machine1  admin1
      3    2018-12-03 13:05:00  Created user u2    admin2

    You can see that row id=1 in both tables are identical. This will be
    skipped. On the other hand, row id=2 in "t1" is different with row id=2
    in "t2". This row will be adjusted: "id" will be changed to 2+1000=1002.
    So the final rows in table "t2" will be (sorted by date):

     id    date                 description        user
     --    ----                 -----------        ----
      1    2018-12-03 12:01:01  Created user u1    admin1
      1002 2018-12-03 12:44:33  Removed user u1    admin1
      2    2018-12-03 13:00:45  Rebooted machine1  admin1
      3    2018-12-03 13:05:00  Created user u2    admin2

    So basically this utility is similar to MySQL's INSERT ... ON DUPLICATE
    KEY UPDATE, but will avoid inserting identical rows.

    If the adjusted PK column clashes with another row in the target table,
    the row is skipped.

    This function is not exported.

    This function supports dry-run operation.

    Arguments ('*' denotes required arguments):

    *   adjust* =&gt; *str*

        How to adjust the value of the PK column.

        Currently the choices are:

        *   "add N" add N to the original value.

        *   "subtract N" subtract N from the original value.

    *   database* =&gt; *str*

    *   from* =&gt; *str*

        Name of source table.

    *   host =&gt; *str* (default: "localhost")

    *   password =&gt; *str*

        Will try to get default from "~/.my.cnf".

    *   pk_column* =&gt; *str*

        Name of PK column.

    *   port =&gt; *int* (default: 3306)

    *   to* =&gt; *str*

        Name of target table.

    *   username =&gt; *str*

        Will try to get default from "~/.my.cnf".

    Special arguments:

    *   -dry_run =&gt; *bool*

        Pass -dry_run=&gt;1 to enable simulation mode.

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_drop_all_tables
    Usage:

     mysql_drop_all_tables(%args) -&gt; [status, msg, payload, meta]

    Drop all tables in a MySQL database.

    For safety, the default is dry-run mode. To actually drop the tables,
    you must supply "--no-dry-run" or DRY_RUN=0.

    This function is not exported.

    This function supports dry-run operation.

    Arguments ('*' denotes required arguments):

    *   database* =&gt; *str*

    *   host =&gt; *str* (default: "localhost")

    *   password =&gt; *str*

        Will try to get default from "~/.my.cnf".

    *   port =&gt; *int* (default: 3306)

    *   username =&gt; *str*

        Will try to get default from "~/.my.cnf".

    Special arguments:

    *   -dry_run =&gt; *bool*

        Pass -dry_run=&gt;1 to enable simulation mode.

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_drop_dbs
    Usage:

     mysql_drop_dbs(%args) -&gt; [status, msg, payload, meta]

    Drop MySQL databases.

    For safety, the default is dry-run mode. To actually drop the databases,
    you must supply "--no-dry-run" or DRY_RUN=0.

    Examples:

     # Drop dbs D1, D2, D3 (dry-run mode)
     % mysql-drop-dbs D1 D2 D3
 
     # Drop all dbs with names matching /^testdb/ (dry-run mode)
     % mysql-drop-dbs --db-pattern ^testdb
 
     # Actually drop all dbs with names matching /^testdb/, don't delete more than 5 dbs
     % mysql-drop-dbs --db-pattern ^testdb --limit 5 --no-dry-run

    This function is not exported.

    This function supports dry-run operation.

    Arguments ('*' denotes required arguments):

    *   db_pattern =&gt; *re*

    *   dbs =&gt; *array[str]*

    *   host =&gt; *str* (default: "localhost")

    *   limit =&gt; *posint*

        Don't delete more than this number of databases.

    *   password =&gt; *str*

        Will try to get default from "~/.my.cnf".

    *   port =&gt; *int* (default: 3306)

    *   username =&gt; *str*

        Will try to get default from "~/.my.cnf".

    Special arguments:

    *   -dry_run =&gt; *bool*

        Pass -dry_run=&gt;1 to enable simulation mode.

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_drop_tables
    Usage:

     mysql_drop_tables(%args) -&gt; [status, msg, payload, meta]

    Drop tables in a MySQL database.

    For safety, the default is dry-run mode. To actually drop the tables,
    you must supply "--no-dry-run" or DRY_RUN=0.

    Examples:

     # Drop table T1, T2, T3 (dry-run mode)
     % mysql-drop-tables DB T1 T2 T3
 
     # Drop all tables with names matching /foo/ (dry-run mode)
     % mysql-drop-tables DB --table-pattern foo
 
     # Actually drop all tables with names matching /foo/, don't delete more than 5 tables
     % mysql-drop-tables DB --table-pattern foo --limit 5 --no-dry-run

    This function is not exported.

    This function supports dry-run operation.

    Arguments ('*' denotes required arguments):

    *   database* =&gt; *str*

    *   host =&gt; *str* (default: "localhost")

    *   limit =&gt; *posint*

        Don't delete more than this number of tables.

    *   password =&gt; *str*

        Will try to get default from "~/.my.cnf".

    *   port =&gt; *int* (default: 3306)

    *   table_pattern =&gt; *re*

    *   tables =&gt; *array[str]*

    *   username =&gt; *str*

        Will try to get default from "~/.my.cnf".

    Special arguments:

    *   -dry_run =&gt; *bool*

        Pass -dry_run=&gt;1 to enable simulation mode.

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_find_identical_rows
    Usage:

     mysql_find_identical_rows(%args) -&gt; [status, msg, payload, meta]

    List rows on one table that are identical on another table.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   database* =&gt; *str*

    *   exclude_columns =&gt; *array[str]*

        What column(s) to exclude from comparison.

    *   host =&gt; *str* (default: "localhost")

    *   password =&gt; *str*

        Will try to get default from "~/.my.cnf".

    *   port =&gt; *int* (default: 3306)

    *   return_column* =&gt; *str*

        What column to return.

    *   t1* =&gt; *str*

        Name of the first table.

    *   t2* =&gt; *str*

        Name of the second table.

    *   username =&gt; *str*

        Will try to get default from "~/.my.cnf".

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_query
    Usage:

     mysql_query(%args) -&gt; [status, msg, payload, meta]

    Run query and return table result.

    This is like just regular querying, but the result will be returned as
    table data (formattable using different backends). Or, you can output as
    JSON.

    Examples:

     # by default, show as pretty text table, like in interactive mysql client
     % mysql-query DBNAME "SELECT * FROM t1"
 
     # show as JSON (array of hashes)
     % mysql-query DBNAME "QUERY..." --json ;# or, --format json
 
     # show as CSV
     % mysql-query DBNAME "QUERY..." --format csv
 
     # show as CSV table using Text::Table::CSV
     % FORMAT_PRETTY_TABLE_BACKEND=Text::Table::Org mysql-query DBNAME "QUERY..."

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   add_row_numbers =&gt; *bool*

        Add first field containing number from 1, 2, ...

    *   database* =&gt; *str*

    *   host =&gt; *str* (default: "localhost")

    *   password =&gt; *str*

        Will try to get default from "~/.my.cnf".

    *   port =&gt; *int* (default: 3306)

    *   query* =&gt; *str*

    *   username =&gt; *str*

        Will try to get default from "~/.my.cnf".

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_run_pl_files
    Usage:

     mysql_run_pl_files(%args) -&gt; [status, msg, payload, meta]

    Run each .pl file, feed the output to `mysql` command and write result
    to .txt file.

    The ".pl" file is supposed to produce a SQL statement. For simpler
    cases, use mysql-run-sql-files.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   database* =&gt; *str*

    *   directory =&gt; *dirname* (default: ".")

        Specify directory for the resulting *.txt files.

    *   mkdir =&gt; *true* (default: 1)

        Create output directory if not exists.

    *   overwrite_when =&gt; *str* (default: "none")

        Specify when to overwrite existing .txt file.

        "none" means to never overwrite existing .txt file. "older"
        overwrites existing .txt file if it's older than the corresponding
        .sql file. "always" means to always overwrite existing .txt file.

    *   pl_files* =&gt; *array[filename]*

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_run_sql_files
    Usage:

     mysql_run_sql_files(%args) -&gt; [status, msg, payload, meta]

    Feed each .sql file to `mysql` command and write result to .txt file.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   database* =&gt; *str*

    *   directory =&gt; *dirname* (default: ".")

        Specify directory for the resulting *.txt files.

    *   mkdir =&gt; *true* (default: 1)

        Create output directory if not exists.

    *   overwrite_when =&gt; *str* (default: "none")

        Specify when to overwrite existing .txt file.

        "none" means to never overwrite existing .txt file. "older"
        overwrites existing .txt file if it's older than the corresponding
        .sql file. "always" means to always overwrite existing .txt file.

    *   sql_files* =&gt; *array[filename]*

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

  mysql_sql_dump_extract_tables
    Usage:

     mysql_sql_dump_extract_tables(%args) -&gt; [status, msg, payload, meta]

    Parse SQL dump and spit out tables to separate files.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   dir =&gt; *dirname*

        Directory to put the SQL files into.

    *   exclude_table_patterns =&gt; *array[re]*

    *   exclude_tables =&gt; *array[str]*

    *   include_table_patterns =&gt; *array[re]*

    *   include_tables =&gt; *array[str]*

    *   overwrite =&gt; *bool*

    *   stop_after_table =&gt; *str*

    *   stop_after_table_pattern =&gt; *re*

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (payload) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

    Return value: (any)

HOMEPAGE
    Please visit the project's homepage at
    &lt;https://metacpan.org/release/App-MysqlUtils&gt;.

SOURCE
    Source repository is at
    &lt;https://github.com/perlancar/perl-App-MysqlUtils&gt;.

BUGS
    Please report any bugs or feature requests on the bugtracker website
    &lt;https://rt.cpan.org/Public/Dist/Display.html?Name=App-MysqlUtils&gt;

    When submitting a bug or request, please include a test-file or a patch
    to an existing test-file that illustrates the bug or desired feature.

SEE ALSO
AUTHOR
    perlancar &lt;perlancar@cpan.org&gt;

COPYRIGHT AND LICENSE
    This software is copyright (c) 2018, 2017, 2016 by perlancar@cpan.org.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

</pre></body></html>