-
Archives
- July 2010
- June 2010
- May 2010
- April 2010
- January 2010
- December 2009
- November 2009
- October 2009
- August 2009
- June 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
-
Meta
Category Archives: MySQL
Zend Framework DB Load Balancing (Master/Slave Database)
網路上找來找去……
沒看到有人寫相關的解法….
加上不想用mysql-proxy來解這部份…
所以打算從code 的部份下手
看到最後只能動Zend Framework 的code 了(還沒想到可以不動ZF 的code 而做到DB LB的方法)
我是先從function save 下手去找..
Zend/Table/Row/Abstract.php: public function save()
public function save()
{
/**
* If the _cleanData array is empty,
* this is an INSERT [...]
Performance Tuning Best Practices for MySQL
這是Jay Pipes 在Google 演講時有關MySQL Tuning 的Tips
Direct URL: http://video.google.com/videoplay?docid=2524524540025172110
[02:20] Don’t benchmark without a goal. Have a goal like “improve performance by 20%”. Otherwise you’ll waste a lot of time tuning milliseconds out of your application.
[02:50] Change just one thing at a time and re-run the benchmarks.
[03:40] Disable the query cache by setting the cache size to [...]
Tuning MySQL ..
因為被slow query 搞的很煩….網站速度一直起不來
因為Database 設計上的問題…..(幾個比較常用的Table 大蓋都差不多有70萬個Record )
且因為我Table Engine 是 MyISAM
用Rep 的話….若是crash 要修…好像很麻煩…
所以變成要用Rep 的話最好能先轉成InnoDB
不過因為我Slow Query 很多…若是我Rep Master Lock 的話
Slave 也會卡住…..
也不是完全的解決了Slow Query這問題….
所以我想最完美的解法可能是
Rep + Aging…
不過要花不少時間來整個改……
當前沒這麼多時間讓我來用這些…
所以我目前的解法是…
加Ram 然後把MySQL 的Ram 讓他吃愈多愈好…
Ref
MYSQL優化詳細介紹!
7.5.2. Tuning Server Parameters
Section 5.1.3, “System Variables”
5.1.2. Command Options
Section 5.1.5, “Status Variables”.
5.2.4. The Slow Query Log
結論就是RAM 有多少吃多少…
讓MySQL可以用的Ram 愈多愈好就沒錯了…
PS
FreeBSD 因為單一Process 預設只能吃到512MB 的Ram
所以在/boot/loader.conf 也要調一下
FreeBSD limits the size of a process to 512MB, even if [...]
super-smack(MySQL Benchmark tool)
剛剛在Joehorn 的個人版上看到的….
我整個很lag…
ports 裡面已經有了……
裝好後..
cp /usr/local/share/super-smack/* ~
才會有
select-key.smack和update-select.smack 這兩個檔案….
執行的話..就在console 下
#super-smack -d mysql select-key.smack 80 100
我的blog 機是FreeBSD 7.0 R
CPU: Intel(R) Xeon(TM) CPU 2.60GHz (2591.61-MHz 686-class CPU),
RAM:2G
HD: 10K SCSI 36.4G
FS: UFS2
數據是
Query_type num_queries max_time min_time q_per_s
select_index [...]
MySQL Active Report
一如往常..在看訂閱的rss 的時後..
其中這篇
有介紹幾個mysql 的工具..
其中mytop 已經快樂使用中…
另一個就是
MySQL Active Report
看起來挺不錯的..
一樣在ports 裡面也有..
#cd /usr/ports/databases/mysqlard/
#make install clean
裝好後的提示似乎不是很完整
1) Add the ‘mysqlar’ user with USAGE privileges to your mysql server:
$ mysql -u root -p mysql
mysql> GRANT USAGE ON *.* TO mysqlar@localhost;
mysql> FLUSH PRIVILEGES;
2) Add the mysqlard crontab to root’s crontab:
*/5 * * * * /usr/bin/env hourly=1 daily=1 weekly=1 monthly=1 \
/usr/local/bin/mysqlar_graph > /dev/null
3) Add a [...]
找出Table 中 資料相同的Record
因為有遇到這個問題
所以特別寫出來備忘
SELECT *
FROM bb_downloads a
WHERE
(SELECT count( * )
FROM bb_downloads b
WHERE b.post_id = a.post_id
AND b.url = a.url
) >1
ORDER BY `post_id`,`download_times` DESC
reference
UPDATE: 2007/10/14
找出不相同的資料
非常的easy
select r.user_id from rtable r WHERE r.user_id not in (select a.user_id from atable a)
刪除不相同的資料
delete from rtable WHERE user_id not in (select a.user_id from atable a)
MySQL 4.1.x 編碼問題(UTF8)
剛剛寫code發現在phpMyAdmin裡面的中文看起來非常正常 不過程式print 卻都是亂碼,很怪!! 後來google 了一下,發現是
有 SUPER 權限的 user 在連線的時候不會去執行 init_connect
所以說即使我的 init_connect=’SET NAMES utf8′ 還是沒用
因為我db是用root連的……….
所以才會是亂碼~~ :*-):
直接去開了一個新帳號來用就好了。
ref.
MySQL 4.1.x SET NAMES UTF8
MySQL backup and restore
因為翰x要移機,所以要把db 上的資料轉出來,不過因為用mysql db < db.sql
常常會出他媽的鬼問題,很杜爛!!!
所以單純把資料dump 成 text file 會是一個比較好的方式,然後再透過mysqlimport
或是LOAD DATA INFILE。
我寫了兩個小小的scripts
就是dump和 restore
有須要的人請自行服用 ::-p:
1.import_db.sh
db_dir=$1
db=$2
for file in `find $1 -type f -depth 1 | egrep txt`
do
table=`echo $file |cut -d “/” -f 5|cut -d “.” -f 1`
echo ‘import data to ‘$table’ finished ‘
/usr/local/bin/mysql -u root -p -e “load data infile ‘$file’ into table $table” $db
done
2.dump_db.sh
date=`date +%Y%m%d`
db=$1
dump_dir=$2
charset=$3
#Dump DB structure
/usr/local/bin/mysqldump [...]
MySQL replication
昨天和貓哥談到了關於備份移機的事,
有談到關於mysql replication
so 找了一下有關於
mysql replication 的資料
簡單來說mysql replication
就是主要架設一台Mysql Master
和一些slave。
而slave 會主動和master 要資料,
且可以提供query ,來分散一些master 的load
當master 有更新時,slave 就會和master 要資料更新。
so 也就達到備份的效果
而mysql replication 有不少作法
如one-way, multi-way , circle
One Way replicaton
例如A跟B
B不write, 只有A write, 然後A是master
這叫做one-way
Multi Way replication
如果A, B都能write, 互相以對方為master
就是multi-way
Circle
而Circle 又分
circle, double circle, semi-double circle
一般circle
A(master) < ===> (slave)B(master) < ===> (slave)C(master) < ===> A
double circle
是兩個circle, 然後兩個circle的master node之間做multi-way
semi-double
是一邊做circle, 然後circle 跟外頭的node做multi-way replication
以下是一些資料
http://dev.mysql.com/doc/refman/5.0/en/replication.html
http://blog.johnpupu.tw/wp-content/uploads/2007/01/sop-mysql.pdf
Posted in MySQL
Leave a comment