一、数据导入: 把系统文件的内容存储到数据库的表里
mysql> load data infile "目录/文件名" into table 库.表名 fields

terminated by "字段间隔符号" lines terminated by "\n";

                        /etc/passwd          studb.user

用户名:密码占位符 : uid : gid : 描述信息 : 家目录 : shell

create database studb;
create table studb.user(
name varchar(50),
password char(1),
uid int(2),
gid int(2),
comment varchar(100),
homedir char(100),
shell char(25),
index(name)
);
desc studb.user;
select * from studb.user;

alter table studb.user add id int(2) primary key auto_increment

first;

二、数据导出 : 把表记录存储到系统文件里。

mysql> sql查询 into outfile "目录/文件名";

mysql> sql查询 into outfile "目录/文件名" fields terminated by "

符号" lines terminated by "符号";

三、管理表记录 studb.user

insert into 库.表 values (字段值列表);
insert into 库.表 values (字段值列表),(字段值列表);

insert into 库.表(字段名列表) values (字段值列表);
insert into 库.表(字段名列表) values (字段值列表),(字段值列表

);


select 字段名列表 from 库.表;
select 字段名列表 from 库.表 where 条件;

select from user;
select
from user where name="mysql";

条件匹配的表示方式:
数值比较 > >= < <= = !=
字段名 符号 值
select name from user where uid=15;
select * from user where id=10;

字符比较 = !=
字段名 符号 "值"
select name,shell from user where shell!="/bin/bash";
select id,name from user where name="apache";

范围内匹配
字段名 between 值1 and 值2 在...之间

select * from user where id between 10 and 15;
select name from user where uid between 1 and 10;

字段名 in (值列表) 在...里
select id,name from user where name in ("apache","root","bob");
select id,name,uid from user where uid in (10,15,9,12);

字段名 not in (值列表) 不在...里
select name from user where uid not in (0,1,5,7);
select * from user where name not in ("root","mysql","bin");

匹配空 is null
字段名 is null
匹配非空 is not null
字段名 is not null
select id from user where name is null;
select id,name,shell from user where shell is not null;
insert into user(name)values(""),("null"),(null);
select id,name from user where name="";
select id,name from user where name="null";
distinct 不显示重复值
distinct 字段名
select distinct shell from user;
select distinct shell from user where uid<=10;

逻辑匹配 : 有多个条件
逻辑与 and 多个条件必须都成立
逻辑或 or 多个条件有一个条件成立即可
逻辑非 ! 取反

条件1 && 条件2 && 条件N
条件1 || 条件2 || 条件N

select name from user where name="zhangsan" and

uid=500 and shell="/bin/bash";

select name from user where name="zhangsan" or uid=500

or shell="/bin/bash";

数学运算操作 + - * / %
字段类型必须是数值类型

select 字段名 符号 字段名 from 表 where 条件;

select uid+gid from user where name="root";
select name,uid,gid,uid+gid he from user;
select name,uid,gid,uid+gid he from user where name="bin";

alter table user add age tinyint(2) unsigned default 21 after

name;

select name,age,2017-age old from user where name="bob";

select name,uid,gid,(uid+gid)/2 pjz from user where name="bin";

模糊查询 like
where 字段名 like '表达式';
任意一个字符
% 0个或多个字符
select name from user where name like '
';
select name,uid from user where name like '
_' and uid<=10;
select name from user where name like 'a%';
select name from user where name like '%a%';

select id,name from user where name in ("","null") or name is

null;

select id,name from user where name like '%_%';
select id,name from user where name like 'a';
select id,name from user where name like 'j%' or "%y";

正则匹配
where 字段名 regexp '正则表达式';
. ^ $ [ ] * |

insert into user(name) values("bob9"),("j7im"),("1yaya");
select name from user where name regexp '[0-9]';
select name from user where name regexp '^[0-9]';
select name,uid from user where uid regexp '..';
select name,uid from user where uid regexp '^..$';
select name,uid from user where name regexp 'a.t';
select name,uid from user where name regexp '^a.
t';
select name,uid from user where name regexp '^r|t$'

