|
mysql -h localhost -u root -p123456 登录mysql服务器
show databases 列出所拥有的数据库
use www 选择一个www的数据库
show tables 列出该库的数据表
create table emp (id int auto_increment,name varchar(20),birdate date); 创建一个emp表,有id,name,birdate三个字段
insert into emp values(null,'Libin','2014-07-06'); 插入一条数据
insert into emp values(null,'Libin','2014-07-06'),(null,'Min','2014-07-07') 插入多条数据
update emp set name = 'Php' where name = 'Libin'; 修改单个字段数据
delete from emp where name = 'Php'; 删除符合条件的数据
alter table emp modify name char(125); 修改单个字段的属性,注:modify不能修改字段名
alter table emp change name cname char(125); 修改单个字段的属性,并能修改字段名次
alter table emp modify name char(200) first | after birdate 修改单个字段的属性,并指定修改后的位置
alter table emp add column sex tinyint(1) first | after name 增加一个字段,并可以指定它的位置
alter table emp delete column sex 删除一个字段
describe emp 查看一个表的结构 = desc emp
show create table emp 同上,但更详细
drop table emp 删除一个表
select * from emp 查询emp表所有数据
select name from emp 只查询emp表的name字段
select distinct name from emp 查询name不重复的数据
select * from emp where name = 'Php'; 查询name条件为php的数据
select * from emp where name = 'Php' order by id desc | asc; 条件并排序
select max(id),min(id),sum(id) from emp 查询最大、最小、总计的id的数据
select * from emp limit 2 只要2条数据
select * from emp limit 9,10 从第10条数据开始,取10条数据
select count(id) from emp 求出一共有多少条数据
select * from emp where id in(select id from emp where name = 'Php' or name = 'Libin') 子查询,首先查询name为php或libin的id,然后通过in查询所有能匹配id的数据
select a.name,b.name from emp as a,emp as b where a.id=b.id and a.id=100 id为100的内联(表联)
select a.name,b.name from emp as a left join emp as b on a.id=b.id where a.id = 100 id为100的左连接
select a.name,b.name from emp as a right join emp as b on a.id=b.id where a.id = 100 id为100的右连接
DCL::
grant select,insert on www.* to 'test'@'localhost' identified by '123456' 给www下所有的表创建一个只有select跟insert权限的用户test,密码为123456
revoke insert on www.* from 'test'@'localhost' 收回test的insert权限
concat('Li','Bin') 字符串拼接函数,可对查询的结果字段直接进行拼接
select '<?php echo 100;?>' into outfile 'c://qqq.php' 文本输出,简直是个危险的漏洞
select load_file('c://qqq.php'); 读取一个文本
|
|