开始->运行->cmd->确定
mysql命令行实用程序:
1、mysql -u root
如果设有密码,输入:
mysql -u root -p -h localhost -p 123456
完成命令行选项和参数列表可用mysql--help获得。
2、显示数据库
show databases;
3、选择一个数据库
use foo;
4、获得这个数据库内的表的列表
show tables;
5、show columns要求给出一个表名,它对每个字返回一行,行中包含字段名、数据类型、是否允许null、键信息、默认值以及其他信息(如字段cust_id的auto_increment).
show columns from customers;
6、利用select语句从customers表中检索一个名为cust_id的列。所需的列名在select关键字之后给出,from关键字指出从其中检索数据的表名;
select cust_id from customers;
7、检索多个列,用逗号隔开
select cust_id ,cust_name from customers;
8、检索所有列
select * from customers;
9、检索不同的行
select distinct cust_id from customers;
10、限制结果,select语句返回所有匹配的行,它们可能是指定表中的每个行。为了返回第一行或前几行,可使用limit语句,
select cust_name from customers limit 5;
11、select cust_name from customers limit 3,5;
limit3,5指示mysql返回从行3开始的5行,第一个数为开始位置,第二个数为要检索的行数。如果要检索的行数不足,mysql只返回它能返回的行数。检索出来的第一行为0而不是1.
12、使用完全限定的表名
select customers.cust_name from foo.customers;
等同于select cust_name from customers;
13、数据库表输出特定的顺序
select cust_name from customers order by cust_name;
14、按多个列排序
select cust_name,cust_id from customers order by cust_name;
15、指定排序方式 默认为升序 desc为降序 asc为升序
select cust_name,cust_id from customers order by cust_name desc;
16、使order by 和limit组合,
select cust_name from customers order by cust_name desc limit 1;
17、使用where子句 指定的搜索条件进行过滤 where子句在表名from子句之后给出
select cust_id,cust_name from customers where cust_id=10001;
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;
今日感悟:
感觉一些语句掌握不好,还是需要多加练习,要明白它内在的含义