MYSQl命令整理

1 连接数据库,找到msysql
C:\Windows\system32>cd C:\Program Files\MySQL\MySQL Server 5.7\bin
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p
Enter password: ****
2 查询数据库
mysql> create databases;
3新建数据库
mysql> create database sjk;
4切换数据库
mysql> use sjk;
5显示数据库里的表
mysql> show tables;
6新建表
use sjk;
create table 表名(字段设定列表)//ENGINE:引擎 默认字符类型是utf8
create table if not exists stuTable (id int,name varchar(20),gender varchar(2))ENGINE='innoDB' default charset='utf8';
7显示数据表的结构
describe 表名;
describe stutable;
8插入数据
插入数据:insert into 表名(字段名1,字段2) values(值1,值2);
mysql> insert into stutable(name,gender)values('张三','M');
9修改数据
修改:update 表名 set 字段1=值1,字段2=值2 where 条件;
mysql> update stutable set name='李四'where name='张三';
10显示表中的记录
select * from 表名
mysql> select *from stutable;
11修改字段名或者儿编码类型
11_1增加字段
mysql> alter table stuTable add( beizhu char(8));
11-2重命名
mysql> alter table stuTable rename to student;
11-3修改属性
mysql> alter table student change beizhu opp char not null;
11-4删除
mysql> alter table student drop oop;
12查询
select *from student;//查询所有
select * from student id = 4;// 根据条件查询
select name,phone from stuTable where phone = '119' or phone = '120' // ||
select * from stuTable where name = 'xiaohan' and phone = '120 // &&
// 模糊查找
select count(name) from stuTable where name like '%xiao%' // like % 模糊查找
13排序
select score from scoreTable order by score // 升序
select * from scoreTable order by score desc // 降序
select score from scoreTable where score > 70 order by score limit 0,1
// limit begin,pageCount
14函数
count() 统计个数
max() 最大值
min() 最小值
avg() 平均值

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 50个常用的sql语句Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname...
    哈哈海阅读 1,256评论 0 7
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,778评论 18 399
  • 一. Java基础部分.................................................
    wy_sure阅读 3,839评论 0 11
  • 开始前刷卡 结束后 刷卡 三件。卡 小书 那张纸 1016 方向盘1.5 45度 1017 这个星期六约车
    footSInRoad阅读 331评论 0 0
  • Photoreading是关注许久的行动派琦琦强烈推荐过好几次的课程。在课程介绍中,几个关键词就都抓住了我的好奇,...
    anitayan阅读 6,130评论 8 17