站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > MySQL 5.1参考手册中文版

Appendix聽E.聽Porting to Other Systems - MySQL 5.1参考手册中文版

闄勫綍E锛氱Щ妞嶅埌鍏跺畠绯荤粺

杩欎釜闄勫綍甯姪浣犳妸MySQL绉绘鍒板叾瀹冩搷浣滅郴缁熴傝鍏堟煡鐪嬩竴涓嬪綋鍓嶆敮鎸佹搷浣滅郴缁熷垪琛ㄣ傝鍙傞槄2.1.1鑺傦紝鈥淢ySQL鏀寔鐨勬搷浣滅郴缁熲銆傚鏋滀綘鍒涘缓浜嗕竴涓柊鐨凪ySQL绉绘锛堢Щ妞嶅埌鍒楄〃涓婃病鏈夌殑鎿嶄綔绯荤粺锛夛紝璇烽氱煡鎴戜滑锛屼互渚挎垜浠兘鎶婅繖涓搷浣滅郴缁熷垪鍒版垜浠綉绔欎笂锛http://www.mysql.com/锛夛紝鎺ㄨ崘缁欏叾瀹冪殑鐢ㄦ埛銆

娉ㄦ剰锛氬鏋滀綘鍒涘缓涓涓柊鐨凪ySQL绉绘锛屼綘鍙互鍦℅PL璁稿彲璇佷笅浠绘剰澶嶅埗鍜屽彂甯冨畠锛屼絾杩欎笉鑳戒娇浣犳垚涓篗ySQL鐨勭増鏉冩寔鏈夎呫

杩欎釜鏈嶅姟鍣ㄩ渶瑕佷竴涓鍦ㄥ伐浣滅殑POSIX 绾跨▼搴撳湪銆傚湪Solaris 2.5 涓婃垜浠娇鐢⊿un PThreads 锛堝湪2.4鐗堝拰鏇存棭鐨勭増鏈笂锛屽師鐢熺嚎绋嬫敮鎸佸緱涓嶆槸寰堝ソ锛夛紝鍦↙inux涓婏紝鎴戜滑浣跨敤Xavier Leroy<Xavier.Leroy@inria.fr>鐨凩inuxThreads銆

瀵逛簬閭d簺瀵瑰師鐢熺嚎绋嬫敮鎸佷笉濂界殑鏂癠nix鍙樹綋锛岀Щ妞嶅埌鍏朵笂鐨勮壈闅鹃儴鍒嗗ぇ姒傚氨鏄Щ妞峂IT-pthreads鍖呫傝鍙傞槄mit-pthreads/README 鍜孭rogramming POSIX Threads (http://www.humanfactor.com/pthreads/)銆

鐩村埌MySQL 4.0.2鐗堬紝MySQL鍙戝竷鍖呭寘鎷潵鑷狹IT缁忚繃琛ヤ竵鐨凜hris Provenzano鐨凱threads锛堣鍙傞槄MIT Pthreads 缃戦〉http://www.mit.edu/afs/sipb/project/pthreads/ 浠ュ強http://www.mit.edu:8001/people/proven/IAP_2000/涓婄殑缂栫▼鎸囧锛夈傚浜庢煇浜涙病鏈塒OSIX绾跨▼鐨勬搷浣滅郴缁熷彲鑳芥湁鐢ㄣ傝鍙傞槄2.8.5鑺傦紝鈥淢IT-pthreads 娉ㄦ剰浜嬮」鈥

涔熷彲鑳戒細鐢ㄥ埌鍙︿竴涓悕涓 FSU Pthreads鐨勭敤鎴风骇绾跨▼杞欢鍖咃紙璇峰弬闃http://moss.csc.ncsu.edu/~mueller/pthreads/锛夈 杩欎釜宸ュ叿琚敤鏉ュ埌SCO鐨勭Щ妞嶃

鍙傞槄 mysys鐩綍涓嬬殑thr_lock.c 鍜宼hr_alarm.c 绋嬪簭鑾峰彇涓浜涘叧浜庤繖浜涢棶棰樼殑娴嬭瘯/渚嬪瓙銆

鏈嶅姟鍣ㄥ拰瀹㈡埛绔渶瑕佷竴涓兘鐢ㄧ殑C++缂栬瘧鍣ㄣ傛垜浠湪寰堝骞冲彴涓婁娇鐢gcc銆傚叾瀹冪紪璇戝櫒锛屾嵁浜嗚В锛屽彲鐢ㄧ殑缂栬瘧鍣ㄦ槸SPARCworks, Sun Forte, Irix cc, HP-UX aCC, IBM AIX xlC_r), Intel ecc/icc 鍜 Compaq cxx)銆

瑕佷粎缂栬瘧瀹㈡埛绔紝璇蜂娇鐢./configure --without-server.

鐜板湪涓嶆敮鎸佷粎缂栬瘧鏈嶅姟鍣紝涔熶笉鑳藉姞杩欎釜鍔熻兘锛岄櫎闈炴湁浜烘壘鍑轰竴涓ソ鐨勭悊鐢便

濡傛灉浣犳兂/闇瑕佹敼鍙樹换浣昅akefile 鎴栭厤缃剼鏈紝浣犱篃浼氶渶瑕佸埌GNU Automake 鍜 Autoconf銆傝鍙傞槄2.8.3鑺 锛屸滀粠寮鍙戞簮鏍戝畨瑁呪

鎵鏈夋楠ら渶瑕佷粠鏈鍩烘湰鐨勬枃浠堕噸鏂扮敓鎴愶紙remake锛夋墍鏈変笢瑗裤

