现在的位置: 首页 > 综合 > 正文

mysql学习笔记(未完)

2013年10月12日 ⁄ 综合 ⁄ 共 980字 ⁄ 字号 评论关闭
1.连接服务器:mysql -h localhost -u user -p,然后输入密码。
2.断开服务器:quit
3.查询服务器版本和当前时间:
select version(), current_date;
select now();
4.取消一条命令:/c
5.显示数据库:show databases;
6.使用数据库:use test;
7.创建数据库:create database test;
8.显示表:show tables;
9.创建表:create table pet(name varchar(20), sex char(1), birth date);
10.查看表结构:describe pet;
11.将txt文件数据装入表中:load data local infile 'd:/pet.txt' into table pet;
pet.txt(内容如下)
Fluffy    f    2000-01-01
Bowser    m    2008-08-08
Slim    /N    3000-01-01
Claws    f    2000-01-01
slim    m    2005-02-01
用定位符(tab)把值分开,/N代表空缺
12.从表中检索:select * from pet;
13.检索唯一输出:select distinct sex from pet;
14.排序:
(默认升序)select * from pet order by birth;
(降序)select * from pet order by birth desc;
(区分大小写)select * from pet order by binary name desc;
(多列排序,name升序,birth降序)select * from pet order by name, birth desc;
15.日期计算:
year():获取年份
select * from pet where year(birth)='2008';
month():获取月份
select * from pet where month(birth)='01';
day():获取日
select * from pet where day(birth)='01';
right():提取日期的MM-DD (日历年)部分的最右面(例如:5个字符)
select name, right(birth, 5) from pet;
16.判断是否为null
select * from pet where sex is null;

抱歉!评论已关闭.