<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>丫忠的伺服器 &#187; mysql</title>
	<atom:link href="http://homeserver.com.tw/%E6%96%87%E7%AB%A0%E5%88%86%E9%A1%9E/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://homeserver.com.tw</link>
	<description>提供工作心得，教學文件的部落格</description>
	<lastBuildDate>Thu, 26 Aug 2010 03:38:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>mysql proxy讀寫分流(二)-加入RW splitting</title>
		<link>http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/</link>
		<comments>http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 07:39:47 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysq loadbalance]]></category>
		<category><![CDATA[mysql proxy]]></category>
		<category><![CDATA[mysql rw splitting]]></category>
		<category><![CDATA[mysql 負載]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=1045</guid>
		<description><![CDATA[上一篇中提到 安裝LUA及MySQL Proxy後，接下來就是RW splitting(讀寫分流)的部份了
整體的概念圖跟上一篇MySQL Proxy安裝方式相同，丫忠再補上一個對應port的圖表：

針對上圖的架構，首先需要了解幾點基本的觀念：

所有寫入(ADD、UPDATE、DELETE)的動作都是針對MySQL Master
所有讀取(SELECT)的動作都是大部分都是在MySQL Slave(部份在MySQL Master，因為涉及到是否同步完成的關係，請見下面 MySQL Proxy如何解決同步延遲問題 的說明)
MySQL Master與MySQL Slave已經建立起 同步(Replication)的機制
MySQL Proxy也一個MySQL 的客戶端(Client)，也是一個MySQL的伺服器端(Server)

如果你對於上面的觀念都已經清楚後，對於上圖的流程我想應該很容易了解。丫忠就流程架構做個簡單說明：
1. 以往 所有應用程式(PHP)存取MySQL都是直接對應至MySQL Master，有了 MySQL Proxy當代理後，現在所有應用程式的連線都是連接至MySQL Proxy
2. 當MySQL Proxy接收到應用程式的SQL語法後，會自動判斷SQL語法是讀取還是寫入，再分別將寫入的SQL語法對應至MySQL Master、將讀取的SQL語法對應至MySQL Slave
3. 寫入MySQL Master的資料會透過Replication機制(binlog)同步至所有的MySQL Slave
看到這裡好像一切都很順利也沒有任何問題，如果你有意識到【當應用程式透過MySQL Proxy寫入資料到MySQL Master後， 此時應用程式又立即讀取剛寫入的資料；但是，MySQL Master還沒有同步至MySQL Slave，那麼應用程式讀取的資料不就是舊的資料嗎？】沒錯，當你有這樣的疑問時，表示你已經深入了解這個架構了，底下先針對MySQl Proxy如何解決同步延遲問題做說明
MySQL Proxy如何解決同步延遲問題
解決方式是在MySQL Master上新增一個自增表(count table)，當MySQL Master接收到更新資料的動作時便會觸發這個觸發器，這個觸發器會更新自增表(count table)中的記錄，如下圖所示：

(圖片來源：http://hi.baidu.com)
因為自增表(count table)也會一起同步(replication)至MySQL Slave，當應用程式透過MySQL Proxy讀取資料時，MySQL Proxy會先向MySQL Master和MySQL Slave的自增表(count table)發送查詢請求，當MySQL Master和MySQL Slave的資料相同時，MySQL Proxy就可以認定MySQL Master和MySQL Slave的資料是一致的，接著把應用程式的請求對應至MySQL Slave主機上，否則就將請求發送至MySQL Master上，如下圖所示：

(圖片來源：http://hi.baidu.com)
透過自增表(count table)的方式就可以解決同步延遲的問題，ok~了解整個架構及克服同步延遲的問題後，再來就是實做的部份啦，底下將說明如何啟動MySQL Proxy及設定相關參數
本章應用一個範例架構來說明RW [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(一)-mysql proxy的安裝方式'>mysql proxy讀寫分流(一)-mysql proxy的安裝方式</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/' rel='bookmark' title='Permanent Link: MySQL Replication(Master Slave負載平衡)'>MySQL Replication(Master Slave負載平衡)</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/' rel='bookmark' title='Permanent Link: mysql(my.cnf)設定檔說明(二)'>mysql(my.cnf)設定檔說明(二)</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql proxy讀寫分流(一)-mysql proxy的安裝方式</title>
		<link>http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/</link>
		<comments>http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 02:42:19 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql proxy]]></category>
		<category><![CDATA[mysql rw splitting]]></category>
		<category><![CDATA[mysql負載]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=1036</guid>
		<description><![CDATA[丫忠在上一篇文章中描述到 MySQL Replication 的架構，接著此篇將延伸那個架構再加入 MySQL Proxy來當mysql的代理，那麼要代理那些工作呢？主要是將讀寫分開，讓MySQL Proxy自動判斷來源的指令中是讀取(SELECT)還是寫入(ADD、UPDATE、DELETE)，然後再將寫入的動作移至Master主機，讀取的動作平均移至多台的Slave主機。
當然，如果你的程式中已經將讀取跟寫入的動作已經自動分配至各個不同的mysql，那麼你就可以忽略本篇文章。
MySQL Proxy整體架構的概念圖如下：

(圖片來源：http://kaj.arno.fi)
讓我們先來看一下 MySQL Proxy官網 對於MySQL Proxy的功能及特性的說法如下：
MySQL Proxy is a simple program that sits between your client and MySQL server(s) that can monitor, analyze or transform their communication. Its flexibility allows for unlimited uses; common ones include:

load balancing
failover (故障恢復)
query analysis
query filtering and modification
RW Splitting (http://forge.mysql.com/wiki/MySQL_Proxy_RW_Splitting)
&#8230; and many more

要使用MySQL Proxy除了先了解MySQL Proxy的功能外，再來就是MySQL [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(二)-加入RW splitting'>mysql proxy讀寫分流(二)-加入RW splitting</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/' rel='bookmark' title='Permanent Link: MySQL Replication(Master Slave負載平衡)'>MySQL Replication(Master Slave負載平衡)</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-telnet-ip-3306%e6%b2%92%e6%9c%89%e5%9b%9e%e6%87%89/' rel='bookmark' title='Permanent Link: mysql-telnet ip 3306沒有回應'>mysql-telnet ip 3306沒有回應</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL Replication(Master Slave負載平衡)</title>
		<link>http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/</link>
		<comments>http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 09:43:55 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql master slave]]></category>
		<category><![CDATA[mysql replication]]></category>
		<category><![CDATA[mysql 備援]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=1025</guid>
		<description><![CDATA[前陣子丫忠一直在尋找MySQL負載平衡的方式，搞了一陣子後終於暫告一個段落，趁著記憶猶新時趕快做個筆記，給有需要的人參考，自己日後也可以參考啦!
網路上有很多人提供MySQL的負載方式，例如：Master Slave架構、MySQL MMM架構、DRBD、Cluster、HeartBeat&#8230;等一堆MySQL負載平衡的架構，一直MySQL負載平衡的架構，到底要選擇那一個方式才是最好的？
丫忠認為符合自己個人(公司)需求的架構最好，再來是穩定及簡單好維護；如果只是單純的公司形象網站或者是一般個人的Blog，總不能想著要架構Master + Slave，外加MySQL Proxy做讀寫分流，再替Master做個HeartBeat的備援，再後再加幾台memcached來加快搜尋速度&#8230;.等，如果只是為了測試架構倒是可以玩一玩，如果是要用在運作中的主機的話，那丫忠勸您要3思 再3思了，不要搞到後來出問題時找不到問題，或者資料不一致時，到時候拜再多的神也沒用囉&#8230;
講了一堆哩哩扣扣都還沒進入主題，MySQL 的M/S架構(Master Slave)是負載平衡中最基礎的架構，也就是很多的架構都是從此延伸出去，這也是丫忠認為最簡單的架構之一了。如果可以閱讀英文的網友可以直接參考MySQL官網的資料 http://dev.mysql.com/doc/refman/5.0/en/replication.html
MySQL M/S架構的原理大致如下：
1.  新增(Add)、刪除(delete)、修改(update)的動作必須移至Master
2. Master會針對這些動作的語法自動產生binlog 檔案
3. Master會將binlog檔案同步(Replication)至所有的Slave
4. Slave會執行binlog檔案中的SQL語法
原理的圖形概念如下：

(圖形來源：http://baoz.net)
看到這個架構的原理，或者有些網友就想到了，程式中針對MySQL的動作(SELECT、UPDATE、DELETE、ADD&#8230;)都是固定在同一台MySQL中運作，除非是修改程式，否則要怎樣將讀寫分開呢？這個部份就要加入MySQL Proxy的概念了，MySQL Proxy可以自動將讀寫分開，不用修改程式碼，不過本章的重點不是在MySQL Proxy，有興趣的網友可以先參考 http://forge.mysql.com/wiki/MySQL_Proxy
了解MySQL M/S的運作原理之後，再來就是MySQL的設定了，假設要完成的架構如下：

Master：192.168.10.2
Slave：192.168.10.3
只有同步(Replication) 資料庫mytest

MySQL Replication Master設定
Master要做的流程大概如下：
1. 設定 一個同步的帳號(如果是用root，可以忽略此步驟)
2. 設定my.cnf
3. 將資料庫變成唯讀(read only)
4. 將mytest資料匯出(mysqldump或tar)
5.  解除資料唯讀狀態
6. 重新啟動mysql讓剛設定的my.cnf 生效
7. 將匯出的資料拷貝(scp)至slave
下面針對Master流程的部份，做個詳細說明：
1. 設定一個同步的帳號repl，密碼為slavepass，讓repl具有REPLICATION的權限，相關指令如下：
$mysql -u root -p    #進入mysql
mysql&#62;CREATE USER &#8216;repl&#8217;@'%&#8217; IDENTIFIED BY &#8217;slavepass&#8217;;
mysql&#62;GRANT REPLICATION SLAVE ON *.* TO &#8216;repl&#8217;@'%&#8217;;
2. Master主機必須產生binlog檔案，並且指定只有同步 mytest 這個資料庫，/etc/my.cnf 的修改如下：
[mysqld]
server-id [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysql-%e5%90%84%e7%a8%aebinlog_format%e5%84%aa%e7%bc%ba%e9%bb%9e%e6%af%94%e8%bc%83/' rel='bookmark' title='Permanent Link: mysql 各種binlog_format優缺點比較'>mysql 各種binlog_format優缺點比較</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(二)-加入RW splitting'>mysql proxy讀寫分流(二)-加入RW splitting</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(一)-mysql proxy的安裝方式'>mysql proxy讀寫分流(一)-mysql proxy的安裝方式</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>mysql(my.cnf)設定檔說明(二)</title>
		<link>http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/</link>
		<comments>http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 04:12:32 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[my.cnf]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=1018</guid>
		<description><![CDATA[丫忠最近一直在搞mysql的東東，不得不參考大量的設定檔及說明，剛又看到一個關於mysql設定檔相關的說明，再次的轉貼到此給自己及大家參考看看囉!
MySQL資料庫5.0的my.cnf配置選項概述:
 
mysqld程序&#8211;目錄和文件
 basedir = path 使用給定目錄作為根目錄(安裝目錄)。
 character-sets-dir = path 給出存放著字符集的目錄。
 datadir = path 從給定目錄讀取資料庫文件。
 pid-file = filename 為mysqld程序指定一個存放進程ID的文件(僅適用於UNIX/Linux系統)
Init-V腳本需要使用這個文件裡的進程ID結束mysqld進程。
 socket = filename 為MySQL客戶程序與服務器之間的本地通信指定一個套接字文件
(僅適用於UNIX/Linux系統; 默認設置一般是/var/lib/mysql/mysql.sock文件)。
在Windows環境下，如果MySQL客戶與服務器是通過命名管道進行通信的，&#8211;sock選項給出的將是該命名管道的名字(默認設置是MySQL)。
 lower_case_table_name = 1/0 新目錄和資料表的名字是否只允許使用小寫字母; 這個選項在Windows環境下的默認設置是1(只允許使用小寫字母)。
 
mysqld程序&#8211;語言設置
 character-sets-server = name 新資料庫或資料表的默認字符集。為了與MySQL的早期版本保持兼容，這個字符集也可以用&#8211;default-character-set選項給出; 但這個選項已經顯得有點過時了。
 collation-server = name 新資料庫或資料表的默認排序方式。
 lanuage = name 用指定的語言顯示出錯信息。
 
mysqld程序&#8211;通信、網絡、信息安全
 enable-named-pipes 允許Windows 2000/XP環境下的客戶和服務器使用命名管道(named pipe)進行通信。這個命名管道的默認名字是MySQL，但可以用&#8211;socket選項來改變。
 local-infile [=0] 允許/禁止使用LOAD DATA LOCAL語句來處理本地文件。
 myisam-recover [=opt1, opt2, [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e/' rel='bookmark' title='Permanent Link: mysql(my.cnf)設定檔說明'>mysql(my.cnf)設定檔說明</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(二)-加入RW splitting'>mysql proxy讀寫分流(二)-加入RW splitting</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/' rel='bookmark' title='Permanent Link: MySQL Replication(Master Slave負載平衡)'>MySQL Replication(Master Slave負載平衡)</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql 各種binlog_format優缺點比較</title>
		<link>http://homeserver.com.tw/mysql/mysql-%e5%90%84%e7%a8%aebinlog_format%e5%84%aa%e7%bc%ba%e9%bb%9e%e6%af%94%e8%bc%83/</link>
		<comments>http://homeserver.com.tw/mysql/mysql-%e5%90%84%e7%a8%aebinlog_format%e5%84%aa%e7%bc%ba%e9%bb%9e%e6%af%94%e8%bc%83/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 08:05:11 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=1008</guid>
		<description><![CDATA[MySQL 5.1 中，在復制(Replication)方面的改進就是引進了新的複制技術：基於行的複制。 簡言之，這種新技術就是關注表中發生變化的記錄，而非以前的照抄 binlog 模式。 從 MySQL 5.1.12 開始，可以用以下三種模式來實現：基於SQL語句的複制(statement-based replication, SBR)，基於行的複制(row-based replication, RBR)，混合模式複制(mixed-based replication, MBR)。 相應地，binlog的格式也有三種：STATEMENT，ROW，MIXED。MBR 模式中，SBR 模式是默認的。
在運行時可以動態低改變binlog的格式，除了以下幾種情況：
1. 存儲過程或者觸發器中間
2. 啟用了NDB
3. 當前會話試用 RBR 模式，並且已打開了臨時表
如果binlog採用了 MIXED 模式，那麼在以下幾種情況下會自動將binlog的模式由 SBR 模式改成 RBR 模式。
1. 當DML語句更新一個NDB表時
2. 當函數中包含 UUID() 時
3. 2個及以上包含 AUTO_INCREMENT 字段的表被更新時
4. 行任何 INSERT DELAYED 語句時
5. 用 UDF 時
6. 視圖中必須要求使用 RBR 時，例如創建視圖是使用了 UUID() 函數
設定主從復制(Replication)模式的方法非常簡單，只要在以前設定複製配置的基礎上，再加一個參數：
binlog_format=&#8217;STATEMENT&#8217;
#binlog_format=&#8217;ROW&#8217;
#binlog_format=&#8217;MIXED&#8217;
當然了，也可以在運行時動態修改binlog的格式。 例如
mysql> SET SESSION binlog_format = &#8216;STATEMENT&#8217;;
mysql> [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/' rel='bookmark' title='Permanent Link: MySQL Replication(Master Slave負載平衡)'>MySQL Replication(Master Slave負載平衡)</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(一)-mysql proxy的安裝方式'>mysql proxy讀寫分流(一)-mysql proxy的安裝方式</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(二)-加入RW splitting'>mysql proxy讀寫分流(二)-加入RW splitting</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql-%e5%90%84%e7%a8%aebinlog_format%e5%84%aa%e7%bc%ba%e9%bb%9e%e6%af%94%e8%bc%83/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql(my.cnf)設定檔說明</title>
		<link>http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e/</link>
		<comments>http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 07:31:57 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[my.cnf]]></category>
		<category><![CDATA[mysql replication]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=1004</guid>
		<description><![CDATA[丫忠最近要來實做mysql Replication的架構，在做之前當然是要先把參考資料都找出來，底下丫忠從網路上爬出來的文章，有針對mysql的設定檔(my.cnf)做中文的說明，剛好可以參考的到!
#BEGIN CONFIG INFO
#DESCR: 4GB RAM,只使用InnoDB, ACID,少量的連接,隊列負載大
#TYPE: SYSTEM
#END CONFIG INFO
#
#此mysql配置文件例子針對4G內存
#主要使用INNODB
#處理複雜隊列並且連接數量較少的mysql服務器
#
#將此文件複製到/etc/my.cnf 作為全局設置,
# mysql-data-dir/my.cnf 作為服務器指定設置
# (@localstatedir@ for this installation) 或者放入
# ~/.my.cnf 作為用戶設置.
#
# 在此配置文件中, 你可以使用所有程序支持的長選項.
# 如果想獲悉程序支持的所有選項
#請在程序後加上』&#8211;help』參數運行程序.
#
# 關於獨立選項更多的細節信息可以在手冊內找到
#
#
#以下選項會被MySQL客戶端應用讀取.
#注意只有MySQL附帶的客戶端應用程序保證可以讀取這段內容.
#如果你想你自己的MySQL應用程序獲取這些值
#需要在MySQL客戶端庫初始化的時候指定這些選項
#
[client]
#password    = [your_password]
port        = @MYSQL_TCP_PORT@
socket        = @MYSQL_UNIX_ADDR@
# *** 應用定制選項***
#
# MySQL 服務端
#
[mysqld]
# 一般配置選項
port    [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/' rel='bookmark' title='Permanent Link: mysql(my.cnf)設定檔說明(二)'>mysql(my.cnf)設定檔說明(二)</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-replication-master-slave%e8%b2%a0%e8%bc%89%e5%b9%b3%e8%a1%a1/' rel='bookmark' title='Permanent Link: MySQL Replication(Master Slave負載平衡)'>MySQL Replication(Master Slave負載平衡)</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(二)-加入RW splitting'>mysql proxy讀寫分流(二)-加入RW splitting</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cacti-apache status-mysql套件實圖</title>
		<link>http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%b7%a5%e5%85%b7/cacti-apache-status-mysql%e5%a5%97%e4%bb%b6%e5%af%a6%e5%9c%96/</link>
		<comments>http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%b7%a5%e5%85%b7/cacti-apache-status-mysql%e5%a5%97%e4%bb%b6%e5%af%a6%e5%9c%96/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 02:33:47 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[網路工具]]></category>
		<category><![CDATA[apachestats]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[cacti apache]]></category>
		<category><![CDATA[cacti apache status]]></category>
		<category><![CDATA[mysql-cacti-templates]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=897</guid>
		<description><![CDATA[丫忠 在上一篇【cacti 安裝教學】中提到如何安裝 cacti此套流量監控系統，當安裝完成後 cacti套件就會附上一些templates了，例如：ucd/net &#8211; Load Average、ucd/net &#8211; CPU Usage&#8230;等，如果你只是要監控系統的CPU、記憶體的效能，丫忠認為用原先附上的templates就已經足夠了。
不過，如果你需要監控更多類型的伺服器，例如：Apache以及MySQL等伺服器的效能，那就必須額外安裝templates 。
底下 丫忠 列出這2個套件的下載點，有興趣的朋友可以自行下載安裝：
cacti apache的templates：ApacheStats 0.8.2
cacti mysql的templates：mysql-cacti-templates// 


底下為 cacti 透過snmp監控系統狀態的實圖：
監控的項目：
Traffic-eth0
Memory Usage
CPU Usage
當然還有很多監控的項目沒有加上

底下為丫忠安裝 ApacheStats 後的實圖：
監控的項目：
Apache Stats CPU Usage
Apache Stats Bytes / Hit
Apache Stats Thread Details
Apache Stats Thread scroeboard
當然還有很多監控的項目沒有加上

底下為安裝 cacti-mysql-templates後的實圖：
監控的項目：
MySQL Select Types
MySQL ProcessList
MySQL Network Traffic
MySQL MyISAM Indexes
MySQL Handlers
MySQL connections
MySQL Command Counters
當然還有很多監控的項目沒有加上，你可以依自行需求加上graph



本文相關的文章Cacti 安裝教學
apache 網頁傳送壓縮(ob_gzhandler,zlib)
dns apache 中文網址 詳細說明



本文相關的文章<ol><li><a href='http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%a5%97%e4%bb%b6%e5%ae%89%e8%a3%9d%e6%95%99%e5%ad%b8/cacti-%e5%ae%89%e8%a3%9d%e6%95%99%e5%ad%b8/' rel='bookmark' title='Permanent Link: Cacti 安裝教學'>Cacti 安裝教學</a></li>
<li><a href='http://homeserver.com.tw/%e4%b8%ab%e5%bf%a0%e7%9a%84%e7%94%9f%e6%b4%bb%e7%b6%b2%e8%aa%8c/apache-%e7%b6%b2%e9%a0%81%e5%82%b3%e9%80%81%e5%a3%93%e7%b8%aeob_gzhandlerzlib/' rel='bookmark' title='Permanent Link: apache 網頁傳送壓縮(ob_gzhandler,zlib)'>apache 網頁傳送壓縮(ob_gzhandler,zlib)</a></li>
<li><a href='http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%a5%97%e4%bb%b6%e5%ae%89%e8%a3%9d%e6%95%99%e5%ad%b8/dns-apache-%e4%b8%ad%e6%96%87%e7%b6%b2%e5%9d%80-%e8%a9%b3%e7%b4%b0%e8%aa%aa%e6%98%8e/' rel='bookmark' title='Permanent Link: dns apache 中文網址 詳細說明'>dns apache 中文網址 詳細說明</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%b7%a5%e5%85%b7/cacti-apache-status-mysql%e5%a5%97%e4%bb%b6%e5%af%a6%e5%9c%96/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL最佳化分析指令EXPLAIN</title>
		<link>http://homeserver.com.tw/mysql/mysql%e6%9c%80%e4%bd%b3%e5%8c%96%e5%88%86%e6%9e%90%e6%8c%87%e4%bb%a4explain/</link>
		<comments>http://homeserver.com.tw/mysql/mysql%e6%9c%80%e4%bd%b3%e5%8c%96%e5%88%86%e6%9e%90%e6%8c%87%e4%bb%a4explain/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 08:32:55 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[explain]]></category>
		<category><![CDATA[mysql優化]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=809</guid>
		<description><![CDATA[上一篇丫忠介紹了 MySQL的查詢時間記錄 後，除了從記錄檔中去分析查詢時間外；另外，還有一個非常棒的指令可以用來分析SELECT指令在MySQL中的執行情況，那就是 EXPLAIN。
EXPLAIN 顯示的訊息可以用來幫助索引和查出最佳化的查詢語法。
EXPLAIN 使用的方式：
只要在SELECT語法前面加上 EXPLAIN 指令即可。
例如：EXPLAIN SELECT * FROM website WHERE url=&#8217;http://homeserver.com.tw&#8217;;
執行結果畫面如下：

 其中針對EXPLAIN的欄位說明如下：
table：關連到的資料表(Table)會顯示在此。
type：顯示使用了何種類型。從最優至最差的類型為const、eq_reg、ref、range、indexhe、ALL。
possible_keys：顯示可能使用到的索引。此為從WHERE語法中選擇一個適合的欄位名稱。
key：實際使用到的索引。如果為NULL，則是沒有使用索引。
key_len：使用索引的長度。長度越短 準確性越高。
ref：顯示那一列的索引被使用。一般是一個常數(const)。
rows：MySQL用來返回資料的筆數。
Extra：MySQL用來解析額外的查詢訊息。如果此欄位的值為：Using temporary和Using filesort，表示MySQL無法使用索引。
Extra為MySQL用來解析額外的查詢訊息，其中欄位值所代表的意義如下：
Distinct：當MySQL找到相關連的資料時，就不再搜尋。
Not exists：MySQL優化 LEFT JOIN，一旦找到符合的LEFT JOIN資料後，就不再搜尋。
Range checked for each Record(index map:#)：無法找到理想的索引。此為最慢的使用索引。
Using filesort：當出現這個值時，表示此SELECT語法需要優化。因為MySQL必須進行額外的步驟來進行查詢。
Using index：返回的資料是從索引中資料，而不是從實際的資料中返回，當返回的資料都出現在索引中的資料時就會發生此情況。
Using temporary：同Using filesort，表示此SELECT語法需要進行優化。此為MySQL必須建立一個暫時的資料表(Table)來儲存結果，此情況會發生在針對不同的資料進行ORDER BY，而不是GROUP BY。
Using where：使用WHERE語法中的欄位來返回結果。
System：system資料表，此為const連接類型的特殊情況。
Const：資料表中的一個記錄的最大值能夠符合這個查詢。因為只有一行，這個值就是常數，因為MySQL會先讀這個值然後把它當做常數。
eq_ref：MySQL在連接查詢時，會從最前面的資料表，對每一個記錄的聯合，從資料表中讀取一個記錄，在查詢時會使用索引為主鍵或唯一鍵的全部。
ref：只有在查詢使用了非唯一鍵或主鍵時才會發生。
range：使用索引返回一個範圍的結果。例如：使用大於&#62;或小於&#60;查詢時發生。
index：此為針對索引中的資料進行查詢。
ALL：針對每一筆記錄進行完全掃描，此為最壞的情況，應該盡量避免。


本文相關的文章mysql-telnet ip 3306沒有回應
mysql proxy讀寫分流(二)-加入RW splitting
cacti-apache status-mysql套件實圖



本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysql-telnet-ip-3306%e6%b2%92%e6%9c%89%e5%9b%9e%e6%87%89/' rel='bookmark' title='Permanent Link: mysql-telnet ip 3306沒有回應'>mysql-telnet ip 3306沒有回應</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy-rw-splitting-%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-%e8%b2%a0%e8%bc%89/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(二)-加入RW splitting'>mysql proxy讀寫分流(二)-加入RW splitting</a></li>
<li><a href='http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%b7%a5%e5%85%b7/cacti-apache-status-mysql%e5%a5%97%e4%bb%b6%e5%af%a6%e5%9c%96/' rel='bookmark' title='Permanent Link: cacti-apache status-mysql套件實圖'>cacti-apache status-mysql套件實圖</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql%e6%9c%80%e4%bd%b3%e5%8c%96%e5%88%86%e6%9e%90%e6%8c%87%e4%bb%a4explain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL的查詢時間(log-slow-queries)</title>
		<link>http://homeserver.com.tw/mysql/mysql%e7%9a%84%e6%9f%a5%e8%a9%a2%e6%99%82%e9%96%93log-slow-queries/</link>
		<comments>http://homeserver.com.tw/mysql/mysql%e7%9a%84%e6%9f%a5%e8%a9%a2%e6%99%82%e9%96%93log-slow-queries/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 06:28:09 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[log-slow-queries]]></category>
		<category><![CDATA[mysql查詢時間]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=802</guid>
		<description><![CDATA[MySQL資料庫的query查詢時間往往取決於【是否建立索引】、【資料量多寡】、【query查詢的方法】&#8230;等，然而【是否建立索引】的因素卻是影響query查詢時間最重要的因素之一。
舉個例子：如果你的Table(User)中有一個name的欄位，當你要查詢姓氏為&#8217;林&#8217;的使用者，通常你會這樣下SQL語法
SELECT * FROM User WHERE name like &#8216;%林%&#8217;;
如此，一般而言你會將name這個欄位加入index索引中，否則當資料量大時，query時間的快慢就會明顯出現差異了。
當完成了一個網站後，程式中針對MySQL查詢(query)的次數那麼多，那要如何找出query查詢時間較長的語法呢？其實在my.cnf設定檔中(一般在/etc/my.cnf)，已經提供了參數可以直接產生log記錄檔案，讓管理者可以很清楚了解到那些查詢(query)的語法花費較多的時間。
請在my.cnf設定檔中，找到[mysqld]標籤，在此標籤下面加上：
 log-slow-queries = /path/slow-query.log #slow query記錄檔的路儲存路徑
 long_query_time = 2 #query超過2秒時，則會記錄
 log-queries-not-using-indexes #沒有索引的記錄，則會記錄
設定完成my.cnf後，請記得要重新啟動MySQL
其中，log-slow-queries記錄檔的儲存路徑，這個目錄一定要是mysql使用者可以寫入權限的位置，因為slow-query.log記錄檔是由mysql使用者去執行寫入；否則，會造成記錄檔案無法產生的情況，這個問題是最常發生，請切記!


本文相關的文章MySQL最佳化分析指令EXPLAIN
mysql proxy讀寫分流(一)-mysql proxy的安裝方式
mysql(my.cnf)設定檔說明(二)



本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysql%e6%9c%80%e4%bd%b3%e5%8c%96%e5%88%86%e6%9e%90%e6%8c%87%e4%bb%a4explain/' rel='bookmark' title='Permanent Link: MySQL最佳化分析指令EXPLAIN'>MySQL最佳化分析指令EXPLAIN</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(一)-mysql proxy的安裝方式'>mysql proxy讀寫分流(一)-mysql proxy的安裝方式</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/' rel='bookmark' title='Permanent Link: mysql(my.cnf)設定檔說明(二)'>mysql(my.cnf)設定檔說明(二)</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql%e7%9a%84%e6%9f%a5%e8%a9%a2%e6%99%82%e9%96%93log-slow-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mysql-telnet ip 3306沒有回應</title>
		<link>http://homeserver.com.tw/mysql/mysql-telnet-ip-3306%e6%b2%92%e6%9c%89%e5%9b%9e%e6%87%89/</link>
		<comments>http://homeserver.com.tw/mysql/mysql-telnet-ip-3306%e6%b2%92%e6%9c%89%e5%9b%9e%e6%87%89/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 09:05:04 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=660</guid>
		<description><![CDATA[mysql安裝完成後，預設是只有telnet localhost 3306會有回應；但是，如果telnet 本機 ip 3306是不會有回應的。
此時就必須要藉由phpMyAdmin將 本機ip 加到mysql資料庫的user資料表中，詳細如下：
1.選擇【權限】→【新增使用者】

2. 在新增使用者時
使用者名稱：指的是要允許那些使用者可以連到mysql
主機：這裡記得要輸入本機的IP(內部或外部IP)，此例子代表 telnet 192.168.1.253 3306  這樣才會有回應

另外，如果要限制某一個IP才能連到mysql，那要如何做呢？
mysql 限制連線IP
修改/etc/my.conf(請依自行環境尋找適當路徑),在 [mysqld] 區域中新增設定，如下：
[mysqld]
bind-address=192.168.1.253
但是，以丫忠的測試結果，當bind-address設定為192.168.1.253時，telnet localhost 3306就會鎖起來，也就是不能連線。反之當bind-address設定為localhost(127.0.0.1)時，telnet 192.168.1.253也是不能連線。
所以，當你設定bind-address後，mysql只能對外開放一個IP,包含localhost也是在限制的範圍內




本文相關的文章mysql(my.cnf)設定檔說明(二)
mysql proxy讀寫分流(一)-mysql proxy的安裝方式
mysql(my.cnf)設定檔說明



本文相關的文章<ol><li><a href='http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e%e4%ba%8c/' rel='bookmark' title='Permanent Link: mysql(my.cnf)設定檔說明(二)'>mysql(my.cnf)設定檔說明(二)</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysql-proxy%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81%e4%b8%80-mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f/' rel='bookmark' title='Permanent Link: mysql proxy讀寫分流(一)-mysql proxy的安裝方式'>mysql proxy讀寫分流(一)-mysql proxy的安裝方式</a></li>
<li><a href='http://homeserver.com.tw/mysql/mysqlmy-cnf%e8%a8%ad%e5%ae%9a%e6%aa%94%e8%aa%aa%e6%98%8e/' rel='bookmark' title='Permanent Link: mysql(my.cnf)設定檔說明'>mysql(my.cnf)設定檔說明</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/mysql/mysql-telnet-ip-3306%e6%b2%92%e6%9c%89%e5%9b%9e%e6%87%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
