mysql 高效能

來源:互聯網
上載者:User

標籤: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 高效能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.