查看表结构
desc test;
显示表列定义
show columns from test;
显示表的索引
show index from test;
插入表数据
INSERT INTO book (
book_name,
bokk_author,
price,
publish_date
)
VALUES
("c#", "hhq", 40, NOW()),#可以指定多行的值
("编程语言", "hhq", 40, NOW())
查询表所有数据
select * from book;
查询指定列数据库
select id,book_name name from book;
select id,book_name 书名 from book;
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" and id!=2
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id DESC
排序查找,使用limit
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id DESC limit 2
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id DESC limit 2,1#limit后面的1条,也就是查找第3条
查看id为5的数据
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id limit 4,1
查第三,第四条
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id limit 2,2
模糊查询like
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
book_name like "%c%"
原文地址:http://blog.51cto.com/13496943/2145167