Difference between revisions of "CentOS 8.x mariadb taking backup of large production databases"

From Notes_Wiki
(Created page with "<yambe:breadcrumb self="CentOS 8.x mariadb taking backup of large production databases">CentOS 8.x mariadb|CentOS 8.x mariadb</yambe:breadcrumb> =CentOS 8.x mariadb taking bac...")
 
m
 
Line 1: Line 1:
<yambe:breadcrumb self="CentOS 8.x mariadb taking backup of large production databases">CentOS 8.x mariadb|CentOS 8.x mariadb</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 8.x]] > [[CentOS 8.x database servers]] > [[CentOS 8.x mariadb]] > [[CentOS 8.x mariadb taking backup of large production databases]]
=CentOS 8.x mariadb taking backup of large production databases=


'''For small or non-production databases refer simpler [[Backing up and restoring MySQL database]]'''
'''For small or non-production databases refer simpler [[Backing up and restoring MySQL database]]'''
Line 33: Line 32:




<yambe:breadcrumb self="CentOS 8.x mariadb taking backup of large production databases">CentOS 8.x mariadb|CentOS 8.x mariadb</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 8.x]] > [[CentOS 8.x database servers]] > [[CentOS 8.x mariadb]] > [[CentOS 8.x mariadb taking backup of large production databases]]

Latest revision as of 17:28, 15 May 2022

Home > CentOS > CentOS 8.x > CentOS 8.x database servers > CentOS 8.x mariadb > CentOS 8.x mariadb taking backup of large production databases

For small or non-production databases refer simpler Backing up and restoring MySQL database

To take backup of large production databases without causing slowness on the production system (Affecting users / application) use:

mysqldump -u USER -p --single-transaction --quick --skip-lock-tables DATABASE | bzip2 > OUTPUT.sql.bz2

It makes sense to read briefs of these options from mysqldump man pages:

--single-transaction
This option sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications.
When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.
While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements: ALTER TABLE, CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT that is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.
The --single-transaction option and the --lock-tables option are mutually exclusive because LOCK TABLES causes any pending transactions to be committed implicitly.
To dump large tables, you should combine the --single-transaction option with --quick.
--quick
This option is useful for dumping large tables. It forces mysqldump to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it in memory before writing it out.
--opt
This option is shorthand. It is the same as specifying --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset. It should give you a fast dump operation and produce a dump file that can be reloaded into a MariaDB server quickly.
The --opt option is enabled by default. Use --skip-opt to disable it. See the discussion at the beginning of this section for information about selectively enabling or disabling a subset of the options affected by --opt.
--lock-tables
For each dumped database, lock all tables to be dumped before dumping them. The tables are locked with READ LOCAL to allow concurrent inserts in the case of MyISAM tables. For transactional tables such as InnoDB, --single-transaction is a much better option than --lock-tables because it does not need to lock the tables at all.
Because --lock-tables locks tables for each database separately, this option does not guarantee that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states.
Use --skip-lock-tables to disable.


Refer:



Home > CentOS > CentOS 8.x > CentOS 8.x database servers > CentOS 8.x mariadb > CentOS 8.x mariadb taking backup of large production databases