统计函数 字段得是数值类型。
求和 求平均值 求最大值 最小值 统计个数
sum(字段名) avg(字段名) max(字段名) min(字段名) count(字段名)
select count(name) from user where shell="/bin/bash";
select max(uid) from user;
select min(gid) from user;
select avg(age) from user;
select sum(gid) from user;
select sum(gid) , count(name) from user;
查询排序 sql查询 order by 字段名 asc/desc;
select name,uid from user where uid between 10 and 50 ;
select name,uid from user where uid between 10 and 50 order

by uid desc;
查询分组 sql查询 group by 字段名;
select shell user where uid between 10 and 50 ;
select shell from user where uid between 10 and 50 group by

shell;
select shell from user group by shell;

限制查询显示行数 limit
sql查询 limit 数字; 显示查询结果的前几行
sql查询 limit 数字1 , 数字2; 设置显示行的范围
select from user;
select
from user limit 2 ;
select from user limit 2 ,2 ;
select
from user order by uid desc;
select from user order by uid desc limit 5;
select
from user order by uid desc limit 1;
单表查询
++++++++++++++++++++++++++++++++++++++
where嵌套查询 :把内层的查询结果作为外层查询的查询条件。

select 字段名列表 from 表名 where 条件 ( select 字段名列表 from

表名 where 条件 );

显示用户名和uid uid字段的值 大于 uid字段的平均值。

select name,uid from user where uid > ( select avg(uid) from

user );

select name from user where name not in (select user from

mysql.user );

select name from user where name in (select user from

mysql.user where user="zhangsan");

select name from user where name not in (select user from

mysql.user where user="zhangsan";);

+++++++++++++++++++++
复制表: 作用: 快速建表 、 备份表

create table 库.表 sql查询;

create database dbbak;
create table dbbak.user2 select from studb.user;
create table dbbak.user3 select
from studb.user where 1 = 2;
create table dbbak.user4 select name,uid from studb.user limit

3;
+++++++++++++++++++++
多表查询
select 字段名列表 from 表名列表; 迪卡尔集
select 字段名列表 from 表名列表 where 条件;

create table studb.t1 select name,uid,shell from user limit 3;
create table studb.t2 select name,uid,homedir from user limit 4;
show tables;

select from t1; select from t2;

select * from t1,t2 where t1.uid = t2.uid and t1.name=t2.name;

select t1.* , t2.homedir from t1,t2 where t1.uid = t2.uid and

t1.name=t2.name;

++++++++++++++++++++++
连接查询
左连接查询
select 字段名列表 from 表A left join 表B on 条件;

右连接查询
select 字段名列表 from 表A right join 表B on 条件;

create table studb.t3 select name,uid,shell from user limit 3;
create table studb.t4 select name,uid,shell from user limit 5;
show tables;
select from t3; select from t4;

select from t3 left join t4 on t3.uid=t4.uid;
select
from t3 right join t4 on t3.uid=t4.uid;
++++++++++++++++++++++++++++++++++

条件匹配的表示方式:
数值比较 字符比较 范围内匹配 匹配空 匹配非空 逻辑匹配
正则匹配 模糊查询

去掉字段重复值 数学计算 统计函数 分组 排序 限制行数


条件匹配的表示方式:

转载于:https://blog.51cto.com/20214843/2055908

