zoukankan      html  css  js  c++  java
  • 文件的导入与导出

    1、数据导入
      1、作用 :把文件系统的内容导入到数据库中
      2、语法
        load data infile "/var/lib/mysql-files/文件名"
        into table 表名
        fields terminated by "分隔符"
        lines terminated by " ";
      3、将scoretable.csv文件导入到数据库的表中
        1、在数据库中创建对应的表
          create table scoretab(
          id int,
          name varchar(15),
          score float(5,2),
          number bigint,
          class char(7)
          );
        2、把文件拷贝到数据库的默认搜索路径中
          1、查看默认搜索路径
            show variables like "secure_file_priv";
            /var/lib/mysql-files/
          2、拷贝文件
            sudo cp ~/scoretable.csv /var/lib/mysql-files/
          3、执行数据导入语句
            load data infile "/var/lib/mysql-files/scoretable.csv"
            into table scoretab
            fields terminated by ","
            lines terminated by " ";
            只要有规律的都可以导入

    2、数据导出
      1、作用
        将数据库中表的记录导出到系统文件里
      2、语法格式
        select ... from 表名
        into outfile "/var/lib/mysql-files/文件名"
        fields terminated by "分隔符"
        lines terminated by " ";
      3、把MOSHOU库下的sanguo表英雄的姓名、攻击值、国家导出来,sanguo.txt
        select name,gongji,country from MOSHOU.sanguo
        into outfile "/var/lib/mysql-files/sanguo.txt"
        fields terminated by " "
        lines terminated by " ";
        $ sudo -i
        $ cd /var/lib/mysql-files/
        $ ls
        $ cat sanguo.txt
      4、将mysql库下的user表中 user、host两个字段的值导出到 user.txt
        select user,host from mysql.user
        into outfile "/var/lib/mysql-files/user.txt" fields terminated by " "
        lines terminated by " ";

  • 相关阅读:
    第8章 传输层(4)_可靠传输
    第8章 传输层(3)_TCP协议
    第8章 传输层(2)_UDP协议
    第8章 传输层(1)_TCP/UDP协议的应用场景
    【Sqlsever系列】日期和时间
    【SqlServer系列】聚合函数
    【Sqlserver系列】CAST和CONVERT
    【SqlServer系列】AS的用法
    【博客目录】SqlServer篇
    【SqlServer系列】集合运算
  • 原文地址:https://www.cnblogs.com/zengsf/p/9573268.html
Copyright © 2011-2022 走看看