1.创建数据库
$ mysql -u root -p
CREATE database crashcourse;
USE crashcourse;
SOURCE ~/create.sql;
SOURCE ~/populate.sql;
2.查看数据库状态
SHOW DATALABLES;
SHOW TABLES;
- 显示数据表的属性,属性类型,主键信息,是否为 NULL,默认值等其他信息。
SHOW COLUMNS FROM Products;
- 显示数据表的详细索引信息,包括PRIMARY KEY(主键)
SHOW INDEX FROM Products;
SHOW TABLE STATUS LIKE [FROM db_name] [LIKE 'pattern'] \G:
3.检索数据
SELECT prod_id, prod_name,prod_price
FROM Products;
SELECT * FROM Products;
SELECT DISTINCT vend_id FROM Products;
SELECT vend_id FROM Products LIMIT 5 OFFSET 5; --LIMIT 5, 5
SELECT vend_id FROM Products LIMIT 5 OFFSET 5;
SELECT vend_id FROM Products LIMIT 5 OFFSET 5;
SELECT vend_id FROM Products LIMIT 5 OFFSET 5;
4.排序检查数据
SELECT prod_name FROM Products ORDER BY prod_name;
select prod_id, prod_price