MySQL基础命令收集(持续更新)

一、命令收集:

1、建表
create table t1 (name char(5));
2、表中插入数据
insert into t1 values(‘11111’) ;
3、查看创表语句及字符集
show create table(t1);
4、查询表中数据
select * from t1;
5、查看文表当中某个列的一些具体值的占用长度。
select length(name) from t1;
6、所有字符集校对规则
show collation;
7、查看所有字符集
show charset;
8、查询某参数
show variables like ‘%lower%’;
9、删库
drop database 库名;
10、查库
show create database test;
show databases; (所有库)
11、改库字符集
alter database test charset utf8mb4;
12、取当前时间
select now();
13、查看表的列信息
desc xx;
14 、添加列
alter table xs1 add 微信 varchar(64) not null unique key comment ‘微信号’;
如果是在某列之后添加➕after xxx;
如果是在最前面添加 直接写first;
删除列
alter table xs1 drop dianhua;(危险操作)
列名属性都修改
alter table xs1 change name sname varchar(64)
只修改数据属性
alter table xs1 modify 微信 varchar(64) not null comment ‘微信号’;
删表(危险,不代表生产操作)
truncate table xs;(清空表的区,数据清空,表定义保留)
drop table xs1;(表定义和数据全部删除)
查表
show tables;
show create table xs;
desc

小结:
建库
create database haha charset utf8mb4;
删库
drop database haha;
改字符集
alter database haha charest uft8;
查看
show create database haha;
show databases;

create table 表名 (
列1 数据类型 约束 其他属性,
列1 数据类型 约束 其他属性
)engine=innodb charset=utf8mb4; comment ‘信息’;

修改表
alter table xuexiao add qq varchar(64) not null unique key comment ‘qq号’

删表
drop table xs1;
desc xs1;

grant 权限 on 范围 to 用户 identified by 密码;
revoke 权限 on 范围 from 用户;

DML
用做表的数据行的增、删、改、查
insert 表名 values();
例子
insert into xs1(id,sname,age,sex,shengfen,shijian) values (1,'张三','18','n','bj',now());

简化方法
insert into xs1 values(2,’李四’,’15’,’n’,’sh’,now());
只对需要录入部分录入。
修改某一行,update要加where条件
update xs1 set age=20 where id=1;

delete 语句(逻辑性删除,注意要加where条件)
delete from xs1 where id=4

面试题:以下语句的区别?
delete from t1;
truncate table t1;

truncate table t1; 是DDL语句,清空整表的所有数据,按照区来删除,属于物理删除,性能高。表所占用空间会立即释放。
delete from t1; 是DML语句,清空整表所有数据,按照行来删除的,属于逻辑删除,性能低。表所占用的空间,不会立即释放。

使用update替代delete 实现伪删除。
添加一个状态列state
delete from xs1 where id=6
update xs1 set state=0 where id=6;
改完后业务进行调整
Select * from xs1 where state=1;

15 select 单独属性的情况(mysql独家)
例子 select @@datadir;
Select @@port;
show模糊查询
mysql> show variables like '%trx%';

select 函数();
select now(); 查当前时间
select user(); 查当前用户
select database();查当前所在数据库
select 15*15; 可以直接做计算
select concat (‘hello world’)做拼接用法
select concat(user,‘@’,host) from mysql.user; 最基本应用
select group_concat(user,‘@’,host) from mysql.user;

from子句应用
select * from city; 查看所有
select country,name from city; 查看某几列。

where子句应用
等值查询
查询中国城市的信息
select * from city where countrycode=’CHN’;
不等值查询
查询人口数量少于100人城市。
select * from city where population<100;
查询id小于10的城市信息
select * from city where id<10;
查询不是中国的城市信息(尽量不使用不等于,可能不走索引)。
select * from city where countrycode !=’CHN’;

select模糊查询
查询国家代号为CH打头的城市信息。
Select * from city where countrycode like ‘CHN%’;
逻辑连接符(and,or)
查询中国城市人口超过500 w的城市信息
select * from city where countrycode=’CHN’and population>500;

查看山东省或河北省的城市信息
select * from city where district=’shandong’ or district=’hebei’;

