Sao lưu bảng có thể thực hiện bằng tiện ích mysqldump (khuyến nghị) hoặc lệnh BACKUP TABLE (chỉ dành cho MySQL 5.0 và cũ hơn).
Sao lưu với mysqldump
- Mở Command Prompt (Win + R, gõ
cmd). - Điều hướng đến thư mục
bincủa MySQL, ví dụ:C:\Program Files\MySQL\MySQL Server 8.0\bin
- Chạy lệnh sao lưu:
mysqldump -u Manish -p business student < E:\student.sql Enter password: ***********
Kết quả đầu ra (rút gọn)
-- MySQL dump 10.13 Distrib 8.0.12, for Win64 (x86_64) -- Host: localhost Database: business -- Server version 8.0.12 SET NAMES utf8mb4; -- Table structure for table `student` DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `id` INT(11) DEFAULT NULL, `Name` VARCHAR(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, KEY `NameStuIndex` (`Name`), KEY `idIndex` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Dumping data for table `student` LOCK TABLES `student` WRITE; INSERT INTO `student` VALUES (1,'John'),(2,'Bob'); UNLOCK TABLES; -- Dump completed on 2018-10-03 10:30:58
File student.sql giờ chứa cả cấu trúc và dữ liệu của bảng student.