MySQL 5.7 GA Release 釋出
MySQL 5.7 的特色如下:(What’s New in MySQL 5.7)- 3x Faster Performance
- New Optimizer
- Native JSON Support
- Multi-source Replication
- GIS Spatial Extensions
- And other important enhancements
- MySQL 5.7 的 Benchmarks 可見:MySQL :: Benchmarks
def self.use_index(index)
from("#{self.table_name} USE INDEX(#{index})")
end
perl -pi -e 's/latin1/utf8/g' DBNAME.utf8.sql
[mysqld]
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_log_file_size=1G
innodb_buffer_pool_size=4G
Sidenote: Whatever your set for innodb_buffer_pool_size, make sure innodb_log_file_size is 25% of innodb_buffer_pool_size.OPTIMIZE TABLE mydb.mytable and the file /var/lib/mysql/mydb/mytable.ibd will actually shrink.mysqldump -h DB_HOST -u DB_USER -p DB_PASSWORD --opt --quote-names \
--skip-set-charset --default-character-set=latin1 DB_NAME > DB_NAME-dump.sql
mysql -h DB_HOST -u DB_USER -p DB_PASSWORD \
--default-character-set=utf8 DB_NAME < DB_NAME-dump.sql
mysql>SET GLOBAL query_cache_size = 1000000;Query OK, 0 rows affected (0.04 sec) mysql>SHOW VARIABLES LIKE 'query_cache_size';+------------------+--------+ | Variable_name | Value | +------------------+--------+ | query_cache_size | 999424 | +------------------+--------+
原理
if ('day' == $Period) {
$sql = "select `Ranking`,RankingType, date_format(`RankingDate`, '%m/%d') as dt, `RankingDate` from `Ranking` where 1 RankingType order by `RankingDate` DESC,RankingType";
}
elseif ('week' == $Period) {
$sql = "select `Ranking`,RankingType, date_format(date_add(`RankingDate`,interval 6-date_format(`RankingDate`,'%w') day),'%m/%d') as dt, date_format(`RankingDate`,'%X %V') as dt2, `RankingDate` from `Ranking` where 1 group by dt2 ,RankingType order by `RankingDate` DESC,RankingType";
}
elseif ('month' == $Period) {
$sql = "select `Ranking`,RankingType, date_format(`RankingDate`,'%Y-%m') as dt, `RankingDate` from `Ranking` where 1 group by dt ,RankingType order by `RankingDate` DESC,RankingType";
}
| 操作功能 | SQL 語法 |
說 明
|
| 建立資料庫 | create database 資料庫名稱; | |
| 列出所有資料庫 | show databases; | |
| 刪除資料庫 | drop database 資料庫名稱; | |
| 使用資料庫 | use 資料庫名稱; | |
| 建立資料表 | create table 資料表名稱( sn integer auto_increment primary key, name char(20), mail char(50), home char(50), messages char(50) ); |
常用資料庫資料型態
1. INT (整數) 2. CHAR (1~255字元字串) 3. VARCHAR (不超過255字元不定長度字串) 4. TEXT (不定長度字串最多65535字元) |
| 列出資料表欄位資訊 | describe 資料表名稱; | |
| 修改資料表欄位 | alter table 資料表名稱 charange column 原來欄位名稱 新欄位名稱 資料型態; |
|
| 新增資料表欄位 | alter table 資料表名稱 add column 欄位名稱 資料型態; | |
| 刪除資料表欄位 | alter table 資料表名稱 drop column 欄位名稱; | |
| 刪除資料表 | drop 資料表名稱 ; | |
| 插入欄位資料 | insert into 資料表名稱(欄位1,欄位2,欄位3,欄位4,
...... 欄位N) values('值1','值2','值3','值4', ...... '值N'); |
|
| 更新修改欄位資料 | update 資料表名稱
set 欄位1='值1',欄位2='值2',欄位3='值3',... 欄位N='值N' where 條件式 (例如 sn='5' 或 name='蘇國憲' ); |
|
| 查詢單一欄位資料 | select 欄位名 from 資料表名稱; | |
| 查詢多個欄位資料 | select 欄位名, 欄位名, 欄位名 from 資料表名稱; | |
| 查詢欄位資料的唯一值 | select distinct 欄位名 from 資料表名稱; | 重複值只列一次 |
| 查詢所有欄位資料 | select * from 資料表名稱 ; | |
| 條件式查詢 | select * from 資料表名稱 where 條件式 (例如 sn='5') ; | (=, <, >, !=) |
| 條件式查詢 and | select * from 資料表名稱 where 條件式1 and 條件式2; | |
| 條件式查詢 or | select * from 資料表名稱 where 條件式1 or 條件式2; | |
| 查詢某一範圍 between | select * from 資料表名稱 where 欄位名 between 值1 and 值2 | 值為數字 |
| 查詢空值欄位的資料 | select * from 資料表名稱 where 欄位名 is null | not null |
| 查詢特定筆數資料 | select * from 資料表名稱 limit 8, 10; | 第9筆開始選取10筆 |
| 查詢結果遞增排序 | select * from 資料表名稱 order by 欄位名; | |
| 查詢結果遞減排序 | select * from 資料表名稱 order by 欄位名 desc ; | |
| 查詢比對字串列出單一欄位 | select 欄位名 from 資料表名稱 where 欄位名 like '%字串%'; | |
| 查詢比對字串列出所有欄位 | select * from 資料表名稱 where 欄位名 like '%字串%'; | |
| 刪除條件值資料 | delete from 資料表名稱 where 條件式 (例如 sn='5' 或 id='91001' ); | |
| 刪除條件值資料 | delete from 資料表名稱 where 條件式1 and 條件式2; | |
| 刪除條件值資料 | delete from 資料表名稱 where 條件式1 or 條件式2; | |
| 比對刪除條件值資料 | delete from 資料表名稱 where 欄位名 like '%字串%'; | |
SELECT * FROM `user` ORDER BY CONVERT(`user_name` USING big5),user_name DESC
| 1.效能優,預設引擎,為 Mysql最早使用的引擎 2.使用MyISAM將具備三種 檔案: .frm (table format) .MYD(data file) .MYI(index file) 3.所有資料是以low byte first儲存,數字型key是以high byte first儲存以利索引 4.支援大檔 ( > 63 bit) 5.支援42億(2^32次方) 資料筆數,如果MySQL編譯有加入--with-big-tables 選項可支援多一倍(2^32次方 * 2)資料量 6.不支援事務處理,例如關聯式 資料庫 7.AUTO_INCREMENT 更快(至少10%),序列的值被刪除之後就不能再利用 |
| 1.具備Commit, Rollback和當掉復原的事務處理能力,可保護使用者資料 2.可進行row-level的 鎖定同時維持nonlocking reads,以支援多人同時連線狀態 3.可支援FOREIGN KEY 4.InnoDB是專門為了大容 量資料的最大效率進行設計的,CPU效能是其他的disk-based資料庫引擎所不及的 5.InnoDB儲 存他的表和 index在一個表空間中,此表空間可能包含幾個檔(有可能在不同disk partitions),此點和MyISAM不同,MyISAM是一個表一個檔案,這差一點造成InnoDB表個可以非常大,即使是超過系統的file size(例如2GB)都可處理 6.此為Windows安裝檔的 默認值 7.InnoDB上可處理存儲超 過1TB的數據,可支援例如平均每秒800次插入/更新的負荷 8.支援關聯資料庫 |
| 1.不要將MyISAM轉成InnoDB table 2.不要在NFS格式上將 InnoDB設定成data files或log file,檔案容易被鎖住 3.一個表不能包含超過1000 欄 4.內部key最大長度為 3500 bytes,MySQL限制為3072 Bytes 5.每筆資料最長約為8000 Bytes,變長的欄位(例如Varchar/BLOB/TEXT)需小於4000 Bytes. 6.即使InnoDB支援row size大於65535,也不能定義一個包含VARBINARY/VARCHAR的欄位總合大於65535 (會出現錯誤訊息) 7.在依些舊系統中,檔案需小於 2GB,這並不限制InnoDB的使用,但你如果需要大的tablespace則需額外進行設定 8.InnoDB的log file總共大小需小於4GB 9.最小的tablespace 大小為10MB,最大的大小為64TB,這也是table的最大值 10.不支援FULLTEXT 11.InnoDB不保留每個表 個的總數統計,也就是count(*)則必須進行index計算 12.在InnoDB 中,AUTO_INCREMENT欄位如果存在,則"必須"定義一個index欄位包含AUTO_INCREMENT欄;在MyISAM 中,AUTO_INCREMENT欄位"可能"為index中的一欄 13.DELETE FROM Table為逐筆資料刪除,非整個table刪除 14.在InnoDB 中,TRUNCATE Table相同於DELETE Table,AUTO_INCREMENT不重置 |
| 1.將所有數據保存在RAM中, 可提供極快的訪問,但如果關機資料就會消失無法儲存 2.每一個MEMORY Table關聯一個Disk file(.frm) 3.常使用在 create temporary table上,連線結束後就釋放空間 4.預設使用hash indexes(速度非常快且對於建立臨時表格非常有效) 5.MEMORY不支持BLOB 或TEXT列 6.MEMORY使用定長的儲存 格式列 7.可支援 AUTO_INCREMENT |