data backup
1. Backup using the mysqldumb command
mysqldump -u user -h host -p dbname[tablename ..] > filebak.sql
The user table uses the user name; host represents the login host name
(Execute mysqldump -u root -p test_db > aaa_bak.sql on the mysql server)
1.1. Backup a single table
mysqldump -u user -h host -p dbname tablename > tablebak.sql
1.2. Backup multiple libraries
mysqldump -u root -p --databases test_db1 test_db2 > db12bak.sql
1.3. Backup multiple libraries
mysqldump -u root -p --all-databases > alldbbak.sql
2. Copy the entire database directory directly
The mysql database table is saved as a file, so the directory can be copied directly. Under ubuntu, the mysql directory is under /var/lib/mysql/. However, before copying the directory, you need to execute lock tables, and then flush tables; or stop the mysql service. The latter way is safer.
But copy catalog does not work for InnoDB database tables.
3. Use the mysqlhotcopy tool to backup
This kind of library can only backup MyISAM and ARCHIVE two storage engines
In addition, the files backed up in this way cannot cross operating systems.
Data Recovery
1.mysql -u user -p dbname < dbbak.sql
2.source dbbak.sql
3.mysqlhotcopy copy directory with data backup