MYSQLFRM(1)

NAME
mysqlfrm - File reader for .frm files

SYNOPSIS

mysqlfrm [options]

DESCRIPTION

The mysqlfrm utility is designed as a recovery tool that reads .frm files and produces equivalent CREATE statements from the table definition data found in the file. In most cases, the generated CREATE statement is usable for recreating the table on another server, or for extended diagnostics. However, some features are not saved in the .frm files and therefore will be omitted. The exclusions include but are not limited to:

    • foreign key constraints

    • auto increment number sequences

The mysqlfrm utility has two modes of operation. The default mode is designed to spawn an instance of an installed server by referencing the base directory using the --basedir option, or by connecting to the server with the --server option. The process will not alter the original .frm file(s). This mode also requires the --port option to specify a port to use for the spawned server. It must be different than the port for the installed server and no other server must be using the port. The spawned server will be shutdown and all temporary files removed after the .frm files are read.

A diagnostic mode is available by using the --diagnostic option. This switches the utility to read the .frm files byte-by-byte to recover as much information as possible. The diagnostic mode has additional limitations in that it cannot decipher character set or collation values without using an existing server installation specified with either the --server or --basedir option. This can also affect the size of the columns if the table uses multibyte characters. Use this mode when the default mode cannot read the file, or if a MySQL server is not installed on the host.

To read .frm files, list each file as a separate argument for the utility as shown in the following examples. You will need to specify the path for each .frm file you want to read or supply a path to a directory and all of the .frm files in that directory will be read.

You can specify the database name to be used in the resulting CREATE statement by adding the name of the database followed by a colon to the .frm filename. For example, oltp:t1.frm will use 'oltp' for the database name in the CREATE statement. The optional database name can also be used with paths. For example, /home/me/oltp:t1.frm will use 'oltp' as the database name. If you leave off the optional database name and include a path, the last folder will be the database name. For example /home/me/data1/t1.frm will use 'data1' as the database name. If you do not want to use the last folder as the database name, simply specify the colon like this: /home/me/data1/:t1.frm. In this case, the database will be omitted from the CREATE statement. OPTIONS

    • --help

    show the program's help page

    • --license

    Display license information and exit.

    • --basedir=<basedir>

    The base directory for the server installed. Use this or --server for the default mode.

    • --diagnostic

    Turn on diagnostic mode to read .frm files byte-by-byte and generate best-effort CREATE statement.

    • --new-storage-engine=<engine>

    Set the ENGINE= option for all .frm files read.

    • --port=<port>

    The port to use for the spawned server in the default mode. Must be a free port. Required for default mode.

    • --server=<server>

    Connection information for a server. Use this option or --basedir for the default mode. If provided with the diagnostic mode, the storage engine and character set information will be validated against this server.

    To connect to a server, it is necessary to specify connection parameters such as the user name, host name, password, and either a port or socket. MySQL Utilities provides a number of ways to supply this information. All of the methods require specifying your choice via a command-line option such as --server, --master, --slave, etc. The methods include the following in order of most secure to least secure.

        • Use login-paths from your .mylogin.cnf file (encrypted, not visible). Example : <login-path>[:<port>][:<socket>]

        • Use a configuration file (unencrypted, not visible) Note: available in release-1.5.0. Example : <configuration-file-path>[:<section>]

        • Specify the data on the command-line (unencrypted, visible). Example : <user>[:<passwd>]@<host>[:<port>][:<socket>]

    • --ssl-ca

    The path to a file that contains a list of trusted SSL CAs.

    • --ssl-cert

    The name of the SSL certificate file to use for establishing a secure connection.

    • --ssl-cert

    The name of the SSL key file to use for establishing a secure connection.

    • --ssl

    Specifies if the server connection requires use of SSL. If an encrypted connection cannot be established, the connection attempt fails. Default setting is 0 (SSL not required).

    • --show-stats, -s

    Show file statistics and general table information for each .frm file read.

    • --start-timeout=<timeout_in_seconds>

    Number of seconds to wait for spawned server to start. The default is 10 seconds.

    • --user

    Execute the spawned server using this user account. Permits the execution of the utility as one user but the spawned server as another. Required if running the utility as the root user (e.g. su or sudo).

    • --quiet

    Turn off all messages for quiet execution except CREATE statements and errors.

    • --verbose, -v

    Control how much information is displayed. For example, -v = verbose, -vv = more verbose, -vvv = debug

    • --version

    Show program's version number and exit
