zoukankan      html  css  js  c++  java
  • MySQL 导入外部数据

    手工为数据库录入数据:

     1 -- 使用数据库
     2 use test;
     3 
     4 -- 创建fruits数据表
     5 create table fruits(
     6     f_id char(10) not null,
     7     s_id int not null,
     8     f_name varchar(255) not null,
     9     f_price decimal(8,2) not null,
    10     primary key(f_id)
    11 );
    12 
    13 -- 插入数据
    14 insert into fruits(f_id,s_id,f_name,f_price)
    15 values('a1',101,'apple',5.2),
    16 ('b1',101,'blackberry',10.2),
    17 ('bs1',102,'orange',11.2),
    18 ('bs2',105,'melon',8.2),
    19 ('t1',102,'banana',10.3),
    20 ('t2',102,'grape',5.3),
    21 ('o2',103,'coconut',9.2),
    22 ('c0',101,'cherry',3.2),
    23 ('a2',103,'apricot',25.2),
    24 ('l2',104,'lemon',6.4),
    25 ('b2',104,'berry',7.6),
    26 ('m1',106,'mango',15.6),
    27 ('m2',105,'xbabay',2.6),
    28 ('t4',107,'xbababa',3.6),
    29 ('b5',107,'xxxx',3.6);
    30 
    31 select * from fruits;

    导入外部数据:

    • 创建数据表结构
    • 导入外部数据
    • 检查表数据

    创建数据表:

     1 -- 创建大气质量表
     2 create table Monthly_Indicator(
     3     city_name varchar(20) not null,
     4     month_key date not null,
     5     aqi int(4) not null default 0,
     6     aqi_range varchar(20) not null default '-',
     7     air_quality varchar(20) not null default '-',
     8     pm25 float(6,2) not null default 0,
     9     pm10 float(6,2) not null default 0,
    10     so2 float(6,2) not null default 0,
    11     co float(6,2) not null default 0,
    12     no2 float(6,2) not null default 0,
    13     o3 float(6,2) not null default 0,
    14     ranking int(4) not null default 0,
    15     primary key(city_name,month_key)
    16     );

    导入外部数据:

    1 -- 为Monthly_Indicator表导入外部txt文件
    2 load data local infile 'D:/data/all.txt' 
    3     into table Monthly_Indicator 
    4     fields terminated by '	'
    5     ignore 1 lines;

    -- 检查倒入内容Monthly_Indicator
    Select * from Monthly_Indicator;
    
    -- 检查导入数据总行数Monthly_Indicator
    Select count(*) from Monthly_Indicator;
    
    -- 检查表结构
    Desc Monthly_Indicator;
  • 相关阅读:
    调试D2JS
    PG 中 JSON 字段的应用
    面试----
    机器学习面试题
    闭包和装饰器
    scss-混合@mixin @include @function
    scss基本使用及操作函数
    常用的scss函数(mixin)
    二叉搜索树基本操作实现
    判断一棵树是否是二叉搜索树
  • 原文地址:https://www.cnblogs.com/waterr/p/14308686.html
Copyright © 2011-2022 走看看