Mysql four common backup table methods, history table

1. Backup the table to a physical machine

mysqldump -h domain name -P port -u user -p password library name table name> /path/table name.{$date}.bak

2. Backup the table in the library (create copy table structure, insert copy table content)

create table one_bak like one; copy table structure
insert into one_bak select * from one; copy table content

3. Backup the table in the library (create table as backup)

Note: The difference from the 2-step backup in the library is that the as backup table will not back up the primary key and foreign key, but only the table data

create table one_bak as select * from one;

4. Everyone knows that log files have the attribute of "only appending and not modifying". The history table is similar to log files and also has this attribute.
At the same time, like the log file, the history table also has the characteristics of "sequential read" and "random read", so sometimes some indexes are added to the history table.
So here comes the question: as time goes by, more and more data in the history table will make its "append write" performance worse and worse, so what should we do now?

One of the methods is history table hot backup

1. Add a new table (empty table) according to the original history table:
mysql> show create table history_log\G
mysql> create table history_log_new ...;

2. Rename the history table and rename the new table to history table:
mysql> RENAME TABLE history_log to history_log_bak_20230717, history_log_new to history_log;

 


If this article is helpful to you, I am very happy to help you.

Of course, if you think there is something in the article that makes you feel unreasonable, or there is an easier way to implement it, or there is something you don’t understand, I hope you can point it out in the comments after reading it, and I will read it as soon as possible reply you.

Guess you like

Origin blog.csdn.net/chenthe1/article/details/131713019