MySQL学习
服务器端运行原理图:
MYSQL控制台:
help:查找命令
show databases; 查找数据库
create database dataname; 创建一个数据库
use dataname; 使用这个数据库
show tables; 查看表
desc tablename;查看表的信息
//创建一个表
create table tablename(col_name type not null auto_increment,col_name type default,primary key(col_name));
//插入数据
insert into tablename(col_name,col_name) value(value1,value2);
//改变(更新)数据
update tablename set col_name=value,col_name=value where conditions;
//删除数据
delete from tablename where conditions;
//查找数据
select * from tablename; //查找所有的数据 *代表所有的
select col_list 查找表里的什么
from table_name 从哪个表查找
where condition 判断条件
order by col_list (desc) 代表排序(默认从小到大)desc表示反转
limit rom_limit; 限制条件 limit 2,3表示去掉两个,然后从开始找3个数据
查询静态值
select 'some string';
select 1+1;
select now();
select curdate();
select curtime();
select pi();
select mod(45,7);
select sqrt(25);
可以在查询的时候通过as 修改这一列的列名
select 'some string';
select 1+1;
select now();
select curdate();
select curtime();
select pi();
select mod(45,7);
select sqrt(25);
可以在查询的时候通过as 修改这一列的列名
查询的时候可以使用的功能函数
round() 四舍五入
round(columnname,x)四舍五入保留x位小数
floor()直接舍
ceiling()直接入
round() 四舍五入
round(columnname,x)四舍五入保留x位小数
floor()直接舍
ceiling()直接入
查询的时候可以对查询的列做一些运算
*
/ (除 结果为浮点)
div (除 结果为整数)
% mod (求余,结果为浮点数)
+
-
*
/ (除 结果为浮点)
div (除 结果为整数)
% mod (求余,结果为浮点数)
+
-
//字符串的操作:
concat 连接
left 取多少字符
length 长度
reverse 反转
replace 替换
date_format %m %b %d %y %Y %T %f 修改时间模式的'%y/%m/%d' 年月日
left 取多少字符
length 长度
reverse 反转
replace 替换
date_format %m %b %d %y %Y %T %f 修改时间模式的'%y/%m/%d' 年月日
distinct 去掉重复的
where条件
1,数字 > < = >= <= <>
2,字符串 = '' > < = >= <= <> !=
逻辑操作
is 仅用is null或is not null
and or not
and 优先级> or
范围判断
in (not in) 在这范围之内取值
between (not between) 示例:select * from category where category_id between 1 and 9;
like (not like) % _ %代表多个任意字母,_代表一个任意字母
示例1:select * from category where name like 'A%';
关于NULL的条件
is NULL
is not NULL
1,数字 > < = >= <= <>
2,字符串 = '' > < = >= <= <> !=
逻辑操作
is 仅用is null或is not null
and or not
and 优先级> or
范围判断
in (not in) 在这范围之内取值
between (not between) 示例:select * from category where category_id between 1 and 9;
like (not like) % _ %代表多个任意字母,_代表一个任意字母
示例1:select * from category where name like 'A%';
关于NULL的条件
is NULL
is not NULL