MySQL 导出
    INTO OUTFILE将资料导出至文件中
    mysqldump工具导出资料和数据结构,并且可以针对数据库、数据表、索引的结构。
 
INTO OUTFILE测试
 
  select * from seq_test into outfile '/tmp/backup_v0.txt';
    
 
生成一个文件,各值用逗号隔开
 
  select *  into outfile '/tmp/backup_v1.txt' fields terminated by ',' enclosed by '"' lines terminated by '\n' from seq_test;
    

  select * from seq_test into outfile '/tmp/backup_v2.txt' fields terminated by ',' enclosed by '"' lines terminated by '\r\n' ;
       
 
mysqldump工具导出原始资料
        mysqldump -u root -p runoob seq_test|gzip > backup_data.zip
           

 
   也可以使用以下命令将导出的数据直接导入到远程的服务器上,但请确保两台服务器是相通的,是可以相互访问的:</p>
    $ mysqldump -u root -p database_name \
           | mysql -h other-host.com database_name
 
 
资料导入
    针对使用INTO OUTFILE方式导出的资料,可以使用LOAD DATA LOCAL INFILE方式导入资料。
         LOAD DATA LOCAL INFILE '/tmp/backup_v0.txt' INTO TABLE seq_test;
 

 mysql> select count(*) from seq_test;
+----------+
| count(*) |
+----------+
| 111 |
+----------+
1 row in set (0.00 sec) mysql> truncate table seq_test;
Query OK, 0 rows affected (0.00 sec) mysql> LOAD DATA LOCAL INFILE '/tmp/backup_v0.txt' INTO TABLE seq_test;
Query OK, 111 rows affected (0.00 sec)
Records: 111 Deleted: 0 Skipped: 0 Warnings: 0 mysql> select count(*) from seq_test;
+----------+
| count(*) |
+----------+
| 111 |
+----------+
1 row in set (0.00 sec)
 
   

       
    还可以使用mysqlimport工具导入
[root@t-xi-mysql01 tmp]# cp backup_v0.txt seq_test.txt
[root@t-xi-mysql01 tmp]#  mysqlimport -u root -p --local runoob seq_test.txt
Enter password:
runoob.seq_test: Records: 111  Deleted: 0  Skipped: 111  Warnings: 0
 
 
 
将mysqldump导出的资料进行导入
    
  gunzip  -c backup_data.zip>backup_data.sql
  mysql -u root -p
  mysql> source backup_data.sql
 
  

[root@t-xi-mysql01 tmp]# mysqldump -u root -p runoob seq_test|gzip > backup_data.zip
Enter password:
[root@t-xi-mysql01 tmp]# gunzip -c backup_data.zip>backup_data.sql
[root@t-xi-mysql01 tmp]#
[root@t-xi-mysql01 tmp]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.1.71 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use runoob;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> source backup_data.sql
Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.01 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 111 rows affected (0.00 sec)
Records: 111 Duplicates: 0 Warnings: 0 Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from seq_test;
+----------+
| count(*) |
+----------+
| 111 |
+----------+
1 row in set (0.00 sec)
 
 
 