where配合between and的使用
查询人口数在100w-200w之间的城市信息(包含头尾)
select * from city where population between 1000000 and 2000000;

where 配合in使用
查看山东省或河北省的城市信息
select * from city where district in(‘shandong’,’hebei’);
select * from city where district notin(‘shandong’,’hebei’);排除

group by 字句+聚合函数
按照某个列进行分组

常用的聚合函数
count() 计数
max()最大值
min()最小值
average 平均值
sum() 总和
group_concat() 组拼接,列转行

例子
统计每个国家的城市个数
select countrycode,count(id) from city group by countrycode;
统计每个国家的总人口数
select countrycode,sum(population) from city group countrycode;
统计中国每个省的城市个数及总人口数
select district,count(name),sum(population) from city where countrycode=’CHN’group by district;
统计各个国家的城市名列表
select countrycode,group_concat(name)
From city
Group by countrycode;

having 字句使用 再过滤
统计中国每个省的城市个数及省总人口数,只显示人口总数达于800万的省
select district ,count(name),sum(population) from city where countrycode=’CHN’ group by district
having sum(population)>8000000;

统计中国每个省的城市个数及省总人口数,只显示人口总数达于800万的省,将人口数进行排序输出。
order by字句
在having之后

select district,count(name),sum(population) from city where countrycode=’CHN’ group by district having
sum(population)>8000000 order by sum(population);默认从小到大排序
select district,count(name),sum(population) from city where countrycode=’CHN’ group by district having
sum(population)>8000000 order by sum(population) desc; 从大到小排序

order by 可以在where 后面使用

查询中国所有城市信息,并以人口数量进行降序排序。
select * from from city where countrycode=’CHN’order by population desc;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数字乡村和智慧农业的数字化转型是当前农业发展的新趋势,旨在通过应用数字技术,实现农业全流程的再造和全生命周期的管理服务。中国政府高度重视这一领域的发展,提出“数字中国”和“乡村振兴”战略,以提升国家治理能力,推动城乡融合发展。 数字乡村的建设面临乡村治理、基础设施、产业链条和公共服务等方面的问题,需要分阶段实施《数字乡村发展战略纲要》来解决。农业数字化转型的需求包括满足市民对优质农产品的需求、解决产销对接问题、形成优质优价机制、提高农业劳动力素质、打破信息孤岛、提高农业政策服务的精准度和有效性,以及解决农业融资难的问题。 数字乡村建设的关键在于构建“1+3+4+1”工程,即以新技术、新要素、新商业、新农民、新文化、新农村为核心,推进数据融合,强化农业大数据的汇集功能。数字农业大数据解决方案以农业数字底图和数据资源为基础,通过可视化监管,实现区域农业的全面数字化管理。 数字农业大数据架构基于大数据、区块链、GIS和物联网技术,构建农业大数据中心、农业物联网平台和农村综合服务指挥决策平台三大基础平台。农业大数据中心汇聚各类涉农信息资源和业务数据,支持大数据应用。信息采集系统覆盖市、县、乡、村多级,形成高效的农业大数据信息采集体系。 农业物联网平台包括环境监测系统、视频监控系统、预警预报系统和智能控制系统,通过收集和监测数据,实现对农业环境和生产过程的智能化管理。综合服务指挥决策平台利用数据分析和GIS技术,为农业决策提供支持。 数字乡村建设包括三大服务平台:治理服务平台、民生服务平台和产业服务平台。治理服务平台通过大数据和AI技术,实现乡村治理的数字化;民生服务平台利用互联网技术,提供各类民生服务;产业服务平台融合政企关系,支持农业产业发展。 数字乡村的应用场景广泛,包括农业生产过程、农产品流通、农业管理和农村社会服务。农业生产管理系统利用AIoT技术,实现农业生产的标准化和智能化。农产品智慧流通管理系统和溯源管理系统提高流通效率和产品追溯能力。智慧农业管理通过互联网+农业,提升农业管理的科学性和效率。农村社会服务则通过数字化手段,提高农村地区的公共服务水平。 总体而言,数字乡村和智慧农业的建设,不仅能够提升农业生产效率和管理水平,还能够促进农村地区的社会经济发展,实现城乡融合发展,是推动中国农业现代化的重要途径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值