mysql 10501_SQL-10501zhangyue-ChinaUnix博客

开始->运行->cmd->确定

mysql命令行实用程序:

1、mysql -u root

5f3c173e81461b1537f92cba8b1b350f.png

如果设有密码,输入:

mysql -u root -p -h localhost -p 123456

完成命令行选项和参数列表可用mysql--help获得。

2、显示数据库

show databases;

b4452fde3b49e54a9483519586dd8cdf.png

3、选择一个数据库

use foo;

566388a1e96a54c3a0b199b960441c17.png

4、获得这个数据库内的表的列表

show tables;

ed6898b3f5817a568cee1a38ac1e62df.png

5、show columns要求给出一个表名,它对每个字返回一行,行中包含字段名、数据类型、是否允许null、键信息、默认值以及其他信息(如字段cust_id的auto_increment).

show columns from customers;

2a19eada1e19ac9ded4976b829058944.png

6、利用select语句从customers表中检索一个名为cust_id的列。所需的列名在select关键字之后给出,from关键字指出从其中检索数据的表名;

select cust_id from customers;

11499796bc1354cf240a29637206e2aa.png

7、检索多个列,用逗号隔开

select cust_id ,cust_name from customers;

17e6d13c213e4f7de02c07903e096f51.png

8、检索所有列

select * from customers;

47f28eae10ecdfce901f3fbba77283b7.png

9、检索不同的行

select distinct cust_id from customers;

e0a03cd6fe5e3185e39fafb7f0e7fe9b.png

10、限制结果,select语句返回所有匹配的行,它们可能是指定表中的每个行。为了返回第一行或前几行,可使用limit语句,

select cust_name from customers limit 5;

ce6a5756d07f327b7278c81ba1ef6f1a.png

11、select cust_name from customers limit 3,5;

limit3,5指示mysql返回从行3开始的5行,第一个数为开始位置,第二个数为要检索的行数。如果要检索的行数不足,mysql只返回它能返回的行数。检索出来的第一行为0而不是1.

d8f37bfc9debc2e38fe8e28052ebec52.png

12、使用完全限定的表名

select customers.cust_name from foo.customers;

等同于select cust_name from customers;

13、数据库表输出特定的顺序

select cust_name from customers order by cust_name;

c53154259e1e3041c29bf8d4b3c36ffc.png

14、按多个列排序

select cust_name,cust_id from customers order by cust_name;

ebdd01cb05c58119256878d971331b33.png

15、指定排序方式 默认为升序  desc为降序 asc为升序

select cust_name,cust_id from customers order by cust_name desc;

a2c949427e291359ce83188516b50bc0.png

16、使order by 和limit组合,

select cust_name from customers order by cust_name desc limit 1;89d4201f12c91a8b7cb88b2994a2bcd3.png

17、使用where子句 指定的搜索条件进行过滤 where子句在表名from子句之后给出

select cust_id,cust_name from customers where cust_id=10001;

cdc5b5a24632cfb372e6cd193fc03021.png

18、where子句操作符

select cust_name,cust_id from customers where cust_name='e fudd';

select cust_name,cust_id from customers where cust_id<>10001;

select cust_name,cust_id from customers where cust_id between 10001 and 10002;

空值检查

select cust_id from customers where cust_email is null;

6a4ae4446bf4bfc6cf3d77d4fb17802a.png

今日感悟:

感觉一些语句掌握不好,还是需要多加练习,要明白它内在的含义

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值