MySQL->导出/导入资料[20180521]的更多相关文章

  1. [转]mysql导出导入中文表解决方法

    在开发过程中会经常用到mysql导出导入中文表,本文将详细介绍其如何使用,需要的朋友可以参考下. 在开发过程中会经常用到mysql导出导入中文表,本文将详细介绍其如何使用,需要的朋友可以参考下一.先针 ...

  2. mysql导出导入某张表

    一般表数据少的话都用图形界面了,看着比较方便. 如果表中数据比较多,用图形界面极容易卡死,这个时候就要用到命令行了. 用命令行导出导入大量数据还是比较快的,方法如下: 导出库db1中的表table1: ...

  3. Mysql导出导入乱码问题解决

    MySQL从4.1版本开始才提出字符集的概念,所以对于MySQL4.0及其以下的版本,他们的字符集都是Latin1的,所以有时候需要对mysql的字符集进行一下转换,MySQL版本的升级.降级,特别是 ...

  4. mysql导出导入数据

    使用sql语句导出数据: 导出时如果不写绝对路径,会提示The MySQL server is running with the --secure-file-priv option so it can ...

  5. mysql导出导入数据库表

    1.下载数据库 mysqldump db_name  -h 192.168.5.162 -uroot -p > /var/www/db_name.sql(这个可以自定义) 2,下载数据库中的某个 ...

  6. Mysql 导出导入

    MySQL数据库导出 以root登录vps,执行以下命令导出. 1./usr/local/mysql/bin/mysqldump -u root -p123456 zhumaohai > /ho ...

  7. MySQL导出导入命令的用例

    1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql 2.导 ...

  8. mysql 导出导入数据 -csv

    MySql数据库导出csv文件命令: mysql> select first_name,last_name,email from account into outfile 'e://output ...

  9. mysql导出导入数据库和表学习笔记

    一.mysql导出数据库和表 1.导出单个数据库 mysqldump [-h Host] -u Username -p [PASSWORD] db_name > db_name.sql 2.导出 ...

随机推荐

  1. FineReport和泛微OA(Ecology)的单点登录集成方案

    最近出现了很多关于帆软报表和泛微OA的集成问题,均出现在“单点登录”上.直接也有相关的文章介绍一些FineReport和泛微集成的背景.价值等,以及FineReport和OA的深度集成的方案,但是并没 ...

  2. The difference between a local variable and a member variable

    package com.itheima_04; /* * 成员变量和局部变量的区别: * A:在类中的位置不同 * 成员变量:类中,方法外 * 局部变量:方法中或者方法声明上(形式参数) * B:在内 ...

  3. MUI框架-01-介绍-创建项目-简单页面

    MUI框架-01-介绍-准备-创建项目 从0开始快速高效学习 MUI 框架 官方文档:http://dev.dcloud.net.cn/mui/ui/ (1)MUI 介绍 MUI 是什么,解决了什么问 ...

  4. 在Windows下为PHP5.6安装redis扩展和memcached扩展

    一.php安装redis扩展   1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本       2.根据PHP版本号,编译器版本号和CPU架构, 选择php_redis-2.2 ...

  5. bootstrap-table 分页增删改查之一(分页)

    记录一下 bootstrap-table插件的使用 先看下效果图 首先是导入js <!--js jquery --> <script type="text/javascri ...

  6. 排查在 Azure 中新建 Windows VM 时遇到的部署问题

    尝试创建新的 Azure 虚拟机 (VM) 时,遇到的常见错误是预配失败或分配失败. 当由于准备步骤不当,或者在从门户捕获映像期间选择了错误的设置而导致 OS 映像无法加载时,将发生预配失败. 当群集 ...

  7. c#多线程调用有参数的方法

      Thread (ParameterizedThreadStart) 初始化 Thread 类的新实例,指定允许对象在线程启动时传递给线程的委托.   Thread (ThreadStart) 初始 ...

  8. CAShapeLayer的使用[1]

    CAShapeLayer的使用[1] 使用CoreAnimation绘制动画带来的系统开销非常的小,CoreAnimation通常都是使用GPU的. CAShapeLayer属于CoreAnimati ...

  9. August 29th 2017 Week 35th Tuesday

    Life is a pure flame, and we live by an invisible sun within us. 生命如纯洁的火焰,而维系这火焰的是我们内心的太阳. Burn my l ...

  10. [朴孝敏/Loco][Nice Body]

    歌词来源:http://music.163.com/#/song?id=28738294 作曲 : 勇敢兄弟/大象王国 [作曲 : 勇敢兄弟/大象王国] 作词 : 勇敢兄弟 [作词 : 勇敢兄弟] A ...