MySql 系列数据库详解
2016-10-05 14:15
260 查看
数据类型:文本,数字,日期
/**
* Likie
* 重启
* Linux(CentOs):/etc/init.d/mysqld restart
*
* 命令:
* DB:数据库
查看当前有哪些DB:show databases;
添加DB:create database gc;
create database gc;
删除DB:drop database gc;
drop database gc;
table:数据表
选择数据库DB:(成功返回:Database changed)
查看数据表:show tables;show tables;
查看表结构(查看字段):descride 表名;
descride table_name
删除表:drop table 表名;
字段操作:
增加字段(增加列):alter table 表名 add 字段名 int(11) not null default 1;
删除字段(删除列):alter table 表名 drop 字段名;
修改字段名(修改列名)(数据类型不变):alter table 表名 change 原字段 新字段 varchar(255);
修改字段数据类型(修改列人数据类型):alter table 表名 change 字段 字段 新数据类型;
修改字段名和数据类型:alter table 表名 change 原字段 新字段 新数据类型;
表名操作:
修改表名:alter table 原表名 rename 新表名;
创建数据表及字段:
CREATE TABLE 表名(
id bigint(20),
caeate Time datetime,
ip varchar(255),
mobile varchar(255),
nickname varchar(255),
passwd varchar(255),
brief text,
);
删除表:drop table 表名
*
*
*/
/**
SQL查询语句:
select * from 表名;
select 字段,字段2,字段3 from 表名;
SQL插入数据:
insert into 表名 value(值1,值2,...)
insert into 表名 (字段1,字段2)value('值1','值2')
where语法
select 字段或* from 表名 where 字段='字段值';
where高级(in)语法,多值或值为查询后
select * from 表名 where 字段 in(值1,值2);
select * from 表名 where 字段 in(select 字段 from 表名);
where高级(between)之间
select * from 表名 where between id 1 and 3; 查询id为1到3之间的数据
select * from 表名 where not between id 1 and 3; 查询id不在1到3之间的数据
where高级(like)匹配:%:通配符:%123%:包函123,%123或最后函有123
select * from 表名 where 字段 like '%123%'; 查询字段值包括123的信息
select * from 表名 where 字段 not like '%123%'; 查询字段值不为123的信息
and:和、or:或者
select * from 表名 where 字段=值 and 字段2=值2
括号结合运算:
select * from 表名 where 字段=值 and (字段2=值2 or 字段3=值3);
查找为空的数据:
slectr * from 表名 where 字段 is null;
查询不为空的数据:
select * from 表名 where 字段 is not null;
去重:distinct(字段内容重复的直接过滤)
select distinct 字段,字段2 from 表名
order by:排序 asc与desc,默认asc
单按字段(列)排序:
select * from 表名 where 字段1=值1 order by 字段 asc或desc;
多字段(列)排序:先按第一个字段要求排序,如果第一个字段有相同内容再用第二字段来排序
select * from 表名 where 字段2=值2 order by 字段 asc或desc,字段2 asc或desc;
limit:查询数量
select * from 表名 where 字段=值 order by 字段 desc limit [起始,]多少条记录;
insert into 与 select组合使用:将查询结果全部插入表1
insert into 表1 select * from 表2 where 字段字!=值1
修改更新数据:updete
单个字段值修改:update 表名 set 需要修改的字段=修改成的值 where 字段=值3;
多个字段值修改:update 表名 set 需要修改的字段=修改成的值,需要修改的字段2=修改成的值2 where 字段=值3;
/**
* Likie
* 重启
* Linux(CentOs):/etc/init.d/mysqld restart
*
* 命令:
* DB:数据库
查看当前有哪些DB:show databases;
show databases;
添加DB:create database gc;
create database gc;
删除DB:drop database gc;
drop database gc;
table:数据表
选择数据库DB:(成功返回:Database changed)
use gc
查看数据表:show tables;show tables;
查看表结构(查看字段):descride 表名;
descride table_name
删除表:drop table 表名;
drop table table_name;
字段操作:
增加字段(增加列):alter table 表名 add 字段名 int(11) not null default 1;
alter table table_name add id int(11) not null default 1;
删除字段(删除列):alter table 表名 drop 字段名;
alter table table_name drop id;
修改字段名(修改列名)(数据类型不变):alter table 表名 change 原字段 新字段 varchar(255);
修改字段数据类型(修改列人数据类型):alter table 表名 change 字段 字段 新数据类型;
修改字段名和数据类型:alter table 表名 change 原字段 新字段 新数据类型;
表名操作:
修改表名:alter table 原表名 rename 新表名;
创建数据表及字段:
CREATE TABLE 表名(
id bigint(20),
caeate Time datetime,
ip varchar(255),
mobile varchar(255),
nickname varchar(255),
passwd varchar(255),
brief text,
);
删除表:drop table 表名
*
*
*/
/**
SQL查询语句:
select * from 表名;
select 字段,字段2,字段3 from 表名;
SQL插入数据:
insert into 表名 value(值1,值2,...)
insert into 表名 (字段1,字段2)value('值1','值2')
where语法
select 字段或* from 表名 where 字段='字段值';
where高级(in)语法,多值或值为查询后
select * from 表名 where 字段 in(值1,值2);
select * from 表名 where 字段 in(select 字段 from 表名);
where高级(between)之间
select * from 表名 where between id 1 and 3; 查询id为1到3之间的数据
select * from 表名 where not between id 1 and 3; 查询id不在1到3之间的数据
where高级(like)匹配:%:通配符:%123%:包函123,%123或最后函有123
select * from 表名 where 字段 like '%123%'; 查询字段值包括123的信息
select * from 表名 where 字段 not like '%123%'; 查询字段值不为123的信息
and:和、or:或者
select * from 表名 where 字段=值 and 字段2=值2
括号结合运算:
select * from 表名 where 字段=值 and (字段2=值2 or 字段3=值3);
查找为空的数据:
slectr * from 表名 where 字段 is null;
查询不为空的数据:
select * from 表名 where 字段 is not null;
去重:distinct(字段内容重复的直接过滤)
select distinct 字段,字段2 from 表名
order by:排序 asc与desc,默认asc
单按字段(列)排序:
select * from 表名 where 字段1=值1 order by 字段 asc或desc;
多字段(列)排序:先按第一个字段要求排序,如果第一个字段有相同内容再用第二字段来排序
select * from 表名 where 字段2=值2 order by 字段 asc或desc,字段2 asc或desc;
limit:查询数量
select * from 表名 where 字段=值 order by 字段 desc limit [起始,]多少条记录;
insert into 与 select组合使用:将查询结果全部插入表1
insert into 表1 select * from 表2 where 字段字!=值1
修改更新数据:updete
单个字段值修改:update 表名 set 需要修改的字段=修改成的值 where 字段=值3;
多个字段值修改:update 表名 set 需要修改的字段=修改成的值,需要修改的字段2=修改成的值2 where 字段=值3;
相关文章推荐
- Mysql系列五:数据库分库分表中间件mycat的安装和mycat配置详解
- PHP4 与 MySQL 数据库操作函数详解
- PHP4 与 MySQL 数据库操作函数详解
- php连接mysql 数据库的函数及用法详解
- cygwin下用mysql c api连接数据库详解
- mysql 数据库分区详解
- [菜鸟系列].NET 插入数据到MySql 数据库乱码问题
- 渣渣小本求职复习之路每天一博客系列——数据库基础(MySQL)(1)
- Mysql 数据库导入导出 sql文件导入导出 命令 详解~~Myself
- Delphi XE3 数据库系列(一):使用dbexpress访问mysql
- MySQL 数据库性能优化之缓存参数优化(这是 MySQL数据库性能优化专题 系列的第一篇文章)
- PHP4 与 MySQL 数据库操作函数详解
- Windows+OpenLDAP+MySQL配置及使用详解(二)——数据库初始化
- Windows+OpenLDAP+MySQL配置及使用详解(二)——数据库初始化
- PHP4 与 MySQL 数据库操作函数详解
- ubuntu MySQL导入导出数据库详解
- 数据库技巧:MySQL十大优化技巧详解
- mysql dba系统学习(22)数据库事务详解
- 卦卦学mysql系列(1)——mysql入门 对数据库的操作