查询数据库中所有表名
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';
或者show tables;也可以
创建数据库:create database 数据库名;
删除数据库:drop database 数据库名;
查看数据库:show databases;
查看用户 show user();
修改数据编码格式为utf-8 set character_set_client = utf8;
character_set_client为客户端编码方式;
character_set_connection为建立连接使用的编码;
character_set_database数据库的编码;
character_set_results结果集的编码;
character_set_server数据库服务器的编码;
查看表中的字段:desc/describe 表名
查看一张表创建的过程:show create table 表名
删除user表中name="zh"的数据:delete from user where name="zh";
查询user表中所有name=“zh”的数据:select * from user where name = “zh”;
向user表中插入数据:insert into user(name,age,sex) values("zh", 20, "man");
insert user set name="zh", age=20,sex="man";//如果数据可以为空,或有默认值可以不赋初值
更新表中数据:update user set age = age + 5 where name="zh";
查询结果,并按顺序排列:select * from user order by id//按id升序排列 末尾加上desc后为降序排列
limit关键字:select * from user limit 3;//查询前3条数据
select * from user limit 1, 2;//查询1开始的两条数据,从0开始计数
group by 关键字:分组 select * from user group by id//按id分组
having 关键字:表示选择的附加条件
Having中可以加入函数:常见的有count,max,min,avg等;
连表查询:select * from tb_student where clazz_id = (select id from tb_clazz where code = "1209");//查询班级是1209的学生
select * from tb_student as s inner join tb_clazz as c where clazz_id=c.id and code="1209";//一样的结果
删除seckill表中number字段:alter table seckill drop column number;
在SecKill表中增加number字段:alter table seckill add number int;
修改seckill表的字段属性为int:alter table seckill number int;
修改数据库的密码为123456:set password=password(‘123456’);
就先复习到这里吧。