NOTES.PP Tables with certain storage engines cannot be read in the default mode. These include PARTITION, PERFORMANCE_SCHEMA. You must read these with the --diagnostic mode.

Use the --diagnostic mode for tables that fail to open correctly in the default mode or if there is no server installed on the host.

To change the storage engine in the CREATE statement generated for all .frm files read, use the --new-storage-engine option

To turn off all messages except the CREATE statement and warnings or errors, use the --quiet option.

Use the --show-stats option to see file statistics for each .frm file.

If you need to run the utility with elevated privileges, use the --user option to execute the spawned server using a normal user account.

If you encounter connection or similar errors when running in default mode, re-run the command with the --verbose option and view the output from the spawned server and repair any errors in launching the server. If mysqlfrm fails in the middle, you may need to manually shutdown the server on the port specified with --port. EXAMPLES.PP The following example will read a single .frm file in the default mode from the current working directory using the server installed in /usr/local/bin/mysql and port 3333 for the spawned server. Notice the use of the db:table.frm format for specifying the database name for the table. The database name appears to the left of ':' and the .frm name to the right. In this case, we have database = test1 and table = city, so the CREATE statement reads CREATE TABLE test1.city.

    shell> mysqlfrm --basedir=/usr/local/bin/mysql test1:city.frm --port=3333
    # Starting the spawned server on port 3333 ... done.
    # Reading .frm files
    #
    # Reading the city.frm file.
    #
    # CREATE statement for city.frm:
    #
    CREATE TABLE `test1`.`city` (
      `city_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
      `city` varchar(50) NOT NULL,
      `country_id` smallint(5) unsigned NOT NULL,
      `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`city_id`),
      KEY `idx_fk_country_id` (`country_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    #...done.

The following demonstrates reading multiple .frm files in the default mode using a running server. The .frm files are located in different folders. Notice the use of the database name option for each of the files. The t1 file was given the database name temp1 since that is the folder in which it resides, t2 was given db1 since that was specified in the path, and t3 was not given a database name since we used the ':' without providing a database name.

    shell> mysqlfrm --server=root:pass@localhost:3306 /mysql/data/temp1/t1.frm \
              /mysql/data/temp2/db1:t2.frm --port=3310
    # Starting the spawned server on port 3333 ... done.
    # Reading .frm files
    #
    #
    # Reading the t1.frm file.
    #
    # CREATE statement for ./mysql-test/std_data/frm_files/t1.frm:
    #
    CREATE TABLE `temp1`.`t1` (
      `a` int(11) DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    # Reading the t2.frm file.
    #
    # CREATE statement for ./mysql-test/std_data/frm_files/t2.frm:
    #
    CREATE TABLE `db1`.`t2` (
      `a` int(11) DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    #
    # Reading the t3.frm file.
    #
    # CREATE statement for ./mysql-test/std_data/frm_files/t3.frm:
    #
    CREATE TABLE `t3` (
      `a` int(11) DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    #...done.

The following demonstrates running the utility in diagnostic mode to read all of the .frm files in a directory.

    shell> mysqlfrm --diagnostic /mysql/data/sakila
    # WARNING: Cannot generate character set or collation names without the --server option.
    # CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
    # Reading .frm file for /mysql/data/sakila/city.frm:
    # The .frm file is a TABLE.
    # CREATE TABLE Statement:
    CREATE TABLE `city` (
      `city_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
      `city` varchar(150) NOT NULL,
      `country_id` smallint(5) unsigned NOT NULL,
      `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY `PRIMARY` (`city_id`),
    KEY `idx_fk_country_id` (`country_id`)
    ) ENGINE=InnoDB;
    #...done.

PERMISSIONS REQUIRED.PP The permissions for using mysqlfrm will vary and depend entirely on how you use it. If you use the utility to read .frm files in a protected folder like the example above (in either mode), you must have the ability to run the spawned server with privileges that allow you to read the protected files. For example, you could use a user account that has root-level privileges.

If you use the utility with a server connection, the user you use to connect must have the ability to read system variables at a minimum including read access to the mysql database.

    Note

    You should never use the root user to spawn the server nor should you use the mysql user when spawning the server or running the utility.

COPYRIGHT

Copyright © 2006, 2016, Oracle and/or its affiliates. All rights reserved.

This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/.

SEE ALSO
For more information, please refer to the MySQL Utilities and Fabric documentation, which is available online at http://dev.mysql.com/doc/index-utils-fabric.html

AUTHOR
Oracle Corporation (http://dev.mysql.com/).