MySQL dump Partition and import partition:
$ mysqldump --user=root --password=<code> \
-S/mysql/<db_name>/data/<db_name>.sock --set-gtid-purged=OFF --no-create-info \
<db_name> <table_name>--where="datetime between 'YYYY-MM-DD' and 'YYYY-MM-DD'" \
> /mysql/backup/<partition_name>.sql
Where data type is bigint for partition, it will dump DDL for table also:
$ mysqldump -uroot -p -S/mysql/mysql.sock --set-gtid-purged=OFF \
<db_name> <table_name> --where="ENDDATE" between '20200801000000' and '20201101000000' \
> /mysql/dump/<schema_name>.<table_name>.sql
Alter table and add partitions which are truncated:
Note: In following case partition 2018_MAY and 2018_JUN were truncated, so we need to reorganize the partition which is just after the desired partition.
ALTER TABLE <table_name> REORGANIZE
PARTITION 2018_JUL INTO
(
PARTITION 2018_MAY VALUES LESS THAN ('2018-06-01'),
PARTITION 2018_JUN VALUES LESS THAN ('2018-07-01'),
PARTITION 2018_JUL VALUES LESS THAN ('2018-08-01')
);
mysql> SHOW CREATE TABLE <db_anme>.<table_name>;
mysql> select table_name, partition_name, table_rows from information_schema.partitions where table_schema='<db_name>' and table_name like '<table_name>' order by table_rows desc;
Restore the data:
mysql> mysql -u root -p<code> -S/mysql/<db_name>/data/<db_name>.sock \
<db_name> < /mysql/backup/<partition_name>.sql
Ref. :
Comments
Post a Comment