next up previous contents
Next: 匯出資料庫 Up: Export 匯出 Previous: 匯出到檔案   Contents

匯出 Raw Data

  1. 使用 mysqldump 命令匯出 Raw Data 並導向到檔案 dump.txt。
    [root@kvm8 ~]# mysqldump -uroot -p123qwe dyw animals > dump.txt
    
  2. 查看 mysqldump 命令匯出的 Raw Data 檔 dump.txt。
    [root@kvm8 ~]# cat dump.txt 
    -- MySQL dump 10.13  Distrib 5.5.38, for Linux (x86_64)
    --
    -- Host: localhost    Database: dyw
    -- ------------------------------------------------------
    -- Server version	5.5.38
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
    /*!40103 SET TIME_ZONE='+00:00' */;
    /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
    
    --
    -- Table structure for table `animals`
    --
    
    DROP TABLE IF EXISTS `animals`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `animals` (
      `id` int(10) unsigned NOT NULL DEFAULT '0',
      `name` varchar(20) NOT NULL,
      `foot` tinyint(3) unsigned NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `animals`
    --
    
    LOCK TABLES `animals` WRITE;
    /*!40000 ALTER TABLE `animals` DISABLE KEYS */;
    INSERT INTO `animals` VALUES (2,'cat',4),(3,'chicken',2),(1,'dog',4);
    /*!40000 ALTER TABLE `animals` ENABLE KEYS */;
    UNLOCK TABLES;
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
    
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
    /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    
    -- Dump completed on 2015-01-01 20:15:56
    
  3. 使用 mysqldump 命令匯出 Raw Data,選項 --tab=/tmp 指定存檔目錄為 /tmp。
    [root@kvm8 ~]# mysqldump -uroot -p123qwe --tab=/tmp dyw animals
    
  4. 查看 mysqldump 命令匯出的 Raw Data 檔,/tmp/animals.txt 只存資料表內容,/tmp/animals.sql 為 sql 格式檔。
    [root@kvm8 ~]# cat /tmp/animals.txt 
    2	cat	4
    3	chicken	2
    1	dog	4
    [root@kvm8 ~]# cat /tmp/animals.sql 
    -- MySQL dump 10.13  Distrib 5.5.38, for Linux (x86_64)
    --
    -- Host: localhost    Database: dyw
    -- ------------------------------------------------------
    -- Server version	5.5.38
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
    /*!40103 SET TIME_ZONE='+00:00' */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
    
    --
    -- Table structure for table `animals`
    --
    
    DROP TABLE IF EXISTS `animals`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `animals` (
      `id` int(10) unsigned NOT NULL DEFAULT '0',
      `name` varchar(20) NOT NULL,
      `foot` tinyint(3) unsigned NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
    
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    
    -- Dump completed on 2015-01-01 20:03:51
    



2017-06-01