码迷,mamicode.com
首页 > 数据库 > 详细

mysql 高性能

时间:2014-09-21 03:37:39      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:color   使用   ar   数据   2014   sp   on   c   amp   

第一章节:
共享锁(读锁),排他锁(写锁)

查询数据表所使用的存储引擎:
show table status like ‘表名‘ \G

转换数据表的存储引擎:
alter table 表名 engine=引擎名称
as:
alter table mytable engine=Innodb;
---------
第三章节
char,varchar兄弟类型: binary,  varbinary,用来保存二进制字符串,但是保存的是字节,而不是字符

blob和text分别以二进制和字符形式保存大量数据
都有各自的数据类型家族:
text: tinytext, smalltext, text,mediumtext, longtext,(text相当于smalltext)
blob:tinyblob, smallblob, blob, mediumblob,longblob(blob相当于smallblob)

mysql不能索引这些 (blob,text...)的完整长度,也不能排序使用索引

enum类型,as:
create table enum_table(
  e enum(‘yes‘, ‘no‘) not null,
  ....
);

日期和时间类型
datetime:精度为秒,格式如 YYMMDDHHMMSS,与时区无关,默认时格式如下:
2014-09-18 21:38:08
时间范围为 1001-9999年

timestamp:保持了自 1970-1-1午夜(格林尼治标准时间)以来的秒数,与 unix的时间戳相同,与mysql服务器,操作系统,客户端时区设置有关(推荐用)

有范围的查询,会失去索引的意义, 如
select * from where id>100 order by date asc

正则化(根据范式特征,分表)与非正则化(非范式)

第四章
Mysql
select t1.id from test.t1 inner join test.t2 using(id) where t1.id > 500
==
where t1.id > 500 and t2.id > 500
相当于 using(id)其实就是 两个表都使用了后来的 where 条件,但必须是两个表的字段名称相同,局限于 mysql 数据库

//统计颜色值
select sum(if(color=‘blue‘, 1, 0)) as blue,
sum(if(color=‘red‘), 1, 0) as red from 表名
==
select count(color=‘blue‘ or null) as blue,count(color=‘red‘ or null) as red from 表名

自定义变量,但是只能是数值的
tt(id, name);
as:
SET @id :=1; //表示从1开始
select name, @id := @id+1 as myid from tt limit 3;
则表示 id = 2开始接下来的三条数据

第五章

mysql 高性能

标签:color   使用   ar   数据   2014   sp   on   c   amp   

原文地址:http://www.cnblogs.com/lin3615/p/3984058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!