mysql常用命令和用法命令
时间: 2023-11-30 17:02:28 浏览: 32
1. 连接MySQL服务器: mysql -h 主机名 -u 用户名 -p
2. 创建数据库: create database 数据库名;
3. 删除数据库: drop database 数据库名;
4. 使用数据库: use 数据库名;
5. 显示当前使用的数据库:select database();
6. 显示数据库中所有的表: show tables;
7. 创建表:create table 表名 (字段名1 数据类型1, 字段名2 数据类型2, …);
8. 查看表结构:desc 表名;
9. 删除表:drop table 表名;
10. 插入数据:insert into 表名 (字段名1, 字段名2, …) values (值1, 值2, …);
11. 更新数据:update 表名 set 字段名1=值1, 字段名2=值2, … where 条件;
12. 删除数据:delete from 表名 where 条件;
13. 查询数据:select 字段名1, 字段名2, … from 表名 where 条件;
14. 查询数据并排序:select 字段名1, 字段名2, … from 表名 order by 字段名 asc/desc;
15. 查询数据并限制数量:select 字段名1, 字段名2, … from 表名 limit 数量;
16. 查询数据并分页:select 字段名1, 字段名2, … from 表名 limit 开始位置, 数量;
17. 查询数据并统计数量:select count(*) from 表名;
18. 查询数据并分组:select 字段名, count(*) from 表名 group by 字段名;
19. 查询数据并使用聚合函数:select sum(字段名), avg(字段名), max(字段名), min(字段名) from 表名;
20. 查询数据并连接表:select 表1.字段名, 表2.字段名 from 表1, 表2 where 表1.字段名=表2.字段名;