/bin/rm */.deps/*.P
/bin/rm -f config.cache
aclocal
autoheader
aclocal
automake
autoconf
./configure --with-debug=full --prefix='your installation directory'

# The makefiles generated above need GNU make 3.75 or newer.
# (called gmake below)
gmake clean all install init-db

濡傛灉鍦ㄦ柊绉绘MySQL涓婇亣鍒伴棶棰橈紝鏈濂藉仛涓浜涜皟璇曪紒璇峰弬闃E.1鑺傦紝鈥滆皟璇昅ySQL鏈嶅姟鍣ㄢ

娉ㄦ剰锛氬湪浣犲紑濮嬭皟璇mysqld涔嬪墠锛岄鍏堣璁╂祴璇曠▼搴mysys/thr_alarmmysys/thr_lock宸ヤ綔銆傝繖浼氱‘淇濅綘鐨勭嚎绋嬪畨瑁呭彧鏈夐潪甯稿皬鐨勬満浼氳兘杩愯锛

E.1.聽璋冭瘯MySQL鏈嶅姟鍣

濡傛灉浣犱娇鐢∕ySQL鏌愪簺闈炲父鏂扮殑鍔熻兘锛屼綘鍙互甯--skip-new鍙傛暟锛堣繖涓夐」绂佹鎺夋墍鏈夋柊鐨勬綔鍦ㄤ笉瀹夊叏鐨勫姛鑳斤級鎴栧甫 --safe-mode鍙傛暟锛堝畠绂佹鎺夊緢澶氬彲鑳藉鑷撮棶棰樼殑浼樺寲璁剧疆锛夋潵杩愯mysqld 璇峰弬闃A.4.2鑺傦紝鈥滃鏋淢ySQL渚濇棫宕╂簝锛屽簲璇ュ仛浠涔堚

濡傛灉 mysqld 涓嶅惎鍔紝浣犲簲璇ユ煡璇佹湁娌℃湁骞叉壈浣犵殑璁剧疆鐨刴y.cnf鏂囦欢銆備綘鍙互鐢mysqld --print-defaults...妫鏌y.cnf鍙傞噺锛屽苟鐢mysqld --no-defaults鏉ュ惎鍔ㄥ幓閬垮厤瀹冧滑銆

濡傛灉mysqld 鍚姩鑰楀敖CPU鎴栧唴瀛樿祫婧愶紝鎴栬呭畠鈥滄寕鈥濅簡璧锋潵锛屼綘鍙互浣跨敤 mysqladmin processlist status鍘绘壘鍑烘槸鍚︽湁浜烘墽琛屼簡涓涓崰鐢ㄥ緢闀挎椂闂寸殑鏌ヨ銆傚鏋滀綘姝i潰涓寸潃鎬ц兘闂鎴栨柊瀹㈡埛绔笉鑳借繛 涔嬫椂鐨勯棶棰橈紝鍦ㄦ煇浜涚獥鍙d腑杩愯mysqladmin -i10 processlist status鍙兘鏄涓涓ソ涓绘剰銆

mysqladmin debug 鍛戒护鎶婁竴浜涙湁鍏充娇鐢ㄤ腑鐨勯攣锛屼娇鐢ㄧ殑鍐呭瓨浠ュ強鏌ヨ浣跨敤鐨勪俊鎭浆鍌ㄥ埌MySQL鏃ュ織鏂囦欢閲屻傝繖灏嗘湁鍔╀簬瑙e喅涓浜涢棶棰樸傚嵆浣夸綘娌℃湁涓鸿皟璇曠紪璇慚ySQL锛岃繖涓懡浠や篃鎻愪緵涓浜涙湁鐢ㄧ殑淇℃伅锛

濡傛灉闂鏄竴浜涜〃鍙樺緱瓒婃潵瓒婃參锛屼綘搴旇璇曠潃鐢≒TIMIZE TABLE鎴myisamchk浼樺寲琛ㄣ侷璇峰弬闃呯5绔狅細鏁版嵁搴撶鐞銆備綘涔熷彲浠ョ敤EXPLAIN妫鏌ユ參 鐨勬煡璇€ 

瀵归偅浜涗簬浣犵殑鐜鏄嫭鐗圭殑闂锛屼綘涔熷簲璇ユ煡闃呰繖涓墜鍐岄噷OS瑙勬牸鐨勯儴鍒嗚鍙傞槄聽2.12鑺傦紝鈥滄搷浣滅郴缁熺郴缁熺殑娉ㄦ剰浜嬮」鈥

E.1.1.聽閽堝璋冭瘯缂栬瘧MySQL

濡傛灉浣犻亣鍒颁竴浜涢潪甯告槑纭殑闂锛屼綘鍙互鎬绘槸璇曠潃璋冭瘯MySQL銆傝璋冭瘯MySQL锛屼綘蹇呴』鐢--with-debug鎴--with-debug=full閫夐」鏉ラ厤缃甅ySQL銆備綘鍙互妫鏌ySQL鏄惁鏄氳繃mysqld --help鏉ュ拰璋冭瘯涓璧风紪璇戠殑銆傚鏋--debug鏍囪鍜岄夐」涓璧疯鍒楀嚭浜嗭紝浣犲氨鍙互璋冭瘯浜嗐傚湪杩欑鎯呭喌mysqladmin ver涓嬫妸mysqld鐗堟湰鍒楁垚mysql ... --debug

濡傛灉浣犱娇鐢gccegcs锛屾帹鑽愮殑configure 琛屽涓嬶細

CC=gcc CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors \
   -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
   --with-debug --with-extra-charsets=complex

杩欓伩鍏嶄簡libstdc++搴撳拰C++寮傚父锛堝緢澶氱紪璇戝櫒鍦ㄧ嚎绋嬩唬鐮侀噷鏈塁++寮傚父鐨勯棶棰橈級鐨勯棶棰橈紝骞剁紪璇戜簡涓涓敮鎸佹墍鏈夊瓧绗﹂泦鐨凪ySQL鐗堟湰銆

濡傛灉浣犳鐤戝唴瀛樻孩鍑洪敊璇紝浣犲彲浠ョ敤--with-debug=full鏉ラ厤缃甅ySQL锛岃繖浼氬畨瑁呬竴涓唴瀛樺垎閰嶏紙SAFEMALLOC锛夋鏌ュ櫒銆傚彲鏄紝杩愯SAFEMALLOC鏄潪甯告參鐨勶紝鎵浠ュ鏋滀綘閬囧埌鎬ц兘涓婄殑闂锛屼綘搴旇 鐢--skip-safemalloc閫夐」鍚姩mysqld銆傝繖鏍风姝㈡帀瀵硅皟鐢╩alloc()鍜宖ree()鐨勫唴瀛樻鏌ャ

褰撲綘鐢--with-debug缂栬瘧mysqld鏃讹紝濡傛灉瀹冧笉鍐嶅穿婧冿紝浣犲ぇ鑷村凡缁忓湪MySQL鍐呮壘鍒颁竴涓紪璇戝櫒缂洪櫡鎴栬鏃剁己闄枫傝繖绉嶆儏鍐典笅锛屼綘鍙互璇曠潃鎶-g鍔犲埌涓婇潰鐨CFLAGSCXXFLAGS鍙橀噺锛屽苟涓斾笉浣跨敤--with-debug銆傚鏋mysqld澶辫触锛屼綘鑷冲皯鍙互gdb鐢ㄩ檮鐫涓婂畠鎴栦娇鐢ㄦ牳蹇冩枃浠朵笂鐨gdb鍘绘壘鍑哄彂鐢熶粈涔堥棶棰樸

褰撲綘涓鸿皟璇曢厤缃甅ySQL鏃讹紝浣犲氨鑷姩鍏佽璁稿棰濆鐨勭洃瑙mysqld鍋ュ悍鐨勫畨鍏ㄦ鏌ュ嚱鏁般傚鏋滃畠浠彂鐜颁竴浜涒滀笉鏈熸湜鈥濈殑浜嬶紝浼氬啓涓涓潯鐩埌stderr锛safe_mysqld鎸囧紩杩欎釜stderr鍒伴敊璇棩蹇楋紒杩欎篃鎰忓懗鐫濡傛灉MySQL鍙戠敓浠涔堟剰澶栫殑闂锛屽苟涓斾綘姝d娇鐢ㄤ竴涓簮鏂囦欢鍙戝竷鐗堟湰锛岄偅涔堜綘瑕佸仛鐨勭涓浠朵簨灏辨槸鍘讳负璋冭瘯閰嶇疆MySQL锛侊紙绗簩浠朵簨鏄彂閭欢鍒癕ySQL閭欢鍒楄〃璇锋眰甯姪锛夈傝鍙傞槄1.7.1.1鑺傦紝鈥淢ySQL閭欢鍒楄〃鈥銆傝鏍规嵁浣犱娇鐢ㄧ殑MySQL鐗堟湰瀵规墍鏈夌己闄锋姤鍛婃垨闂浣跨敤mysqlbug鑴氭湰锛

鍦╓indows MySQL鍙戝竷鍖呴噷锛宮ysqld.exe榛樿缂栬瘧涓烘敮鎸佽拷韪枃浠躲

E.1.2.聽鍒涘缓璺熻釜鏂囦欢

濡傛灉mysqld 鏈嶅姟鍣ㄦ病鏈夊惎鍔ㄦ垨鑰呬綘鍙互蹇熷湴浣垮叾宕╂簝锛屼綘鍙互鍒涘缓涓涓窡韪枃浠舵潵鎵惧嚭闂銆

瑕佽繖涔堝仛鐨勮瘽锛屼綘蹇呴』鏈変竴涓紪璇戜簡鏀寔璋冭瘯鐨mysqld 浣犲彲浠ラ氳繃鎵цmysqld -V鏉ユ鏌ヤ竴涓嬨傚鏋滅増鏈彿鍚庨潰璺熺潃-debug锛屽畠灏辨槸琚紪璇戞垚鏀寔璺熻釜鏂囦欢銆傦紙鍦 Windows涓紝璋冭瘯鏈嶅姟鍣ㄨ鍛藉悕涓mysqld-debug 鑰屼笉鏄薄MySQL 4.1 閭f牱鐨mysqld 锛夈

濡備笅鍛戒护锛屽惎鍔ㄥ甫璺熻釜鏂囦欢鐨 mysqld 鏈嶅姟鍣紝璺熻釜鏂囦欢浣嶄簬Unix涓婄殑/tmp/mysqld.trace鐩綍閲岋紝Windows涓 鐨凜:\mysqld.trace鐩綍閲岋細

shell> mysqld --debug

鍦╓indows涓婏紝浣犱篃鍙互浣跨敤--standalone鍙傛暟锛屽惎鍔mysqld璁╁畠涓浣滀负鏈嶅姟銆傚湪鎺у埗鍙扮獥鍙o紝浣跨敤杩欎釜鍛戒护锛

C:\> mysqld-debug --debug --standalone

瀹屾瘯涔嬪悗锛屼綘鍙互浣跨敤绗簩涓獥鍙d腑鐨 mysql.exe 鍛戒护琛屽伐鍏烽噸鏂板埗閫犻棶棰樸備綘鍙互鐢mysqladmin shutdown鍛戒护鍋滄mysqld鏈嶅姟鍣ㄣ

娉ㄦ剰锛岃窡韪枃浠朵細鍙樺緱寰堝ぇ锛佸鏋滀綘鎯崇敓鎴愪竴涓皬涓鐐圭殑璺熻釜鏂囦欢锛屼綘鍙互浣跨敤绫讳技杩欐牱鐨勮皟鍒堕夐」锛

mysqld --debug=d,info,error,query,general,where:O,/tmp/mysqld.trace

杩欐牱灏变粎鎶婂甫鏈鎰熷叴瓒f爣璁扮殑淇℃伅鍐欒繘璺熻釜鏂囦欢閲.

濡傛灉浣犵敓鎴愪竴涓湁鍏充簬姝ょ殑缂洪櫡鎶ュ憡锛岃鍙敤鎶婅窡韪枃浠朵腑鐨勭浉鍏宠鍙戦佸埌鎭板綋鐨勯偖浠跺垪琛ㄥ幓锛岄偅閲屽叧娉ㄤ綘鎶ュ憡鍑洪棶棰樼殑閮ㄥ垎銆傚鏋滀綘涓嶈兘鎵惧嚭鍝噷鍑洪棶棰橈紝浣犲彲浠tp涓婅浇鏁翠釜璺熻釜鏂囦欢鍒ftp://ftp.mysql.com/pub/mysql/upload/锛屽苟闄勬湁瀹屽叏鐨勭己闄锋姤鍛婏紝MySQL寮鍙戜汉鍛樹細鐪嬪埌瀹冪殑銆

杩借釜鏂囦欢鏄敱Fred Fish鐢DBUG杞欢鍖呯敓鎴愮殑锛岃鍙傞槄E.3鑺傦紝鈥淒BUG杞欢鍖呪

E.1.3.聽鍦gdb鐜涓嬭皟璇mysqld

濡傛灉mysqld宕╂簝浜嗭紝鍦ㄥぇ澶氭暟绯荤粺涓婏紝浣犱篃鍙槸浠gdb鍚姩mysqld鏉ヨ幏鍙栨洿澶氫俊鎭

Linux涓婏紝鏈変竴浜涜佺増鏈殑gdb锛屽鏋滀綘鎯宠鑳借皟璇mysqld绾跨▼锛屼綘蹇呴』浣跨敤run --one-threadsome銆傚湪杩欑鎯呭喌涓嬶紝浣犲彲浠ヤ竴娆″彧婵娲讳竴涓嚎绋嬨傛垜浠帹鑽愪綘鍗囩骇鍒癵db 5.1 ASAP 锛岃繖涓増鏈笂绾跨▼璋冭瘯宸ヤ綔寰楁洿濂斤紒

NTPL 绾跨▼锛圠inux涓婄殑鏂扮嚎绋嬪簱锛夊彲鑳戒細鍦gdb涓嬭繍琛mysqld鏃堕亣鍒伴棶棰樸備竴浜涚棁鐘跺涓嬶細

  • mysqld 鍦ㄥ惎鍔ㄨ繃绋嬩腑鎸傝捣锛堝湪瀹冨啓ready for connections涔嬪墠锛夈

  • mysqld 鍦ㄨ皟鐢╬thread_mutex_lock()鎴杙thread_mutex_unlock()杩囩▼涓穿婧冦

鍦ㄨ繖绉嶆儏鍐典笅浣犲簲璇ュ湪鍚姩gdb涔嬪墠鍦ㄥ澹充笂璁剧疆濡備笅鐜鍙橀噺锛

LD_ASSUME_KERNEL=2.4.1
export LD_ASSUME_KERNEL

gdb涓嬭繍琛mysqld鏃讹紝浣犲簲璇ョ敤--skip-stack-trace鏉ョ姝㈠爢鏍堣窡韪紝浠ヤ究鑳芥崟鑾gdb鍐呯殑娈甸敊璇

鍦∕ySQL 4.0.14鍜屼互涓婄増鏈紝浣犲簲璇ュmysqld浣跨敤--gdb閫夐」銆 杩欎細涓篠IGINT瀹夎涓涓腑鏂鐞嗗櫒锛堥渶瑕佺敤^C鍋滄mysqld鏉ヨ缃柇鐐癸級锛屽苟涓旂姝㈠爢鏍堣窡韪拰鏍稿績鏂囦欢澶勭悊銆

gdb娌℃湁缁欐棫绾跨▼閲婃斁鍐呭瓨鐨勬暣涓椂闂撮噷锛屽鏋滀綘鍋氫簡澶ч噺鐨勬柊杩炴帴锛屽湪gdb涓嬭皟璇昅ySQL鏄潪甯稿洶闅剧殑銆備綘鍙互閫氳繃甯 -O thread_cache_size= 'max_connections +1' 鍚姩mysqld 鏉ラ伩鍏嶈繖涓棶棰樸傚湪澶氭暟鎯呭喌涓嬶紝鍙娇鐢-O thread_cache_size=5'灏卞彈鐩婃棤绌蜂簡锛

濡傛灉mysqld甯︾潃SIGSEGV淇″彿姝绘帀浜嗭紝鑰屼綘鎯冲湪Linux涓婅浆鍌ㄦ牳蹇冿紝浣犲彲浠ュ甫--core-file閫夐」鍚姩mysqld銆傝繖涓牳蹇冩枃浠跺彲浠ヨ鐢ㄦ潵鐢熸垚 鍚戝悗璺熻釜锛屽畠鍙互甯綘鎵惧嚭mysqld 涓轰綍姝绘帀锛

shell> gdb mysqld core
gdb>   backtrace full
gdb>   exit

璇峰弬闃A.4.2鑺傦紝鈥滃鏋淢ySQL渚濇棫宕╂簝锛岃濡備綍鍘诲仛鈥

濡傛灉浣犲湪Linux涓婁娇鐢gdb 4.17.x 鎴栦互涓婄増鏈紝浣犲簲璇ュ畨瑁呬竴涓甫鏈夊涓嬩俊鎭殑 .gdb 鏂囦欢鍒颁綘褰撳墠鐩綍锛

set print sevenbit off
handle SIGUSR1 nostop noprint
handle SIGUSR2 nostop noprint
handle SIGWAITING nostop noprint
handle SIGLWP nostop noprint
handle SIGPIPE nostop
handle SIGALRM nostop
handle SIGHUP nostop
handle SIGTERM nostop noprint

濡傛灉浣犵敤gdb璋冭瘯绾跨▼閬囧埌闂锛屼綘搴旇涓嬭浇gdb 5.x鐗堟湰骞剁敤瀹冭瘯涓涓嬭皟璇曘傛柊鐗堟湰鐨 gdb 澶уぇ鏀瑰杽浜嗙嚎绋嬪鐞嗭紒

涓嬮潰鏄浣曡皟璇昺ysqld鐨勪緥瀛愶細

shell> gdb /usr/local/libexec/mysqld
gdb> run
...
backtrace full # Do this when mysqld crashes

鎶婁笂闈㈢殑杈撳叆鍐欒繘涓涓敤mysqlbug鐢熸垚鐨勯偖浠堕噷锛屽彂閫佸埌缁煎悎MySQL閭欢鍒楄〃銆傝鍙傞槄1.7.1.1鑺傦紝鈥淢ySQL 閭欢鍒楄〃鈥

濡傛灉mysqld 鎸傝捣锛屼綘鍙互璇曠潃鐢ㄤ竴浜涜濡俿trace 鎴 /usr/proc/bin/pstack 杩欐牱鐨勭郴缁熷伐鍏疯繛妫鏌mysqld 鍦ㄥ摢閲屾寕璧枫

strace /tmp/log libexec/mysqld

濡傛灉浣犱娇鐢 Perl DBI 鎺ュ彛锛屼綘鍙互浣跨敤trace鏂规硶鎴栬缃瓺BI_TRACE鐜鍙橀噺鏉ユ墦寮璋冭瘯淇℃伅銆

E.1.4.聽浣跨敤鍫嗘爤璺熻釜

鍦ㄤ竴浜涙搷浣滅郴缁熶笂锛屽鏋mysqld鎰忓姝绘帀锛岄敊璇棩蹇楀寘鍚竴涓爢鏍堣窡韪備綘鍙互鐢ㄥ畠鏉ユ壘鍑mysqld 鍦ㄥ摢閲岋紙涔熻鍙兘鎵惧嚭涓轰粈涔堬級姝绘帀銆傝鍙傞槄5.11.1鑺傦紝鈥滈敊璇棩蹇椻銆傝鑾峰緱鍫嗘爤璺熻釜锛屼綘涓嶈兘鐢-fomit-frame-pointer 閫夐」缂栬瘧mysqld 涓篻cc銆 璇峰弬闃E.1.1鑺傦紝鈥滈拡瀵硅皟璇曠紪璇慚ySQL鈥

濡傛灉閿欒鏂囦欢鍖呭惈绫讳技涓嬮潰鐨勪竴浜涘唴瀹癸細

mysqld got signal 11;
The manual section 'Debugging a MySQL server' tells you how to use a
stack trace and/or the core file to produce a readable backtrace that may
help in finding out why mysqld died
Attempting backtrace. You can use the following information to find out
where mysqld died.  If you see no messages after this, something went
terribly wrong...
stack range sanity check, ok, backtrace follows
0x40077552
0x81281a0
0x8128f47
0x8127be0
0x8127995
0x8104947
0x80ff28f
0x810131b
0x80ee4bc
0x80c3c91
0x80c6b43
0x80c1fd9
0x80c1686

浣犲彲浠ヤ娇鐢ㄥ涓嬫楠ゆ壘鍑mysqld鍦ㄤ粈涔堝湴鏂瑰嚭鐜伴棶棰橈細

  1. 澶嶅埗鍓嶉潰鐨勬暟瀛楀埌涓涓枃浠讹紝濡俶ysqld.stack銆

  2. mysqld 鏈嶅姟鍣ㄧ敓鎴愮鍙锋枃浠讹細

    nm -n libexec/mysqld > /tmp/mysqld.sym
    

    娉ㄦ剰锛屽鏁癕ySQL浜岃繘鍒跺彂甯冨寘锛"debug" 杞欢鍖咃紝鍖呭惈杩欎簺淇℃伅鐨勫湴鏂瑰氨鍦ㄤ簩杩涘埗鍙戝竷鍖呮湰韬箣鍐咃級甯︿笂杩版枃浠讹紝鍦ㄥ叾涓繖浜涙枃浠跺悕涓簃ysqld.sym.gz銆傚湪杩欑鎯呭喌涓嬶紝浣犲彲浠ョ畝鍗曞湴瑙e帇缂╁畠锛

    gunzip < bin/mysqld.sym.gz > /tmp/mysqld.sym
    
  3. 鎵ц resolve_stack_dump -s /tmp/mysqld.sym -n mysqld.stack.

    杩欎釜鍛戒护浼氭墦鍗板嚭mysqld姝诲湪鍝噷銆傚鏋滆繖涓笉鑳藉府浣犳壘鍑mysqld涓轰粈涔堟鎺夛紝浣犲簲璇ョ敓鎴愪竴涓己闄锋姤鍛婏紝骞跺湪缂洪櫡鎶ュ憡閲屽寘鍚笂杩板懡浠ょ殑杈撳嚭缁撴灉銆

    娉ㄦ剰锛屽敖绠″湪澶氭暟鎯呭喌涓嬶紝浠呮湁涓涓爢鏍堣窡韪笉鑳藉府鍔╂垜浠壘鍑洪棶棰樼殑鍘熷洜銆備负浜嗗畾浣嶇己闄锋垨鎵惧埌涓涓ぇ鑷磋寖鍥达紝鎴戜滑鍦ㄥぇ澶氭暟鎯呭喌涓嬮渶瑕佺煡閬撴潃鎺mysqld鐨勬煡璇紝骞舵渶濂界煡閬撲竴涓祴璇曟渚 锛屼互渚挎垜浠兘閲嶅闂锛佽鍙傞槄1.7.1.3鑺傦紝鈥滃浣曟姤鍛婄己闄峰拰闂鈥

E.1.5.聽浣跨敤鏃ュ織鏂囦欢鎵惧嚭mysqld涓鐨勯敊璇師鍥

娉ㄦ剰锛屽湪甯--log閫夐」鍚姩 mysqld涔嬪墠锛屼綘搴旇鐢myisamchk妫鏌ユ墍鏈夌殑琛ㄣ傝鍙傞槄绗5绔狅細鏁版嵁搴撶鐞.

濡傛灉 mysqld 姝讳簡鎴栨寕璧凤紝浣犲簲璇ョ敤--log鍚姩 mysqld 銆傚綋mysqld 鍐嶆姝绘帀鏃讹紝浣犲彲浠ユ鏌ユ棩蹇楁枃浠剁殑鏈鍚庯紝鎵惧嚭鏉鎺mysqld鐨勬煡璇€

濡傛灉浣犱笉甯︽枃浠跺悕浣跨敤 --log 锛屾棩蹇楄淇濆瓨鍦鍚嶄负host_name.log鐨勬暟鎹簱鐩綍閲屻傚湪澶氭暟鎯呭喌涓嬶紝鏃ュ織鏂囦欢涓殑鏈鍚庝竴涓煡璇㈡潃鎺mysqld锛屼絾濡傛灉鏈夊彲鑳斤紝浣犲簲璇ラ噸鍚mysqld骞朵粠mysq鍛戒护琛屽伐鍏锋墽琛屾壘鍒扮殑鏌ヨ鏉ラ獙璇佷竴涓嬨傚鏋滆繖涓煡璇㈡潃鎺浜唌ysqld锛屼綘涔熷簲璇ユ祴璇曟墍鏈夋病鏈夊畬鎴愮殑澶嶆潅鏌ヨ

浣犱篃鍙互鍦ㄦ墍鏈夊崰鐢ㄩ暱鏃堕棿鐨凷ELECT澹版槑涓婄敤鍛戒护EXPLAIN鏉ョ‘璁 mysqld姝i傚綋鍦颁娇鐢ㄧ储寮曘傝鍙傞槄7.2.1鑺傦紝鈥淓XPLAIN 璇硶锛堣幏寰楀叧浜嶴ELECT鐨勪俊鎭锛夆

浣犲彲浠ュ甫 --log-slow-queries鍚姩mysqld鏉ユ壘鍑哄崰鐢ㄩ暱鏃堕棿鏉ユ墽琛岀殑鏌ヨ銆傝鍙傞槄5.11.4鑺 锛屸滅紦鎱㈡煡璇㈡棩蹇椻

濡傛灉浣犲湪閿欒鏃ュ織鏂囦欢锛堥氬父鍚嶄负hostname.err锛変腑鍙戠幇 mysqld restarted 瀛楁牱锛屼綘澶ц嚧宸茬粡鎵惧埌瀵艰嚧mysqld鐨勬煡璇€傚鏋滃彂鐢熻繖绉嶆儏鍐碉紝浣犲簲璇ョ敤myisamchk妫鏌ユ墍鏈夎〃锛堝弬闃 绗5绔狅細鏁版嵁搴撶鐞锛夛紝骞跺湪MySQL鏃ュ織鏂囦欢涓祴璇曡繖浜涙煡璇㈢湅鏄惁鏈変笉鎵ц鐨勩傚鏋滄壘鍒拌繖鏍蜂竴涓煡璇紝璇曠潃鍗囩骇鍒版渶鏂扮殑MySQL鐗堟湰銆傚鏋滆繖鏍蜂笉鑳藉府鍔╀綘锛屼綘涓嶈兘鍦╩ysql閭欢瀛樻。涓彂鐜颁换浣曠浉鍏冲唴瀹癸紝浣犲簲璇ユ妸缂洪櫡鎶ュ憡缁橫ySQL閭欢鍒楄〃銆傞偖浠跺垪琛ㄥ湪http://lists.mysql.com/璁㈤槄锛岃繖涓湴鍧涓婁篃鏈夎繛鍒板湪绾垮垪琛ㄥ瓨妗g殑閾炬帴銆

濡傛灉浣犲凡缁忕敤myisam-recover鍚姩浜mysqld锛孧ySQL鑷姩妫鏌ュ苟璇曠潃淇MyISAM 琛紝鐪嬫槸鍚﹀畠浠鏍囧織涓衡滄湭姝e父鍏抽棴鈥濇垨鈥滃穿婧冣濄傚鏋滃彂鐢熻繖绉嶆儏鍐碉紝MySQL鍦ㄦ枃浠秇ostname.err 鍐欎竴涓潯鐩'Warning: Checking table ...'锛屽悗闈㈣窡鐫璀﹀憡锛氬鏋滆〃闇瑕佷慨澶嶏紝璇蜂慨澶嶅畠銆傚鏋滀綘閬囦笂澶ч噺鐨勮繖浜涢敊璇mysqld娌℃湁鎰忓姝绘帀锛岄偅灏辨槸鏈夐棶棰樹簡锛岄渶瑕佽繘涓姝ヨ皟鏌ャ傝鍙傞槄5.3.1鑺傦紝鈥mysqld鍛戒护琛岄夐」鈥

濡傛灉mysqld鎰忓姝绘帀锛岃繖鍙笉鏄竴涓ソ鍏嗗ご锛屼絾鍦ㄨ繖绉嶆儏鍐典笅涓嶇敤鐮旂┒Checking table...淇℃伅锛岃屾槸瑕佹壘鍑mysqld涓轰粈涔堟鎺夈

E.1.6.聽濡傛灉鍑虹幇琛ㄥ穿婧冿紝璇风敓鎴愭祴璇曟渚

濡傛灉鍦ㄤ竴浜涙洿鏂板懡浠や箣鍚庯紝mysqld鎬绘槸褰撴帀锛屾垨鑰呭鏋滀綘閬囧埌琚牬鍧忕殑琛紝浣犲彲浠ョ敤涓嬮潰鐨勬搷浣滄祴璇曠湅杩欎釜缂洪櫡鏄惁鏄彲閲嶅浜х敓鐨勶細

  • 鍗告帀MySQL瀹堟姢杩涚▼锛堢敤mysqladmin shutdown锛夈

  • 缁欒琛ㄥ仛澶囦唤锛堥槻姝慨澶嶆搷浣滃弽鑰屾悶鍧忚繖绉嶅緢涓嶅彲鑳藉嚭鐜扮殑鎯呭喌锛夈

  • myisamchk -s database/*.MYI 妫鏌ユ墍鏈夌殑琛紝鐢myisamchk -r database/table.MYI淇悊鏈夐敊璇殑琛ㄣ

  • 瀵硅琛ㄥ仛绗簩娆″浠姐

  • 濡傛灉闇瑕佹洿澶氱殑绌洪棿灏变粠MySQL鏁版嵁搴撶洰褰曞垹闄わ紙鎴栫Щ璧帮級鏃ф棩蹇楁枃浠躲

  • 甯--log-bin鍚姩Start mysqld 銆傝鍙傞槄5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥銆傚鏋滀綘鎯虫壘鍑烘悶mysqld鐨勬煡璇紝浣犲簲璇ヤ娇鐢╱se --log --log-bin銆

  • 褰撲綘宸茬粡閬亣涓涓鐮村潖鐨勮〃鏃讹紝璇峰仠姝ysqld server 銆

  • 杩樺師澶囦唤銆

  • 涓嶅甫--log-bin閲嶅惎鍔mysqld 鏈嶅姟鍣ㄣ 

  • 閲嶆柊鎵цmysqlbinlog update-log-file | mysql鍛戒护銆傛洿鏂扮殑鏃ュ織鐢ㄥ悕瀛梙ostname-bin.#淇濆瓨鍦∕ySQL鏁版嵁搴撶洰褰曚笅銆

  • 濡傛灉璇ヨ〃鍐嶆琚牬鍧忥紝鎴栬呬綘鍙敤涓婅瘔鍛戒护璁mysqld 姝绘帀锛屼綘灏卞凡缁忔壘鍒板彲閲嶅浜х敓鐨勭己闄凤紝瀹冨簲璇ュ緢瀹规槗琚慨澶嶏紒鍙互ftp涓婁紶琛ㄥ拰浜岃繘鍒舵棩蹇楀埌 ftp://ftp.mysql.com/pub/mysql/upload/ 鐒跺悗鎶婂畠杈撳叆鎴戜滑鍦 http://bugs.mysql.com/涓婄殑缂洪櫡绯荤粺銆傦紙璇锋敞鎰忥紝/pub/mysql/upload/ 鍦‵TP鏃舵槸涓嶅彲浠ュ垪鍑猴紙鍐呭锛夌殑锛屾墍浠ヤ笉鑳藉湪FTP瀹㈡埛绔湅瑙佷綘宸茬粡涓婅浇鐨勪笢瑗裤傦級濡傛灉浣犳槸涓涓敮鎸佸鎴凤紝浣犲彲浠ヤ娇鐢 MySQL瀹㈡埛鏀寔涓績https://support.mysql.com/ 鏉 鎻愰啋MySQL 鎶鏈汉鍛樿繖涓棶棰橈紝璁╄繖涓棶棰樺敖蹇緱鍒拌В鍐炽

濡傛灉浣犳兂缂╁皬闂鐨勮寖鍥达紝浣犱篃鍙互浣跨敤 mysql_find_rows鑴氭湰鏉ュ彧鎵ц涓浜 鏇存柊璇彞銆

E.2.聽璋冭瘯MySQL瀹㈡埛绔

涓鸿兘澶熺敤闆嗘垚鐨勮皟璇曡蒋浠跺寘璋冭瘯MySQL瀹㈡埛绔 锛屼綘搴旇鐢--with-debug鎴--with-debug=full閰嶇疆MySQL銆傝鍙傞槄2.8.2鑺傦紝鈥滃吀鍨嬬殑閰嶇疆閫夐」鈥

鍦ㄨ繍琛屽鎴风涔嬪墠锛屼綘搴旇璁剧疆 MYSQL_DEBUG鐜鍙橀噺锛

shell> MYSQL_DEBUG=d:t:O,/tmp/client.trace
shell> export MYSQL_DEBUG

杩欎細瀵艰嚧瀹㈡埛绔湪 /tmp/client.trace鐩綍浜х敓涓涓窡韪枃浠躲

濡傛灉浣犺嚜宸辩殑瀹㈡埛绔唬鐮佹湁闂锛屼綘搴旇璇曠潃杩炴帴鍒版湇鍔″櫒锛岀敤宸茬煡鍙敤鐨勫鎴风杩愯浣犵殑鏌ヨ銆傚湪璋冭瘯妯″紡涓嬶紝鎸変笅闈㈠懡浠よ繍琛岋紙鍋囪浣犲凡缁忓甫璋冭瘯缂栬瘧浜哅ySQL锛夛細

shell> mysql --debug=d:t:O,/tmp/client.trace

涓囦竴浣犺鍙戦佷竴涓己闄锋姤鍛婇偖浠讹紝杩欎細鎻愪緵缁欎綘鏈夌敤鐨勪俊鎭傝鏌ラ槄鈥滃浣曟姤鍛婄己闄锋垨闂鈥

濡傛灉浣犵殑瀹㈡埛绔湪涓浜涚湅璧锋潵鍚堟硶鐨勪唬鐮佸宕╂簝浜嗭紝浣犲簲璇ユ鏌ヤ綘鐨刴ysql.h鏂囦欢鏄惁鍖呮嫭鍖归厤浣犵殑MySQL搴撴枃浠躲備竴涓父瑙佺殑閿欒灏辨槸鐢ㄦ柊鐨勭増鏈殑MySQL搴撲娇鐢ㄤ竴涓潵鑷佺増鏈畨瑁呯殑mysql.h鏂囦欢銆

E.3. DBUG杞欢鍖

MySQL鏈嶅姟鍣ㄥ拰澶氭暟MySQL瀹㈡埛绔兘甯︾潃鐢盕red Fish鍒濆垱鐨凞BUG 杞欢鍖呯紪璇戞垚鐨勩傚綋浣犱负璋冭瘯閰嶇疆MytSQL涔嬫椂锛岃繖涓蒋浠朵娇浣犲彲浠ュ緱鍒颁竴涓▼搴忔鍦ㄨ皟璇曚粈涔堢殑璺熻釜鏂囦欢銆傝鍙傞槄E.1.2鑺傦紝鈥滃垱寤鸿窡韪枃浠垛

杩欎竴鑺傛荤粨浜嗕綘瀵瑰凡寤虹珛鏀寔璋冭瘯鐨凪ySQL绋嬪簭鍦ㄥ懡浠よ鐨勮皟璇曢夐」澶勫彲浠ユ寚瀹氱殑鍙傞噺鍊笺傝鑾峰彇鏇村浣跨敤DBUG杞欢鍖呮潵缂栫▼鐨勪俊鎭紝璇峰弬闃匨ySQL婧愬彂甯冨寘閲宒bug鐩綍涓嬬殑DBUG鎵嬪唽銆傛渶濂戒娇鐢ㄦ渶杩戠殑MySQL 5.1鍙戝竷鍖呬互鑾峰緱鏈杩戞洿鏂扮殑DBUG鎵嬪唽銆

浣犻氳繃鐢--debug="..."鎴杢he -#... 閫夐」璋冪敤涓涓▼搴忔潵浣跨敤璋冭瘯杞欢鍖呫

澶氭暟MySQL绋嬪簭鏈夐粯璁ょ殑璋冭瘯瀛楃涓诧紝濡傛灉浣犱笉缁--debug鎸囧畾涓涓夐」锛屽氨浣跨敤杩欎釜榛樿鐨勩傞粯璁ょ殑璺熻釜鏂囦欢閫氬父鏄/tmp/program_name.trace锛堝湪Unix涓婏級鍜孿program_name.trace 锛堝湪Windows涓婏級銆

璋冭瘯瀛楃涓叉槸涓绯诲垪鍐掑彿闅斿紑鐨勫尯娈碉紝濡備笅锛

<field_1>:<field_2>:...:<field_N>

姣忎釜鍖烘鍖呭惈涓涓己鍒舵爣蹇楀瓧绗︼紝鍚庨潰璺熺潃宸插拰鍙夌殑 鈥,鈥 浠ュ強涓鍒楃敤閫楀彿闅斿紑鐨勪慨鏀归噺锛

flag[,modifier,modifier,...,modifier]

褰撳墠琚瘑鍒殑鏍囪绗﹀彿鏄細

鏍囪鎻忚堪
d 鍏佽瀵瑰綋鍓嶇姸鎬佷粠DBUG_<N>瀹忚緭鍑恒傚彲鑳借窡鐫涓鍒楀叧閿瘝锛岃繖浜涘叧閿瘝浠呭閭d簺甯︽湁鍏抽敭璇嶇殑DBUG瀹忛夋嫨杈撳嚭銆備竴涓┖鐨勫叧閿瘝鍒楁剰鍛崇潃瀵规墍鏈夊畯杈撳嚭銆
D 鍦ㄦ瘡涓皟璇曡捣杈撳嚭琛屽悗寤惰繜銆傚弬閲忎竴涓崄鍒嗕箣涓绉掍负鍗曚綅鏉ュ欢杩熺殑鏁帮紝瀹冨彈闄愪簬鏈哄櫒鐨勮兘鍔涖傛瘮濡 -#D,20 鎸囧畾涓涓2绉掔殑寤惰繜銆
f 闄愬埗璋冭瘯鍜/鎴栬窡韪紝浠ュ強绠鍗曡瀹氫簬鍒楀嚭鍚嶅瓧鐨勫嚱鏁般傛敞鎰忥紝绌哄垪灏嗙姝㈡墍鐢ㄥ嚱鏁般傚簲璇ョ粰鍑洪傚綋鐨刣 鎴 t 鏍囪锛屽鏋滃畠浠鍏佽浜嗭紝杩欎釜鏍囪浠呴檺鍒跺畠浠殑鍔ㄤ綔銆
F 瀵硅皟璇曟垨璺熻釜杈撳嚭鐨勬瘡涓琛岃瘑鍒簮鏂囦欢鍚嶃
i 瀵硅皟璇曟垨璺熻釜杈撳嚭鐨勬瘡涓琛岀敤PID鎴栫嚎绋婭D璇嗗埆杩涚▼銆
g 鍏佽瑙f瀽锛屽垱寤哄悕涓虹殑dbugmon.out鏂囦欢锛屽畠鍖呭惈鍙敤鏉ョ畝鍗曡瀹氱▼搴忕殑淇℃伅銆傚彲鑳借窡鐫涓鍒楀叧閿瘝锛屽畠浠槸閫夋嫨鍙鍒椾腑鐨勫嚱鏁板仛绠鍗曡瀹氥備竴涓┖鍒楁剰鍛崇潃鎵鏈夊嚱鏁伴兘瑕佽冭檻鍒般
L 涓鸿皟璇曟垨璺熻釜杈撳嚭鐨勬瘡涓琛岃瘑鍒簮鏂囦欢琛屽彿銆
n 涓鸿皟璇曟垨璺熻釜杈撳嚭鐨勬瘡涓琛屾墦鍗板綋鍓嶅嚱鏁板祵濂楁繁搴︺
N 缁欒皟璇曡緭鍑虹殑姣忎竴琛岀紪鍙枫
o 閲嶅畾鍚戣皟璇曞櫒杈撳嚭娴佸埌鎸囧畾鏂囦欢銆傞粯璁よ緭鍑烘槸stderr 鏂囦欢銆
O 绫讳技浜 o锛屼絾鏄枃浠跺湪姣忔鍐欐搷浣滀箣闂磋鍐插埛銆傚綋闇瑕佷箣鏃讹紝鏂囦欢鍦ㄦ瘡娆″啓鎿嶄綔涔嬮棿琚叧闂劧鍚庨噸鏂版墦寮銆
p 闄愬埗璋冭瘯鍣ㄤ綔鐢ㄤ簬鎸囧畾杩涚▼銆備负浣胯皟璇曞櫒鍔ㄤ綔锛屼竴涓繘绋嬪繀椤荤敤DBUG_PROCESS瀹忔潵璇嗗埆锛屼笖鍖归厤鍒楄〃涓殑涓涓
P 涓鸿皟璇曟垨璺熻釜杈撳嚭鐨勬瘡涓琛屾墦鍗板綋鍓嶈繘绋嬪悕瀛椼
r 褰撴帹鍑轰竴涓柊鐘舵佹椂锛屼笉缁ф壙鍓嶇姸鎬佺殑鎿嶄綔宓屽娣卞害绾у埆銆傚綋杈撳嚭鍦ㄥ乏杈圭┖鐧藉紑濮嬫椂鏈夌敤銆
S 鍦ㄦ瘡涓皟璇曡繃鐨勫嚱鏁板仛_sanity(_file_,_line_)鍑芥暟鐩村埌 _sanity() 杩斿洖涓嶅悓浜0鐨勭粨鏋溿傦紙澶у鏁扮殑鏃跺欎笌safemalloc 涓璧风敤鏉ユ壘鍑哄唴瀛樻紡娲烇級銆
t 鍏佽鍑芥暟璋冪敤/閫鍑鸿窡韪銆傚彲鑳借窡鐫涓涓粰鍑烘渶澶ц窡韪骇鍒殑鏁板瓧鍒楋紙鍙惈涓涓慨鏀归噺锛夛紝瓒呰繃杩欎釜鏁板瓧锛岃皟璇曚腑鎴栬窡韪腑鐨勫畯涓嶈兘浜х敓浠讳綍杈撳嚭銆 榛樿涓轰竴涓紪璇戞椂闂撮夐」銆

鍙兘鍑虹幇鍦ㄥ澹冲懡浠よ锛-# 鍏稿瀷鍦拌鐢ㄦ潵寮曞叆涓涓帶鍒跺瓧绗︿覆鍒颁竴涓簲鐢ㄧ▼搴忎腑锛 鐨勮皟璇曟帶鍒跺瓧绗︿覆鐨勪竴浜涗緥瀛愬涓嬶細

-#d:t
-#d:f,main,subr1:F:L:t,20
-#d,input,output,files:n
-#d:t:i:O,\\mysqld.trace

鍦∕ySQL涓, 鎵撳嵃鐨勪竴鑸爣璁版槸锛堢敤 d 閫夐」锛夋槸 enter, exit, error, warning, info, 鍜 loop 銆

E.4.聽鍏充簬RTS绾跨▼鐨勬敞閲

鎴戞浘灏濊瘯璁㎝ySQL浣跨敤RTS绾跨▼杞欢鍖咃紝浣嗘槸鍦ㄤ笅闈㈢殑闂涓婇亣鍒伴樆纰嶏細

RTS绾跨▼杞欢鍖呭緢澶氳佺増鏈殑POSIX璋冪敤锛屽鎵鏈夊嚱鏁扮殑鍐欏皝瑁呭氨寰堟灟鐕ャ傛垜鍊惧悜浜庤涓烘妸绾跨▼搴撴崲鎴愭渶鏂扮殑POSIX瑙勬牸锛屼細鏇村鏄撲簺銆傘

涓浜涘皝瑁呮鍦ㄧ紪鍐欎腑銆傛洿澶氫俊鎭鍙傞槄mysys/my_pthread.c 鏂囦欢銆

鑷冲皯涓嬮潰璇撮亾鐨勫簲璇ユ敼鍙樹竴涓嬶細

pthread_get_specific璇ヤ娇鐢ㄤ竴涓弬閲忋 sigwait搴旇浣跨敤涓や釜鍙傞噺銆傚緢澶氬嚱鏁帮紙鑷冲皯pthread_cond_wait, pthread_cond_timedwait()锛夊簲璇ヨ繑鍥為敊璇殑閿欒浠g爜銆傜幇鍦ㄥ畠浠繑鍥 -1 涓旇缃 errno銆

鍙︿竴涓棶棰樻槸锛岀敤鎴风骇绾跨▼浣跨敤ALRM淇″彿锛岃繖浼氱粓姝㈠緢澶氬嚱鏁帮紙read, write, open...锛夈侻ySQL搴旇閲嶈瘯涓涓嬫墍鏈夎繖涓婇潰鐨勪腑鏂紝浣嗘槸杩欏苟闈炲緢瀹规槗鍘婚獙璇併

鏈澶х殑鏈В鍐抽棶棰樺涓嬶細

瑕佽幏寰楃嚎绋嬬骇璀︽姤锛屾垜浣跨敤pthread_cond_timedwait()鏀瑰彉 mysys/thr_alarm.c锛岃瀹冨湪璀︽姤涔嬮棿绛夊緟銆備絾鏄畠鍙戠敓EINTR閿欒锛岀粓姝簡銆傛垜璇曠潃璋冭瘯绾跨▼搴撴壘鍑轰负浠涔堜細鍑鸿繖涓敊璇紝浣嗘槸鎵句笉鍒颁竴涓畝渚 鐨勮В鍐冲姙娉曘

濡傛灉浜轰汉鎯宠鐢≧TS绾跨▼璺戜竴涓婱ySQL锛屾垜寤鸿浠ヤ笅鍑犵偣锛

  • 鎶奙ySQL浣跨敤鐨勫嚱鏁颁粠绾跨▼搴撳彉鍒癙OSIX銆傝繖涓嶄細鍗犳嵁閭d箞闀挎椂闂淬

  • 鐢-DHAVE_rts_threads缂栬瘧鎵鏈夊簱銆

  • 缂栬瘧thr_alarm銆

  • 鑻ュ湪鎵ц涓湁涓浜涘皬鐨勫樊寮傦紝鍙互鏀瑰彉my_pthread.h鍜宮y_pthread.c鏉ヤ慨澶嶅畠浠

  • 杩愯thr_alarm銆傚鏋滃畠娌℃湁浠讳綍璀﹀憡锛岄敊璇垨缁堟淇℃伅鍦拌繍琛岋紝浣犲氨鍋氬浜嗐傝繖閲屾槸涓涓湪Solaris鎴愬姛杩愯鐨勪緥瀛愶細

    Main thread: 1
    Thread 0 (5) started
    Thread: 5  Waiting
    process_alarm
    Thread 1 (6) started
    Thread: 6  Waiting
    process_alarm
    process_alarm
    thread_alarm
    Thread: 6  Slept for 1 (1) sec
    Thread: 6  Waiting
    process_alarm
    process_alarm
    thread_alarm
    Thread: 6  Slept for 2 (2) sec
    Thread: 6  Simulation of no alarm needed
    Thread: 6  Slept for 0 (3) sec
    Thread: 6  Waiting
    process_alarm
    process_alarm
    thread_alarm
    Thread: 6  Slept for 4 (4) sec
    Thread: 6  Waiting
    process_alarm
    thread_alarm
    Thread: 5  Slept for 10 (10) sec
    Thread: 5  Waiting
    process_alarm
    process_alarm
    thread_alarm
    Thread: 6  Slept for 5 (5) sec
    Thread: 6  Waiting
    process_alarm
    process_alarm
    
    ...
    thread_alarm
    Thread: 5  Slept for 0 (1) sec
    end
    

E.5.聽绾跨▼杞欢鍖呬箣闂寸殑宸紓

MySQL闈炲父渚濊禆浣跨敤涓殑绾跨▼杞欢鍖呫 鎵浠ュ綋涓篗ySQL閫夋嫨涓涓ソ骞冲彴鐨勬椂鍊欙紝绾跨▼杞欢鍖呭氨闈炲父閲嶈銆

鑷冲皯鏈変笁绉嶇嚎绋嬭蒋浠跺寘锛

  • 鐢ㄦ埛绾跨▼鍦ㄥ崟涓繘绋嬩腑銆傜嚎绋嬪垏鎹㈢敤璀︽姤绠$悊锛岀嚎绋嬪簱鐢ㄩ攣绠$悊鎵鏈夐潪绾跨▼瀹夊叏鍑芥暟銆傝锛屽啓鍜岄夋嫨鎿嶄綔閫氬父琚嚎绋嬩笓鏈夌殑鍒囨崲鍣ㄧ鐞嗭紝 濡傛灉杩愯涓殑绾跨▼瑕佺瓑寰呮暟鎹紝杩欎釜鍒囨崲鍣ㄥ氨浼氬垏鎹㈡搷浣滃埌鍙︿竴涓嚎绋嬨傚鏋滅敤鎴风嚎绋嬭蒋浠跺寘闆嗘垚鍦ㄦ爣鍑嗗簱锛團reeBSD 鍜 BSDI 绾跨▼杞欢鍖咃級閲岋紝杩欐牱鐨 绾跨▼杞欢鍖呮瘮閭d簺涓嶅緱涓嶆槧灏勬墍鏈変笉瀹夊叏璋冪敤锛圡IT-pthreads, FSU Pthreads 鍜 RTS 绾跨▼杞欢鍖咃級鐨勭嚎绋嬭蒋浠跺寘闇瑕佹洿灏戠殑绯荤粺寮閿銆傚湪鏌愪簺鐜涓嬶紙濡係CO锛夛紝鎵鏈夌郴缁熻皟鐢ㄩ兘鏄嚎绋嬪畨鍏ㄧ殑锛屾墍浠ユ槧灏勯潪甯稿鏄擄紙SCO涓婄殑FSU Pthreads鍖咃級銆備笉瓒充箣澶勬槸锛氭墍鏈夋槧灏勭殑璋冪敤鍗犵敤寰堝皯鐨勬椂闂达紝浜庢槸鎯宠鑳藉鐞嗘墍鏈夌殑鎯呭喌灏辩浉褰撶箒鏉傘傛湁涓浜涚郴缁熻皟鐢ㄩ氬父涓嶈绾跨▼杞欢鍖咃紙绫讳技MIT-pthreads and sockets鍖咃級澶勭悊銆傜嚎绋嬭鍒掍笉鎬绘槸鏈浼樺寲鐨勩

  • 鍦ㄥ垎绂昏繘绋嬩腑鐨勭敤鎴风嚎绋嬨傜嚎绋嬪垏鎹㈡槸鐢卞唴鏍告潵鍋氾紝涓旀墍鏈夌殑鏁版嵁鍦ㄧ嚎绋嬩箣闂村叡浜傜嚎绋嬭蒋浠跺寘绠$悊鏍囧噯绾跨▼璋冪敤锛屽厑璁稿湪绾跨▼涔嬮棿鍏变韩鏁版嵁銆侺inuxThreads鍖呭氨浣跨敤杩欑鏂规硶銆備笉瓒充箣澶勶細澶杩涚▼銆傜嚎绋嬪垱寤哄緱鎱紝濡傛灉涓涓嚎绋嬫鎺変簡锛屽叾浣欏緱绾跨▼閫氬父灏辨寕璧锋潵锛屼綘蹇呴』鍦ㄩ噸鍚箣鍓嶆潃鎺夎繖浜涙寕璧风殑绾跨▼銆傜嚎绋嬪垏鎹㈠紑閿鏈変簺澶с

  • 鍐呮牳绾跨▼銆傜嚎绋嬪垏鎹㈢敱绾跨▼搴撴垨鍐呮牳鏉ュ仛锛屽苟涓旈潪甯稿揩銆備竴涓繘绋嬪氨鍙互浜嗐備絾鍦ㄤ竴浜涚郴缁熶腑ps鍙兘鏄剧ず涓嶅悓绾跨▼銆傚鏋滀竴涓嚎绋嬬粓姝紝鏁翠釜杩涚▼灏辩粓姝簡銆傚鏁扮郴缁 璋冪敤鏄嚎绋嬪畨鍏ㄧ殑锛屽苟涓斿彧瑕侀潪甯稿皬鐨勭郴缁熷紑閿銆Solaris, HP-UX, AIX 鍜孫SF/1 閮芥湁鍐呮牳绾跨▼銆

鍦ㄤ竴浜涚郴缁熶腑鍐呮牳绾跨▼琚郴缁熷簱涓暣鍚堢敤鎴风骇绾跨▼绠$悊銆傚湪杩欑鎯呭喌涓嬶紝绾跨▼鍒囨崲鍙兘鐢辩嚎绋嬪簱鏉ュ仛锛岃屽唴鏍稿苟涓嶆槸鐪熸鐨勨滅嚎绋嬫劅鐭モ濈殑銆


杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com銆 鍘熷鍙傝冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