数据库:数据导入/数据导出相关推荐

  1. halcon 将数据保存到excel_用C#操作Excel文件,实现与Sqlserver数据库进行导入与导出的操作。...

    [实例简介] 用C#3层结构对Excel文件与SqlServer数据库进行导入与导出 [实例截图] 1.将数据库中数据导出Excel文件中,其原理是先将数据库中的你所选择的一张表,先加载到DataGr ...

  2. oracle数据导入与导出

    数据的导入导出 说明: 针对的对象:  数据的导入导出牵涉到的角色主要是工程实施人员. 需解决的问题:把所需要的数据从一个数据库中导入到另外一个数据库中. 1    工具方式 1.1         ...

  3. csv导入pgsql不成功_数据科学 | pandas数据导入与导出

    ↑↑↑↑↑点击上方蓝色字关注我们! 『运筹OR帷幄』原创 作者:杨士锦 周岩 书生 编者按 当我们开始着手做一个数据分析项目时,选择和导入数据集是第一个步骤,而导出数据虽然非必需,但有时候我们也需要保 ...

  4. MySQL高级之外键、表关联、数据导入及导出

    文章目录 MySQL高级 外键(foreign key) 嵌套查询(子查询) 多表查询 连接查询 数据导入 数据导出 表的复制 锁(自动加锁和释放锁) MySQL高级-重点掌握 外键 嵌套查询(子查询 ...

  5. oracle数据的导入和导出,Oracle入门教学--数据导入和导出

    数据导入和导出 一.数据导入工具 1.利用PLSQL直接进行数据表的粘贴 (1)下载测试表 (2)打开准备导入的文件并进行创建数据库表的SQL语句编辑 A.复制表头到新的sheet B.选择粘贴 C. ...

  6. java导出csv文件_R语言数据导入与导出

    R语言数据导入与导出 整这么一个系列,还是因为学R语言时遇到过一个非常"小白友好"的网站"DataScience Made Simple".相信很多人搜到过这个 ...

  7. GEE系列:第4单元 Google 地球引擎中的数据导入和导出

    GEE从入门到实战的10个系列单元: GEE系列:第1单元 Google地球引擎简介 GEE系列:第2单元 探索数据集 GEE系列:​第3单元 栅格遥感影像波段特征及渲染可视化 GEE系列:第4单元 ...

  8. memcached命令行memcached数据导入和导出PHP链接memcached memcach

    memcached命令行 memcached数据导入和导出 PHP链接memcached 先安装php的memcache扩展 cd /usr/local/src/ wget  http://www.a ...

  9. 金算盘导出oracle,金算盘软件数据导入和导出操作方法.doc

    金算盘软件数据导入和导出操作方法 金算盘软件维护集锦 此为201003版本,本期讲一下"导入导出"的一些注意事项,以"往来期初"导入导出为例. 导入导出这个功能 ...

  10. mysql 数据库的导入和导出

    mysql 数据库的导入和导出 视频 https://www.bilibili.com/video/BV1tV411o7zv?from=search&seid=2492452830997848 ...

最新文章

  1. AI视觉组仙人一步之模型调优
  2. python统计代码行数
  3. Nagios/Postfix 转发警报邮件到Office365
  4. vscode 一些基本知识
  5. 线程不能被子进程继承
  6. 使用ant触发Tomcat的reload操作
  7. SAP UI5 patternYYY : detailZZZ/{contextPath} - navigation test
  8. [转]Design Pattern Interview Questions - Part 2
  9. 牛客网【每日一题】5月27日题目精讲 货币系统
  10. java日历类add方法_Java日历setMinimalDaysInFirstWeek()方法与示例
  11. 有了它,从此走上炫酷的编码之路!
  12. Java Platform SE 8(Java概念图的描述)中文文档
  13. STC芯片在Keil中的添加与使用
  14. 8086CPU各寄存器及其简介
  15. 二极管和三极管介绍-二极管和三极管的区别及工作原理详解-KIA MOS管
  16. CountDownTimer 倒计时器
  17. HCIA-IoT 个人学习总结 Day4
  18. [转]前端开发必备神级资源(转载请删除括号里的内容)
  19. bluedroid acl 发送和接受
  20. 分布式机器学习的集群方案介绍之HPC实现

热门文章

  1. 手机APP应用如何从公网访问本地WEB应用
  2. 轻量应用服务器支持带宽套餐升级至流量包套餐流程说明
  3. Linux 与Windows 7双系统默认引导顺序的修改
  4. 【MySQL】浅谈一致性读
  5. Yahoo数据仓库架构简介
  6. Windows软件路由器运用实例之OSPF配置
  7. java如何获取tree_如何从javac插件获取memberselecttree中的表达式类型?
  8. Android 屏幕(View)坐标系统
  9. stringWithUTF8String return null (返回null)的解决办法
  10. Java中SimpleDateFormat用法详解