mysql具体操作命令

mysql命令

1.service mysql start 开始

 2.service mysql stop 停止

3.service mysql restart 重启

 4. char,varchar,text 字符串

 5.tinyint,int,decimal 数字

 6.mysql -uroot -p 链接mysql

7.quit或exit 退出

8.select version(); 查看版本

9.select now(); 显示当前时间

10.create database 数据库名 charset=utf8; 创建数据库

11.drop database 数据库名; 删除数据库

 12.use 数据库名; 切换数据库

13.select database(); 查看当前选择的数据库

14.show tables; 查看当前数据库中所有表

15.alter table 表名 add|change|drop 列名 类型;

16.drop table 表名; 删除表

17.desc 表名; 查看表结构

18.rename table 原表名 to 新表名; 更改表名称

19.show create table '表名'; 查看表的创建语句

 20.select * from 表名 查询

21.全列插入:insert into 表名 values(...)

缺省插入:insert into 表名(列1,...) values(值1,...)

同时插入多条数据:insert into 表名 values(...),(...)...;

22.update 表名 set 列1=值1,... where 条件 修改

23.delete from 表名 where 条件 删除

24.select distinct 字段名 from 表名; 消除重复的行

 25.select * from students where name like '黄%' or sname like '%靖%'; 查询姓黄或叫靖的学生

26.select * from students where id in(1,3,8); 查询编号是1或3或8的学生

27.select * from students where id between 3 and 8; 查询学生是3至8的学生

28.select * from students where id between 3 and 8 and sex=1; 查询学生是3至8的男生

29.min() max() count() avg() sum() 聚合函数

1show databases; 显示所有数据库

2show tables; 显示所有库

3select now(); 显示当前时间

4min() max() sum() avg() count() 五个聚合函数

5select * from 表名 where isDelete=1 and sex=1 order by id desc; 降序排列未被删除的男生

6select count(*) from 表名 where sex=1; 统计表里有多少男生

7select * from 表名 where id in(5,6); (select * from 表名 limit 4,2 显示表里第五、六行的数据

8select avg(score) from 表名 where sex=1; 显示表里所有男生的平均分数

9select sum(score) from 表名 where sex=1 and age>20; 显示表里所有男生年龄大于20分数的总和

10select sum(age) from 表名 where sex =1 and age >20 and name like ‘李_’; 显示表里所有年龄大于20 并且 姓李的男生年龄的总和

11select * from 表名 order by price desc; 降序排列商品价格

12select * from 表名 order by xiaoliang asc; 升序排列商品销量

13select avg(times) from 表名; 显示平均寿命 14select count(*) from 表名; 统计表里所有商品销售总量moren

14默认值 ,非空,主键,外键,唯一 ,五个约束类型

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

推荐阅读更多精彩内容

  • MySQL 数据库常用命令 1、MySQL常用命令 create database name; 创建数据库 use...
    55lover阅读 4,872评论 1 57
  • 不要对不起任何东西,首先是自己,然后是RMB,因为最后难受的都是你自己。 人,生而为己,本性如此。能做的只能在既定...
    sshsky阅读 271评论 0 1
  • 这是第二次写文章,第一次写的没头绪,很乱,所以没上简书。但是这个平台真的很好,教会了我很多,学到了很多,希望简书越...
    我愿一世繁华阅读 161评论 0 0
  • 若是提起陈胜吴广,联想到的一定是中国历史上第一次农民起义。光听原来的历史老师讲到这个事件,就觉得这真是一个壮举...
    酥饼子阅读 681评论 0 1