MySQL Tutorial
MySQL Installation and Configuration
MySQL Database Operations
Database Design
MySQL Data Types
MySQL Storage Engines
MySQL Basic Operations of Tables
MySQL Constraints
MySQL Operators
MySQL Function
MySQL Manipulate Table Data
MySQL View
MySQL Indexes
MySQL Stored Procedure
MySQL Trigger
MySQL Transactions
MySQL Character Set
MySQL User Management
MySQL Database Backup and Recovery
MySQL Log
MySQL Performance Optimization
For a MySQL cold backup, you need to copy the entire data directory, which contains the files for databases and tables. The following files and directories are included in the data directory:
Database directories: Each database has its own directory within the data directory, named after the database. Inside each directory, you will find files related to tables, indexes, and metadata. The default database directories include mysql
, performance_schema
, and information_schema
, along with any user-created databases.
Table files (MYD, MYI, and frm files): For MyISAM storage engine tables, there are three types of files:
.MYD
(MyISAM Data): Contains the data stored in the table.MYI
(MyISAM Index): Contains the indexes for the table.frm
(Format): Contains the table structure and metadataInnoDB files:
ibdata1
: Contains the InnoDB system tablespace, which includes data and indexes for InnoDB tables, as well as the InnoDB data dictionary and undo logs.ib_logfile0
and ib_logfile1
: InnoDB redo log files that store changes made to the database. These files help maintain data consistency and are used for crash recovery.ib_buffer_pool
: (Optional) Contains the InnoDB buffer pool dump file, if it is enabled in the configuration.Table files for InnoDB (idb and frm files): For InnoDB storage engine tables, there are two types of files:
.ibd
: Contains the data and indexes for the table, if using file-per-table tablespaces.frm
(Format): Contains the table structure and metadataConfiguration and log files: Although not strictly required for a cold backup, you may want to back up the configuration file (my.cnf
on Linux or my.ini
on Windows) and any relevant log files, such as the binary log, general query log, slow query log, and error log.
When performing a cold backup, it's important to include all the files and directories mentioned above to ensure a successful restoration of the MySQL instance. Note that the specific files present may depend on the MySQL version, storage engine(s) used, and configuration settings.
Backup files generated by mysqldump in MySQL:
mysqldump -u username -p dbname > backup.sql
Copying MySQL data files for cold backup:
cp -r /var/lib/mysql /backup/location
MySQL binary logs and cold backup:
cp -r /var/lib/mysql/binlog /backup/location
Backing up MySQL configuration files in a cold backup:
my.cnf
) in the backup:cp /etc/mysql/my.cnf /backup/location
MySQL tablespace files and cold backup:
.ibd
) in the backup:cp /var/lib/mysql/dbname/*.ibd /backup/location
InnoDB files required for MySQL cold backup:
cp /var/lib/mysql/ibdata* /backup/location cp /var/lib/mysql/ib_logfile* /backup/location
Restoring MySQL from physical cold backup files:
cp -r /backup/location /var/lib/mysql