MySql常用命令总结

用户

登录: mysql - u 用户名 -p 密码

增加用户: insert into mysql.user(host,user,password,select_priv,...) value('服务器名称',‘用户名‘,’密码‘,’权限‘,...);


管理数据库:

显示数据库: show database;

建立数据库: create database;

删除: drop database  T

打开数据库 use T


管理数据表:

建表: create table  name (字段名,字段类型,字段属性,字段名,字段类型,字段属性);

显示数据表结构:describe  name

修改字段类型:alter table 数据库名 change 字段名  新字段名;

增加字段: alter table 数据库名 add 字段名 字段类型

删除字段: alter table 数据库名 drop 字段名

删除表: drop table

表换名:rename table 表名 to 新表名


管理记录

增加记录:insert into 表名 (字段名) value (‘字段值’)

批处理: source sql.sql

删除记录: delete from 表名 where 条件表达式

删除所有记录  delete from 表名 

修改 update  表名  set 字段名 = 字段值 where 条件表达式


查询数据表:

查询所有:select * from 表名

查询排序:select 身份证号,姓名,手机 from member order by 身份证号


多表查询:

关联查询:select * form sell,member where sell.id = member.id

三表关联查询 select * from sell,member ,book where  sell.id = member.id and sell.id = book.id

左关联  select *form a left join on b where a.id =b.id

内关联 select * from a inner join on b where a.id = b.id


 通配符:

通配符用于做字符串的加工,%匹配所有字符,_匹配一个字符

查询 user 表中所有姓张的用户

select * form user where name like ‘张%'

除了除了姓张的

select * form user where name not like ‘张%'

找出所有姓张的名字是两个字的

select * form user where name like ‘张_'


函数:

count (*) 统计记录个数

select count (*) from member

sum(字段名) 对指定字段名求和

avg(字段名)对指定字段名计算平均值

max (字段名) 求最大值

min (字段名) 求最小值

select count (distinct id) from member ID去重计算机数量


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值