oak-online-alter-table
NAME
oak-online-alter-table: Perform a non-blocking ALTER TABLE operationSYNOPSIS
Add an index on the Population column, City table, world database:oak-online-alter-table --database=world --table=City --alter="ADD KEY(Population)"Same as above, specify database with table name:
oak-online-alter-table --table=world.City --alter="ADD KEY(Population)"Perform multiple alters:
oak-online-alter-table --table=world.City --alter="ADD KEY(Population), MODIFY Name VARCHAR(64) CHARSET utf8 NOT NULL"Add column, drop column, modify AUTO_INCREMENT:
oak-online-alter-table --table=world.City --alter="ADD COLUMN Mayor VARCHAR(64) CHARSET utf8 DEFAULT '', DROP COLUMN district, MODIFY id SMALLINT AUTO_INCREMENT"Do not ALTER, just rebuild City:
oak-online-alter-table --database=world --table=CityCreate a ghost table called City_mirror, which is updated online from City table:
oak-online-alter-table --database=world --table=City --alter="ADD KEY(Population)" --ghost=City_mirrorPerform ALTER in chunks of 5000 rows:
oak-online-alter-table --table=world.City --alter="ADD KEY(Population)" --chunk-size=5000Perform ALTER in chunks of 5000 rows, sleep for 20 milliseconds between chunks:
oak-online-alter-table --table=world.City --alter="ADD KEY(Population)" --chunk-size=5000 --sleep=20Perform a cleanup for an aborted run:
oak-online-alter-table --database=world --table=City --cleanupProvide connection parameters. Prompt for password:
oak-online-alter-table --database=world --table=City --alter="ADD KEY(Population)" --user=root --ask-pass --socket=/tmp/mysql.sockUse a defaults file for connection parameters:
oak-online-alter-table --database=world --table=City --alter="ADD KEY(Population)" --defaults-file=/home/myuser/.my-oak.cnf
DESCRIPTION
oak-online-alter-table allows for non blocking ALTER TABLE operations, table rebuilds and creating a table's ghost. To run this utility, the following requirements must be met:- The table has at least one single-column UNIQUE KEY
- Altered table shares a single-column UNIQUE KEY with the original table
- No ‘AFTER’ triggers are defined on the table (the utility creates its own triggers for the duration of the operation)
- The table has no FOREIGN KEYs
- Table name is no longer than 57 characters
- A non blocking ALTER TABLE operation: adding columns or keys,
dropping columns or keys, modifying columns, converting table character
set etc., are all supported, under the following restrictions:
- ADD COLUMN (new column must have a default value)
- DROP COLUMN (as long as there’s still a shared single-column UNIQUE KEY between the old table and the altered one)
- MODIFY COLUMN (change type, including UNIQUE KEY columns)
- ADD KEY (normal, unique, fulltext etc.)
- DROP KEY (as long as there’s still a shared single-column UNIQUE KEY between the old table and the altered one)
- Change ENGINE: works, but great care should be taken when dealing with non-transactional engines
- Adding FOREIGN KEY constraints is possible
- More… Not all ALTERS have been tested, e.g. CONVERT, partition handling…
- An empty ALTER, which rebuilds a table: potentially releasing disk space and organizing rows in a more optimized way on disk.
- (May not be supported in future versions): Creating a live 'ghost'
table, which is synchronized with the original table, as long as the
following do not occur:
- An ALTER TABLE on the original table
- A TRUNCATE on the original table
- LOAD DATA INFILE into the original table
- OPTIMIZE on the original table
OPTIONS
-a ALTER_STATEMENT, --alter=ALTER_STATEMENT
Comma delimited ALTER statement details, excluding the
'ALTER TABLE t' itself. When this options is not used, an 'empty' ALTER
is performed, essentially rebuilding the table.
--ask-pass
Prompt for password.
-c CHUNK_SIZE, --chunk-size=CHUNK_SIZE
Number of rows to act on in chunks. Default: 1000. The
lower the number, the shorter any locks are held, but the more
operations required and the more total running time. Do not use very low
values when the PRIMARY KEY, or otherwise the only UNIQUE KEY are on
textual columns, as values from such keys are reused when working the
chunks. If you're not sure - stick with the defaults.
--cleanup
Remove custom triggers, ghost table from possible
previous runs. In case a previous run was abruptly terminated, this
option removes all custom data this utility may have created. It is not
necessary to run with this option after a normal completion.
-d DATABASE, --database=DATABASE
Database name (required unless table is fully qualified)
--defaults-file=DEFAULTS_FILE
Read from MySQL configuration file. Overrides --user, --password, --socket, --port.
Configuration needs to be in the following format:
[client]
user=my_user
password=my_pass
socket=/tmp/mysql.sock
port=3306
-g GHOST, --ghost=GHOST
user=my_user
password=my_pass
socket=/tmp/mysql.sock
port=3306
Table name to serve as ghost. When this option is
used, a table by this name is created and synchronized with the original
table. The original table is thereafter unaltered, and the three AFTER
INSERT, AFTER UPDATE and AFTER DELETE triggers are maintained. To
perform an ALTER TABLE, do not use this option. [May be removed in future versions]
-H HOST, --host=HOST
MySQL host (default: localhost)
-l, --lock-chunks
Use LOCK TABLES for each chunk. This option enforces a
higher locking mechanism, and is at current available as preparation to
be able to work with unsupported engines. It is not required nor
advisable to use this option with MyISAM or InnoDB engines. [May be removed in future versions].
-p PASSWORD, --password=PASSWORD
MySQL password
-P PORT, --port=PORT
TCP/IP port (default: 3306)
-q, --quiet
Quiet mode, do not verbose. Verbose is on by default, use this option to turn it off.
--sleep=SLEEP_MILLIS
Number of milliseconds to sleep between chunks.
Default: 0. Use a higher value if your system suffers from high load
average. The higher the value, the more time the system is allowed to
'rest', but also the longer the runtime, and the more overhead (over
time) from the triggers effect. You may also wish to set a higher number
if slaves are finding it hard otherwise to catch up.
-S SOCKET, --socket=SOCKET
MySQL socket file. Only applies when host is localhost
-t TABLE, --table=TABLE
Table with AUTO_INCREMENT column to alter (optionally
fully qualified as database_name.table_name, in which case --database is
not required)
-u USER, --user=USER
MySQL user
-v, --verbose
Print user friendly messages. Enabled by default.
No comments:
Post a Comment