Description\n-----------\n\nBACKUP LOCK blocks a table from DDL statements. This is mainly intended to be used by tools like mariadb-backup that need to ensure there are no DDL[^1] statements on a table while the table files are opened. For example, for an Aria table that stores data in 3 files with extensions .frm, .MAI and .MAD. Normal read/write operations can continue as normal.\n\nSyntax\n\nTo lock a table:\n\n``sql\nBACKUP LOCK table_name\n`\n\nTo unlock a table:\n\n`sql\nBACKUP UNLOCK\n`\n\nUsage in a Backup Tool\n\n`sql\nBACKUP LOCK [database.]table_name;\n - Open all files related to a table (for example, t.frm, t.MAI and t.MYD)\nBACKUP UNLOCK;\n- Copy data\n- Close files\n`\n\nThis ensures that all files are from the same generation, that is created at the same time by the MariaDB server. This works, because the open files will point to the original table files which will not be affected if there is any ALTER TABLE while copying the files.\n\nPrivileges\n\nBACKUP LOCK requires the database LOCK TABLES privileges.\n\nBACKUP LOCK requires the RELOAD privilege.\n\nBACKUP LOCK requires the RELOAD privilege.\n\nNotes\n\n The idea is that the BACKUP LOCK should be held for as short a time as possible by the backup tool. The time to take an uncontested lock is very short! One can easily do 50,000 locks/unlocks per second on low end hardware.\n One should use different connections for BACKUP STAGE commands and BACKUP LOCK.\n\nImplementation\n\n* Internally, BACKUP LOCK is implemented by taking an MDLSHARED_HIGH_PRIO` MDL lock on the table object, which protects the table from any DDL operations.\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/backup-commands/backup-lock