mysql学习笔记(未完)
来源:互联网 发布:灯具散热模拟软件 编辑:程序博客网 时间:2024/05/17 06:46
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;
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;
- mysql学习笔记(未完)
- 《真言》学习笔记(未完)
- linux学习笔记(未完)
- (未完)string 学习笔记
- eleasticsearch学习笔记(未完)
- scala学习笔记(未完)
- SpringMVC学习笔记(未完)
- docker 学习笔记(未完)
- mysql 优化笔记 未完
- Ajax学习笔记总结(未完待续)
- 开发文本编辑器学习笔记(未完)
- struts2 学习笔记(未完待续)
- Oracle学习笔记(未完待续)
- dreamweaver学习笔记(未完待续)
- css学习笔记(未完待续)
- 统计分布学习笔记(未完)
- 编译器学习笔记之一:概述(未完)
- 设计模式学习笔记(未完)
- 用Delphi设计代理服务器[正确文章]
- Mysql数学函数不求人
- CSS滤镜:Shadow属性
- TOMCAT中处理POST、GET编码问题解决方案
- 发现:不要Excel也可生成xls文件 !
- mysql学习笔记(未完)
- MySQL 文件系统
- 如何在网页中制作虚线表格
- MySQL 3.23.25 Beta 的安装
- 仿google的下拉提示,实现关键字智能化显示
- 可以左右居中对齐并可设置DisplayFormat的Edit控件
- SQL中HAVING从句的用法
- 利用CSS,链接下划线也玩自定义
- Wubi 安装 Ubuntu 8.04 教程