services.msc 打开服务
1.创建数据库
使用数据库
见表
添加数据
2.使用数据库
查询
--1.切换mysql启动目录
cd C:\Program Files\MySQL\MySQL Server 5.1\bin
--2.使用mysql数据库的root登录
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u root -p
Enter password: **
--3.创建数据库
create database if not exists jack;
--4.使用数据库
use jack;
--5.查看数据库
show databases;
--6. 删除数据库
drop database if exists jack;
--7.创建数据库
create database if not exists jack;
--8.使用数据库
use jack;
--9.创建数据库表
create table if not exists bd12
(
字段名 数据类型(长度)属性 索引,
字段名 数据类型(长度)[属性] [索引]...
id int(10) unsigned auto_increment primary key,
name varchar(20) not null
);
--10.查看表结构
mysql> desc bd12;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.03 sec)
--11.表名重命名
alter table bd12 rename as bd34;
--12.添加数据库列
alter table bd34 add age int(10);
--13.修改列的数据类型和列属性
alter table bd34 modify age varchar(10);
--14.修改数据库的列名和列属性
alter table bd34 change age sex varchar(15);
--15. 删除数据表的字段(列)
alter table bd34 drop sex;
--16.删除数据表
drop table if exists bd34;
--17.查询当前用户下的所有表
select * from tab;
--18.创建数据表student
--sid(10)主键自增长(从10开始) ,
--sname(20),sex(10),age(10),score(10),entrytime(date)
create table student
(
sid int(10) unsigned auto_increment primary key,
sname varchar(20) not null,
sex varchar(10) not null,
age int(10) unsigned,
score double(10,2),
entrytime date
)auto_increment=10;
--19.添加数据
insert into student
(sname,sex,age,score,entrytime)
values
('tingting','gril',18,100.00,'20161224'),
('jingjing','gril',18,98.00,'20161225'),
('fupengcheng','boy',38,80.00,'20161226'),
('hognliang','boy',28,60.00,'20161227'),
('yuanyuan','gril',18,80.00,'20161228'),
('laowang','boy',28,70.00,'20161227'),
('hangzhou','boy',26,76.00,'20161228');
--20.提交事务
commit;
--21. 查看表中所有数据
select * from student;
--22.查看学生中最大年龄
select max(age) from student;
--23.查看学生中最小年龄
select min(age) from student;
--24.查看学生平均年龄
select avg(age) from student;
--25.查看学生成绩总和
select sum(score) from student;
--26.统计学生人数
select count(*) from student;
select count(1) from student;
--27.聚合函数综合使用
select
max(age) '最大年龄',min(age) '最小年龄',
avg(age) '平均年龄',sum(score) '成绩总和'
from student;
--28.按照成绩进行排序
--按照成绩升序查询
select * from student order by score asc;
--按照成绩降序查询
select * from student order by score desc;
--29.按照性别分组
select sex from student group by sex;
--30.按照性别分组,再统计每组的人数
select sex,count(sex) from student group by sex;
--31.按照性别分组,再统计每组的人数,并按照人数进行升序排列
(先分组再排序)
select sex,count(sex) from student group by sex order by count(sex) asc;
--32.修改数据
--update 表名 set 字段=值 where 字段=值;
update student set sex='gril' where sid=10;
--33.删除表数据
delete from student where sid=16;
--34.添加数据
insert into student
(sname,sex,age,score,entrytime)
values
('hongliang','gril',48,95.00,'20161229');
--35.查询姓名中包含w关键字的学生信息
select * from student where sname like '%w%';
--36.查询姓名中以g结尾的学生信息
select * from student where sname like '%g';
--37.查询姓名中以h开头的学生信息
select * from student where sname like 'h%';
--38.分页查询
--pagesize: 每页显示的数据条数
--pageno表示第几页
select * from student limit (pageno-1)*pagesize,pagesize;
select * from student limit 0,2;
select * from student limit 2,2;
select * from student limit 4,2;
select * from student limit 6,2;
--30.回滚数据
rollback;