鐩綍
褰撲綘閬囧埌闂鏃讹紝棣栧厛瑕佸仛鐨勬槸鎵惧嚭瀵艰嚧闂鐨勭▼搴忓拰璁惧閮ㄤ欢锛
路 濡傛灉閬囧埌涓嬭堪寰佸厗涔嬩竴锛屾垨璁告槸鍥犱负纭欢闂锛堝鍐呭瓨銆佷富鏉裤CPU鎴栫‖鐩橈級鎴栧唴鏍搁棶棰橈細
1. 閿洏涓嶅伐浣溿傛甯告儏鍐典笅鍙氳繃鎸Caps Lock寤鸿繘琛屾鏌ャ傚鏋Caps Lock鐨勭偣浜姸鎬佹湭鏀瑰彉锛屽氨闇瑕佹洿鎹㈤敭鐩橈紙鍦ㄦ涔嬪墠锛屽簲灏濊瘯閲嶅惎璁$畻鏈猴紝骞舵鏌ヤ笌閿洏鐩歌繛鐨勬墍鏈夌數缂嗭級銆
2. 榧犳爣鎸囬拡涓嶇Щ鍔ㄣ
3. 鏈哄櫒鏈杩滅▼鏈哄櫒鐨Ping鍛戒护鍋氬嚭搴旂瓟銆
4. 涓MySQL鏃犲叧鐨勫叾浠栫▼搴忓伐浣滀笉姝e父銆
5. 绯荤粺鎰忓閲嶅惎锛堟湁闂鐨勭敤鎴风骇绋嬪簭搴斾笉鑳戒娇绯荤粺鍑虹幇涓ラ噸闂锛夈
鍦ㄨ鎯呭喌涓嬶紝搴旀鏌ユ墍鏈夌殑鐢电紗骞惰繍琛屾煇浜涜瘖鏂伐鍏凤紝瀵逛綘鐨勭‖浠惰繘琛屾鏌ワ紒姝ゅ锛岃繕搴旀鏌ユ槸鍚︽湁鑳藉瑙e喅闂鐨勩侀傜敤浜庝綘鐨勬搷浣滅郴缁熺殑琛ヤ竵銆佹洿鏂版垨鏈嶅姟鍖呫傝妫鏌ユ墍鏈夌殑搴擄紙濡glibc锛夋槸鍚︽槸鏈鏂扮殑銆
浣跨敤閰嶅ECC鍐呭瓨鐨勬満鍣ㄤ互渚垮敖鏃╁彂鐜伴棶棰樻绘槸涓ソ涓绘剰銆
路 濡傛灉閿洏宸查攣瀹氾紝鍙粠鍙︿竴鍙版満鍣ㄧ櫥褰曞埌浣犵殑鏈哄櫒锛屽苟鎵цkbd_mode 鈥揳锛屾垨璁歌兘鎭㈠銆
路 璇锋鏌ョ郴缁熺殑鏃ュ織鏂囦欢锛/var/log/messages鎴栫被浼肩墿锛変互鎵惧嚭闂鐨勫師鍥犮傚鏋滀綘璁や负闂鍑哄湪MySQL涓紝搴旀鏌MySQL鐨勬棩蹇楁枃浠躲傝鍙傝5.11鑺傦紝鈥淢ySQL鏃ュ織鏂囦欢鈥銆
路 濡傛灉浣犱笉璁や负瀛樺湪纭欢闂锛屽簲灏濊瘯鎵惧嚭瀵艰嚧闂鐨勫師鍥犮傝浣跨敤top銆ps銆佷换鍔$鐞嗗櫒鎴栫被浼肩▼搴忥紝浠ユ鏌ュ摢涓▼搴忓崰鐢ㄤ簡鎵鏈CPU鏃堕棿鎴栭攣瀹氫簡鏈哄櫒銆
路 浣跨敤top銆df鎴栫被浼肩▼搴忔鏌ユ槸鍚﹀唴瀛樹笉澶熴佺鐩樼┖闂翠笉瓒炽佹枃浠舵弿杩扮缂轰箯銆佹垨鍏朵粬鍏抽敭璧勬簮缂哄皯銆
路 濡傛灉闂鏄け鍘绘帶鍒剁殑杩涚▼锛屽簲灏濊瘯鏉姝诲畠銆傚鏋滄潃涓嶆杩涚▼锛屾垨璁告槸鍥犱负鎿嶄綔绯荤粺涓瓨鍦ㄧ己闄枫
濡傛灉鍦ㄦ鏌ヤ簡鎵鏈夊叾浠栧彲鑳芥т箣鍚庯紝骞跺緱鍑虹粨璁洪棶棰樻槸鐢MySQL鏈嶅姟鍣ㄦ垨MySQL瀹㈡埛绔鑷寸殑锛屽簲鍒涘缓鎻愪緵缁欐垜鏂圭殑閭欢鍒楄〃鎴栨敮鎸佸洟闃熺殑缂洪櫡鎶ュ憡銆傚湪缂洪櫡鎶ュ憡涓紝璇疯缁嗘弿杩扮郴缁熺殑琛屼负锛屼互鍙婁綘璁や负鍙戠敓浜嗕粈涔堟儏鍐点+3.
杩樺簲闃愭槑涓轰粈涔堜綘璁や负鏄MySQL瀵艰嚧浜嗛棶棰樸傝鑰冭檻鏈珷浠嬬粛鐨勬墍鏈夋儏鍐点傚噯纭槓鏄庡綋浣犳鏌ョ郴缁熸椂闂鏄浣曞嚭鐜扮殑銆傚浜庣▼搴忓拰鏃ュ織鏂囦欢鐨勪换浣曡緭鍑哄拰閿欒娑堟伅锛岃浣跨敤鈥滃鍒跺拰绮樿创鈥濇柟娉曘
灏介噺璇︾粏鎻忚堪涓嶅伐浣滅殑绋嬪簭锛屼互鍙婁綘鎵瑙佸埌鐨勬墍鏈夊緛鍏嗐傛垜浠繃鍘绘敹鍒拌繃寰堝浠呰鏄庘滅郴缁熶笉宸ヤ綔鈥濈殑缂洪櫡鎶ュ憡銆傝繖涓嶄細涓烘垜浠彁渚涙湁鍔╀簬瑙e喅闂鐨勪俊鎭
濡傛灉绋嬪簭澶辫触锛屼簡瑙d笅杩颁俊鎭绘槸鏈夌敤鐨勶細
路 鏈夊珜鐤戠殑绋嬪簭鏄惁鍑虹幇浜嗗垎娈垫晠闅滐紙鏄惁杞偍鍐呮牳锛夛紵
路 绋嬪簭鏄惁鍗犵敤浜嗘墍鏈夊彲鐢ㄧ殑CPU鏃堕棿锛熺敤top.杩涜妫鏌ャ傝绋嬪簭杩愯涓娈垫椂闂达紝鎴栬鑳界畝鍗曞湴璇勪及鏌愪簺浜嬫槸鍚︽槸璁$畻瀵嗛泦鎬х殑銆
路 濡傛灉闂鏄洜mysqld鏈嶅姟鍣ㄥ鑷寸殑锛屼娇鐢mysqladmin -u root ping鎴mysqladmin -u root processlist鏄惁鑳借幏寰楁湇鍔″櫒鐨勫搷搴旓紵
路 褰撲綘灏濊瘯杩炴帴鍒MySQL鏈嶅姟鍣紙渚嬪锛mysql锛夋椂锛屽鎴风绋嬪簭缁欏嚭鐨勪俊鎭槸浠涔堬紵瀹㈡埛绔槸鍚﹀牭濉烇紵鏄惁鑾峰緱浜嗘潵鑷▼搴忕殑浠讳綍杈撳嚭锛
鍙戦佺己闄锋姤鍛婃椂锛岃閬靛惊1.7.1.2鑺傦紝鈥滆鏁欓棶棰樻垨閫氭姤缂洪櫡鈥涓粰鍑虹殑璇存槑銆
鏈妭鍒楀嚭浜嗙敤鎴疯繍琛MySQL鏈嶅姟鍣ㄦ椂甯镐細閬囧埌鐨勪竴浜涢敊璇傚敖绠¢棶棰樻槸鍦ㄤ綘灏濊瘯杩愯瀹㈡埛绔椂鍑虹幇鐨勶紝浣嗗寰堝闂鐨勮В鍐虫柟妗堟潵璇达紝闇瑕佹洿鏀MySQL鏈嶅姟鍣ㄧ殑閰嶇疆銆
瀵艰嚧鎷掔粷璁块棶閿欒鐨勫師鍥犲緢澶氥傝閿欒甯镐笌杩炴帴鏃舵湇鍔″櫒鍏佽瀹㈡埛绔娇鐢ㄧ殑MySQL璐︽埛鏈夊叧銆傝鍙傝5.7.8鑺傦紝鈥滄嫆缁濊闂敊璇殑鍘熷洜鈥銆傝鍙傝5.7.2鑺傦紝鈥滄潈闄愮郴缁熷伐浣滃師鐞嗏銆
Unix骞冲彴涓婄殑MySQL瀹㈡埛绔兘澶熶互涓ょ涓嶅悓鐨勬柟寮忚繛鎺ュ埌mysqld鏈嶅姟鍣細閫氳繃鏂囦欢绯荤粺涓殑鏂囦欢锛堥粯璁や负/tmp/mysql.sock锛変娇鐢Unix濂楁帴瀛楄繘琛岃繛鎺ワ紝鎴栭氳繃绔彛鍙蜂娇鐢TCP/IP杩涜杩炴帴銆Unix濂楁帴瀛楁枃浠剁殑杩炴帴閫熷害姣TCP/IP蹇紝浣嗕粎鑳藉湪涓庣浉鍚岃绠楁満涓婄殑鏈嶅姟鍣ㄧ浉杩炴椂浣跨敤銆傚鏋滄湭鎸囧畾鎸囧畾涓绘満鍚嶆垨鎸囧畾浜嗙壒娈婄殑涓绘満鍚localhost锛屽皢浣跨敤Unix濂楁帴瀛椼
濡傛灉MySQL鏈嶅姟鍣ㄨ繍琛屽湪Windows 9x鎴Me涓婏紝浠呰兘閫氳繃TCP/IP杩涜杩炴帴銆傚鏈嶅姟鍣ㄨ繍琛屽湪Windows NT銆2000銆XP鎴2003涓婏紝鑰屼笖浣跨敤--enable-named-pipe閫夐」鍚姩锛屽鏋滃湪杩愯鏈嶅姟鍣ㄧ殑鏈哄櫒涓婅繍琛屽鎴风锛屼篃鑳戒娇鐢ㄥ懡鍚嶇閬撹繘琛岃繛鎺ャ榛樿鎯呭喌涓嬶紝鍛藉悕绠¢亾鐨勫悕绉颁负MySQL銆傚鏋滃湪杩炴帴鍒mysqld鏃舵湭缁欏畾涓绘満鍚嶏紝MySQL瀹㈡埛绔鍏堜細灏濊瘯杩炴帴鍒板懡鍚嶇閬撱傚鏋滀笉鑳藉伐浣滐紝灏嗚繛鎺ュ埌TCP/IP绔彛銆備娇鐢ㄢ.鈥濅綔涓轰富鏈哄悕锛屽彲鍦Windows骞冲彴涓婂己鍒朵娇鐢ㄥ懡鍚嶇閬撱
閿欒(2002)鈥滄棤娉曡繛鎺ュ埌鈥︹閫氬父鎰忓懗鐫鍦ㄧ郴缁熸病鏈夎繍琛岀殑MySQL鏈嶅姟鍣紝鎴栧湪杩炴帴鍒版湇鍔″櫒鏃朵娇鐢ㄤ簡涓嶆纭殑Unix濂楁帴瀛楁枃浠跺悕鎴TCP/IP绔彛鍙枫
棣栧厛妫鏌ユ湇鍔″櫒涓绘満涓婃槸鍚︽湁鍚嶄负mysqld鐨勮繘绋嬶紙鍦Unix骞冲彴涓婁娇鐢ps xa | grep mysqld锛屾垨鍦Windows骞冲彴涓婁娇鐢ㄤ换鍔$鐞嗗櫒锛夈傚鏋滄病鏈夎繖绫昏繘绋嬶紝搴斿惎鍔ㄦ湇鍔″櫒銆傝鍙傝2.9.2.3鑺傦紝鈥滃惎鍔∕ySQL鏈嶅姟鍣ㄤ互鍙婂叾鏁呴殰璇婃柇鍜屾帓闄も銆
濡傛灉mysqld杩涚▼姝e湪杩愯锛屽彲浣跨敤涓嬭堪鍛戒护妫鏌ャ傚湪浣犵殑鍏蜂綋璁剧疆涓紝绔彛鍙锋垨Unix濂楁帴瀛楁枃浠跺悕鍙兘浼氭湁鎵涓嶅悓銆host_ip浠h〃杩愯鏈嶅姟鍣ㄧ殑鏈哄櫒鐨IP缂栧彿銆
shell> mysqladmin version
shell> mysqladmin variables
shell> mysqladmin -h `hostname` version variables
shell> mysqladmin -h `hostname` --port=3306 version
shell> mysqladmin -h host_ip version
shell> mysqladmin --protocol=socket --socket=/tmp/mysql.sock version
娉ㄦ剰锛屽簲涓庝富鏈哄悕鍛戒护涓璧蜂娇鐢ㄢ`鈥濊屼笉鏄溾欌濓紝杩欎細浣夸富鏈哄悕杈撳嚭锛堝綋鍓嶄富鏈哄悕锛夎浠e叆mysqladmin鍛戒护銆傚鏋滄病鏈変富鏈哄悕鍛戒护鎴栨杩愯鍦Windows骞冲彴涓婏紝搴斾互鎵嬪姩鏂瑰紡杈撳叆鏈哄櫒鐨勪富鏈哄悕锛堟棤鈥`鈥濈鍙凤級锛屽悗璺-h閫夐」銆涔熷彲浠ヤ娇鐢TCP/IP鍗忚鐢-h 127.0.0.1杩炴帴鍒版湰鍦颁富鏈恒
涓嬮潰缁欏嚭浜嗕竴浜涒滄棤娉曡繛鎺ュ埌鏈湴MySQL鏈嶅姟鍣ㄢ濋敊璇殑鍙兘鍘熷洜锛
1. Mysqld鏈繍琛屻傝妫鏌ユ搷浣滅郴缁熺殑杩涚▼鍒楄〃浠ョ‘淇mysqld杩涚▼姝e湪杩愯銆
2. 浣犳鍦ㄥ叿鏈夊緢澶TCP/IP杩炴帴鐨Windows骞冲彴涓婅繍琛MySQL鏈嶅姟鍣ㄣ傚鏋滀綘鐨勫鎴风缁忓父鍑虹幇閿欒锛岃鍙傝A.2.2.1鑺傦紝鈥滃湪Windows涓婁笌MySQL鏈嶅姟鍣ㄧ殑杩炴帴澶辫触鈥锛屼互鎵惧嚭瑙勯伩鏂规硶銆
3. 浣犳鍦ㄤ娇鐢MIT-pthreads鐨勭郴缁熶笂杩愯銆傚鏋滀綘姝e湪杩愯涓嶅叿鏈夊浐鏈夌嚎绋嬬殑鎿嶄綔绯荤粺锛mysqld灏嗕娇鐢MIT-pthreads杞欢鍖呫傝鍙傝2.1.1鑺傦紝鈥淢ySQL鏀寔鐨勬搷浣滅郴缁熲銆備絾鏄紝骞堕潪鎵鏈夌殑MIT-pthreads鐗堟湰鍧囨敮鎸Unix濂楁帴瀛楁枃浠躲傚湪涓嶆敮鎸佸鎺ュ瓧鏂囦欢鐨勭郴缁熶笂锛岃繛鎺ュ埌鏈嶅姟鍣ㄦ椂锛屽繀椤绘槑纭寚瀹氫富鏈哄悕銆傝浣跨敤涓嬭堪鍛戒护鏉ユ鏌ユ槸鍚﹁繛鎺ュ埌浜嗘湇鍔″櫒锛
4. shell> mysqladmin -h `hostname` version
5.
鏌愪汉绉诲姩浜mysqld浣跨敤鐨Unix濂楁帴瀛楁枃浠讹紙榛樿涓/tmp/mysql.sock锛夈備緥濡傦紝浣犲彲鑳芥墽琛屼簡灏嗘棫鏂囦欢浠/tmp鐩綍鍒犻櫎鐨cron浠诲姟銆備綘鎬昏兘鎵цmysqladmin
version鏉ユ鏌mysqladmin璇曞浘浣跨敤鐨Unix濂楁帴瀛楁枃浠舵槸鍚︾殑纭瓨鍦ㄣ傚湪璇ユ儏鍐典笅锛屾洿姝f柟寮忔槸鏇存敼cron浠诲姟锛屼笉鍒犻櫎mysql.sock鏂囦欢锛屾垨灏嗗鎺ュ瓧鏂囦欢缃簬鍏朵粬鍦版柟銆璇峰弬瑙A.4.5鑺傦紝鈥滃浣曚繚鎶ゆ垨鏇存敼MySQL濂楁帴瀛楁枃浠/tmp/mysql.sock鈥銆
6. 浣犱娇鐢--socket=/path/to/socket閫夐」鍚姩浜mysqld鏈嶅姟鍣紝褰撳繕璁板皢濂楁帴瀛楁枃浠剁殑鏂板悕绉伴氱煡瀹㈡埛绔▼搴銆傚鏋滄洿鏀逛簡鍏充簬鏈嶅姟鍣ㄧ殑濂楁帴瀛楄矾寰勶紝涔熷繀椤婚氱煡MySQL瀹㈡埛绔傚彲鍦ㄨ繍琛屽鎴风绋嬪簭鏃朵娇鐢ㄧ浉鍚岀殑鈥攕ocket閫夐」鏉ュ畬鎴愯浠诲姟銆傛澶栵紝浣犺繕搴旂‘淇濆鎴风鍏锋湁璁块棶鏂囦欢mysql.sock鐨勬潈闄愩傝鎯虫壘鍑哄鎺ュ瓧鏂囦欢鐨勪綅缃紝鍙娇鐢細
7. shell> netstat -ln | grep mysql
璇峰弬瑙A.4.5鑺傦紝鈥滃浣曚繚鎶ゆ垨鏇存敼MySQL濂楁帴瀛楁枃浠/tmp/mysql.sock鈥銆
8. 浣犳鍦ㄤ娇鐢Linux鑰屼笖1涓湇鍔″櫒绾跨▼宸叉浜★紙鍐呮牳宸叉竻闄わ級銆傚湪姝ゆ儏鍐典笅锛屽湪閲嶅惎MySQL鏈嶅姟鍣ㄤ箣鍓嶏紝蹇呴』鏉姝诲叾浠mysqld绾跨▼锛堜緥濡傦紝浣跨敤kill鎴mysql_zap鑴氭湰锛夈璇峰弬瑙A.4.2鑺傦紝鈥滃鏋淢ySQL渚濈劧宕╂簝锛屽簲浣滀簺浠涔堚銆
9. 鏈嶅姟鍣ㄦ垨瀹㈡埛绔▼搴忎笉鍏锋湁璁块棶鍖呭惈Unix濂楁帴瀛楁枃浠剁殑鐩綍鎴栧鎺ュ瓧鏂囦欢鏈韩鐨勬伆褰撴潈闄愩傚湪璇ユ儏鍐典笅锛屽繀椤绘洿鏀圭洰褰曟垨濂楁帴瀛楁枃浠剁殑璁块棶鏉冮檺锛屼互渚挎湇鍔″櫒鎴栧鎴风绋嬪簭鑳藉璁块棶瀹冧滑锛屾垨鐢鈥搒ocket閫夐」閲嶅惎mysqld锛屽湪璇ラ夐」涓寚瀹氭湇鍔″櫒鑳藉垱寤恒佽屼笖瀹㈡埛绔彲璁块棶鐨勭洰褰曚笅鐨勫鎺ュ瓧鏂囦欢鍚嶃
濡傛灉閬囧埌閿欒娑堟伅鈥滄棤娉曡繛鎺ュ埌some_host涓婄殑MySQL鏈嶅姟鍣鈥濓紝鍙皾璇曢噰鍙栦笅杩版楠や互鎵惧嚭闂鎵鍦細
路 鎵ц鈥telnet some_host 3306鈥骞舵寜涓ゆ鍥炶溅閿紝妫鏌ユ湇鍔″櫒鏄惁杩愯鍦ㄨ涓绘満涓婏紙3306鏄粯璁ょ殑MySQL绔彛鍙枫傚鏋滀綘鐨勬湇鍔″櫒姝e湪鐩戝惉涓嶅悓鐨勭鍙o紝璇锋洿鏀硅鍊硷級銆傚鏋滄湁1涓MySQL鏈嶅姟鍣ㄦ鍦ㄨ繍琛屽苟鐩戝惉璇ョ鍙o紝浣犲簲鏀跺埌鍖呭惈鏈嶅姟鍣ㄧ増鏈彿鐨勫洖搴斻傚鏋滈亣鍒伴敊璇紝濡傗telnet:鏃犳硶杩炴帴鍒拌繙绋嬩富鏈:鎷掔粷杩炴帴鈥锛岃〃绀哄湪璇ュ畾绔彛涓婃病鏈夎繍琛岀殑鏈嶅姟鍣ㄣ
路 濡傛灉鏈嶅姟鍣ㄦ杩愯鍦ㄦ湰鍦颁富鏈轰笂锛岃浣跨敤Unix濂楁帴瀛楁枃浠讹紝骞朵娇鐢mysqladmin -h localhost variables杩涜杩炴帴銆傞獙璇佹湇鍔″櫒鐩戝惉鐨TCP/IP绔彛鍙凤紙瀹冩槸port鍙橀噺鐨勫硷級銆
路 纭繚浣犵殑mysqld鏈嶅姟鍣ㄦ湭鐢--skip-networking閫夐」鍚姩銆濡傛灉浣跨敤浜嗚閫夐」锛屽皢鏃犳硶浣跨敤TCP/IP杩炴帴鍒板畠銆
路 妫鏌ュ苟纭涓嶅瓨鍦ㄥ睆钄戒簡瀵MySQL璁块棶鐨勯槻鐏銆傞渶瑕侀厤缃濡ZoneAlarm鍜Windows XP涓汉闃茬伀澧欑瓑搴旂敤绋嬪簭锛屼互鍏佽瀵MySQL鏈嶅姟鍣ㄧ殑澶栭儴璁块棶銆
榛樿鎯呭喌涓嬶紝Windows鍏佽鐢ㄤ簬浣跨敤5000涓复鏃讹紙鐭懡锛TCP绔彛銆備换浣曠鍙e叧闂悗锛屽畠灏嗗湪TIME_WAIT鐘舵佷繚鎸120绉掋備笌閲嶆柊鍒濆鍖栧叏鏂扮殑杩炴帴鐩告瘮锛岃鐘舵佸厑璁镐互鏇翠綆鐨勫紑閿閲嶆柊浣跨敤杩炴帴銆浣嗘槸锛屽湪璇ユ椂闂撮濆幓鍓嶏紝鏃犳硶鍐嶆浣跨敤璇ョ鍙c
瀵逛簬灏忕殑鍙敤TCP绔彛鍫嗘爤锛5000锛夛紝浠ュ強鍏锋湁TIME_WAIT鐘舵佺殑澶ч噺鍦ㄧ煭鏃堕棿鍐呮墦寮鍜屽叧闂殑TCP绔彛锛屼綘寰堝彲鑳介亣鍒扮鍙h楀敖闂銆傚鐞嗚闂鐨勬柟娉曟湁涓ょ锛
路 閫氳繃璋冩煡杩炴帴姹犱互鍙婂彲鑳界殑鎸佷箙杩炴帴锛屽噺灏戝揩閫熸秷鑰楃殑TCP绔彛鏁般
路 璋冩暣Windows娉ㄥ唽琛ㄤ腑鐨勬煇浜涜缃紙璇峰弬瑙佷笅闈級銆
瑕佺偣锛氫笅杩版楠ゆ秹鍙婃洿鏀Windows 娉ㄥ唽琛ㄣ傛洿鏀规敞鍐岃〃涔嬪墠锛岃澶囦唤娉ㄥ唽琛紝骞剁‘璁や綘宸叉帉鎻″湪鍑虹幇闂鏃舵仮澶嶆敞鍐岃〃鐨勬柟娉曘傚叧浜庡浠藉勾銆佹仮澶嶅拰缂栬緫娉ㄥ唽琛ㄧ殑鏇村淇℃伅锛岃璇峰弬瑙Microsoft鐭ヨ瘑搴撲腑鐨勪笅杩版枃鐚細http://support.microsoft.com/kb/256986/EN-US/銆
路 鍚姩娉ㄥ唽琛ㄧ紪杈戝櫒锛Regedt32.exe锛夈
路 鍦ㄦ敞鍐岃〃涓‘瀹氫笅杩伴敭鍊肩殑浣嶇疆锛
路 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
路 鍦ㄢ滅紪杈戔濊彍鍗曚笂鐐瑰嚮鈥滄坊鍔犲尖濓紝鐒跺悗澧炲姞涓嬭堪娉ㄥ唽鍊硷細
路 Value Name: MaxUserPort
路 Data Type: REG_DWORD
路 Value: 65534
瀹冪敤浜庤缃负浠讳綍鐢ㄦ埛鎻愪緵鐨勪复鏃剁鍙f暟銆傛湁鏁堣寖鍥翠粙浜5000鍜65534涔嬮棿锛堝崄杩涘埗锛夈傞粯璁ゅ间负0x1388锛5000锛屽崄杩涘埗锛夈
路 鍦ㄢ滅紪杈戔濊彍鍗曚笂鐐瑰嚮鈥滄坊鍔犲尖濓紝鐒跺悗澧炲姞涓嬭堪娉ㄥ唽鍊硷細
路 Value Name: TcpTimedWaitDelay
路 Data Type: REG_DWORD
路 Value: 30
瀹冪敤浜庤缃叧闂箣鍓嶅皢TCP绔彛杩炴帴淇濇寔鍦TIME_WAIT鐘舵佺殑绉掓暟銆鏈夋晥鑼冨洿浠嬩簬0绉掑拰300绉掍箣闂淬傞粯璁ゅ间负0x78锛120绉掞級銆
路 閫鍑烘敞鍐岃〃缂栬緫鍣ㄣ
路 閲嶆柊寮曞鏈哄櫒銆
娉ㄩ噴锛氭挙閿涓婅堪璁剧疆鍗佸垎绠鍗曪紝灏卞儚鍒犻櫎浣犲垱寤虹殑娉ㄥ唽琛ㄤ竴鏍枫
MySQL 5.1閲囩敤浜嗗熀浜庡瘑鐮佹贩缂栫畻娉曠殑閴村畾鍗忚锛屽畠涓庢棭鏈熷鎴风锛4.1涔嬪墠锛変娇鐢ㄧ殑鍗忚涓嶅吋瀹广傚鏋滀綘灏嗘湇鍔″櫒鍗囩骇鍒4.1涔嬩笂锛岀敤鏃╂湡鐨勫鎴风杩涜杩炴帴鍙兘澶辫触锛屽苟缁欏嚭涓嬭堪娑堟伅锛
shell> mysql
瀹㈡埛绔笉鏀寔鏈嶅姟鍣ㄨ姹傜殑閴村畾鍗忚锛氳鑰冭檻鍗囩骇MySQL瀹㈡埛绔
瑕佹兂瑙e喅璇ラ棶棰橈紝搴斾娇鐢ㄤ笅杩版柟娉曚箣涓锛
路 鍗囩骇鎵鏈夌殑瀹㈡埛绔▼搴忥紝浠ヤ娇鐢4.1.1鎴栨洿鏂扮殑瀹㈡埛绔簱銆
路 鐢4.1鐗堜箣鍓嶇殑瀹㈡埛绔繛鎺ュ埌鏈嶅姟鍣ㄦ椂锛岃浣跨敤浠嶅叿鏈4.1鐗堜箣鍓嶉鏍煎瘑鐮佺殑璐︽埛銆
路 瀵逛簬闇瑕佷娇鐢4.1鐗堜箣鍓嶇殑瀹㈡埛绔殑姣忎綅鐢ㄦ埛锛屽皢瀵嗙爜鎭㈠涓4.1鐗堜箣鍓嶇殑椋庢牸銆傚彲浠ヤ娇鐢SET PASSWORD璇彞鍜OLD_PASSWORD()鍑芥暟瀹屾垚璇ヤ换鍔★細
路 mysql> SET PASSWORD FOR
路 -> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');
涔熷彲浠ヤ娇鐢UPDATE鍜FLUSH PRIVILEGES锛
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
-> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;
鐢ㄤ綘鎵撶畻浣跨敤鐨勫瘑鐮佹浛鎹㈠墠渚嬩腑鐨勨newpwd鈥濄MySQL涓嶈兘鍛婅瘔浣犲師鏉ョ殑瀵嗙爜鏄粈涔堬紝鍥犳锛屼綘闇瑕侀夋嫨鏂扮殑瀵嗙爜銆
路 閫氱煡鏈嶅姟鍣ㄤ娇鐢ㄦ棫鐨勫瘑鐮佹贩缂栫畻娉曪細
1. 浣跨敤鈥--old-passwords鈥濋夐」鍚姩mysqld銆
2. 瀵逛簬宸插皢瀵嗙爜鏇存柊涓鸿緝闀4.1鏍煎紡鐨勬瘡涓处鎴凤紝涓哄叾鎸囧畾鍏锋湁鏃ф牸寮忕殑瀵嗙爜銆傚彲浠ヤ娇鐢ㄤ笅杩版煡璇㈢‘瀹氳繖浜涜处鎴凤細
3. mysql> SELECT Host, User, Password FROM mysql.user
4. -> WHERE LENGTH(Password) > 16;
瀵逛簬鏌ヨ鏄剧ず鐨勬瘡涓处鎴疯褰曪紝璇蜂娇鐢Host鍜User鍊硷紝骞朵娇鐢OLD_PASSWORD()鍑芥暟浠ュ強SET PASSWORD鎴UPDATE涔嬩竴鎸囧畾瀵嗙爜锛屽鍓嶉潰鎵浠嬬粛鐨勯偅鏍枫
娉ㄩ噴锛鍦ㄦ棭鏈熺殑PHP鐗堟湰涓紝mysql鎵╁睍涓嶆敮鎸MySQL 4.1.1鍜屾洿楂樼増涓殑閴村畾鍗忚銆傛棤璁轰娇鐢ㄧ殑PHP鐗堟湰鏄粈涔堬紝瀹冨潎鏄纭殑銆傚鏋滀綘鎵撶畻涓MySQL 4.1鎴栨洿楂樼増鏈竴璧蜂娇鐢mysql鎵╁睍锛岄渶瑕佷娇鐢ㄥ墠闈粙缁嶇殑閫夐」涔嬩竴锛岄厤缃MySQL锛屼互渚夸笌杈冩棭鐨勫鎴风涓璧蜂娇鐢ㄣmysqli鎵╁睍锛堟敮鎸鈥鏀硅繘鐨MySQL鈥锛屽湪PHP 5涓鍔狅級涓MySQL 4.1鍜屾洿楂樼増鏈腑浣跨敤鐨勬敼杩涚殑瀵嗙爜娣风紪绠楁硶鍏煎锛屼笉闇瑕佸MySQL杩涜鐗规畩閰嶇疆灏辫兘浣跨敤璇MySQL瀹㈡埛绔簱銆傚叧浜mysqli鎵╁睍鐨勬洿澶氫俊鎭紝璇峰弬瑙http://php.net/mysqli銆
鍏充簬瀵嗙爜娣风紪鍜岄壌瀹氬姛鑳界殑棰濆鑳屾櫙鐭ヨ瘑锛岃鍙傝5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥銆
shell> mysql -u user_name -p
Enter password:
鍦ㄦ煇浜涚郴缁熶笂锛屽綋浣犲湪閫夐」鏂囦欢鎴栧懡浠よ涓婃寚瀹氭椂锛屼綘鍙兘浼氬彂鐜板瘑鐮佽兘澶熷伐浣滐紝浣嗘槸褰撲綘鍦ㄢEnter password:鈥濇彁绀轰笅浠ヤ氦浜掓柟寮忚緭鍏ュ瘑鐮佹椂锛屼綘鍙兘浼氬彂鐜拌緭鍏ョ殑瀵嗙爜涓嶅伐浣溿傚綋绯荤粺鎵鎻愪緵鐨勭敤浜庤鍙栧瘑鐮佺殑搴撳皢瀵嗙爜鍊奸檺瀹氬湪灏戞暟瀛楃鏃讹紙鍏稿瀷鎯呭喌涓嬩负8涓級锛屽氨浼氬嚭鐜拌闂銆傝繖鏄笌绯荤粺搴撴湁鍏崇殑闂锛屼笌MySQL鏃犲叧銆傝鎯冲鐞嗚闂锛屽彲灏MySQL瀵嗙爜鏇存敼涓虹敱8涓瓧绗︽垨鏇村皯瀛楃鏋勬垚鐨勫硷紝鎴栧皢瀵嗙爜缃簬閫夐」鏂囦欢涓
濡傛灉閬囧埌涓嬭堪閿欒锛岃〃绀mysqld宸叉敹鍒版潵鏉ヨ嚜涓绘満鈥host_name鈥濈殑寰堝杩炴帴璇锋眰锛屼絾璇ヤ富鏈哄嵈鍦ㄤ腑閫斾腑鏂
鐢变簬鍑虹幇寰堝杩炴帴閿欒锛屼富鏈'host_name'琚睆钄姐
鍙娇鐢'mysqladmin flush-hosts'瑙i櫎灞忚斀銆
鍏佽鐨勪腑鏂繛鎺ヨ姹傜殑鏁扮洰鐢max_connect_errors绯荤粺鍙橀噺鐨勫煎喅瀹氥褰撹秴鍑max_connect_errors瑙勫畾鐨勮繛鎺ヨ姹傛椂锛mysqld灏嗚涓烘煇澶勫嚭閿欙紙渚嬪锛屾煇浜烘璇曞浘鎻掑叆锛夛紝骞跺睆钄戒富鏈虹殑杩涗竴姝ヨ繛鎺ヨ姹傦紝鐩磋嚦鎵ц浜mysqladmin flush-hosts鍛戒护锛屾垨鍙戝嚭浜FLUSH HOSTS璇彞涓烘銆傝鍙傝5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆
鍦ㄩ粯璁ゆ儏鍐典笅锛mysqld浼氬湪10娆¤繛鎺ラ敊璇悗灞忚斀涓绘満銆備綘鍙互閫氳繃涓嬭堪鏂瑰紡鍚姩鏈嶅姟鍣ㄦ潵璋冩暣璇ュ硷細
shell> mysqld_safe --max_connect_errors=10000 &
濡傛灉鍦ㄧ粰瀹氫富鏈轰笂閬囧埌璇ラ敊璇紝棣栧厛搴旀牳瀹炶涓绘満鐨TCP/IP杩炴帴鏄惁姝g‘銆傚鏋滃瓨鍦ㄧ綉缁滈棶棰橈紝澧炲姞max_connect_errors鍙橀噺鐨勫间笉浼氭湁浠讳綍濂藉銆
褰撲綘璇曞浘杩炴帴鍒mysqld鏈嶅姟鍣ㄦ椂閬囧埌鈥滆繃澶氳繛鎺モ濋敊璇紝杩欒〃绀烘墍鏈夊彲鐢ㄧ殑杩炴帴鍧囧凡琚叾浠栧鎴风浣跨敤銆
鍏佽鐨勮繛鎺ユ暟鐢max_connections绯荤粺鍙橀噺鎺у埗銆榛樿鍊间负100銆傚鏋滈渶瑕佹敮鎸佹洿澶氱殑杩炴帴锛屽簲浣跨敤璇ュ彉閲忕殑杈冨ぇ鍊奸噸鍚mysqld銆
mysqld瀹為檯涓婂厑璁max_connections+1涓鎴风杩涜杩炴帴銆棰濆鐨勮繛鎺ヤ繚鐣欑粰鍏锋湁SUPER鏉冮檺鐨勮处鎴枫傞氳繃涓虹郴缁熺鐞嗗憳鑰屼笉鏄櫘閫氱敤鎴锋巿浜SUPER鏉冮檺锛堟櫘閫氱敤鎴蜂笉搴斿叿鏈夎鏉冮檺锛夛紝绯荤粺绠$悊鍛樿兘澶熻繛鎺ュ埌鏈嶅姟鍣紝骞朵娇鐢SHOW PROCESSLIST鏉ヨ瘖鏂棶棰橈紝鍗充娇宸茶繛鎺ョ殑鏃犵壒鏉冨鎴风鏁板凡杈惧埌鏈澶у间篃鍚屾牱銆璇峰弬瑙13.5.4.16鑺傦紝鈥淪HOW PROCESSLIST璇硶鈥銆
MySQL鑳芥敮鎸佺殑鏈澶ц繛鎺ユ暟鍙栧喅浜庣粰瀹氬钩鍙颁笂绾跨▼搴撶殑璐ㄩ噺銆Linux鎴Solaris搴旇兘鏀寔500-1000涓苟鍙戣繛鎺ワ紝鍏蜂綋鎯呭喌鍙栧喅浜RAM瀹归噺锛屼互鍙婂鎴风姝e湪浣滀粈涔堛MySQL AB鎻愪緵鐨勯潤鎬Linux搴撹兘鏀寔楂樿揪4000涓繛鎺ャ
濡傛灉浣跨敤mysql瀹㈡埛绔▼搴忓彂鍑轰簡鏌ヨ锛屽苟鏀跺埌涓嬭堪閿欒涔嬩竴锛屽垯琛ㄧずmysql娌℃湁瓒冲鍐呭瓨鏉ヤ繚瀛樺叏閮ㄦ煡璇㈢粨鏋滐細
mysql: Out of memory at line 42, 'malloc.c'
mysql: needed 8136 byte (8k), memory in use: 12481367 bytes (12189k)
閿欒2008: MySQL client ran out of memory
瑕佹兂鏇存璇ラ棶棰橈紝棣栧厛搴旀鏌ユ煡璇㈡槸鍚︽纭傝繑鍥炶繖涔堝琛屾槸鍚﹀悎鐞嗭紵濡傛灉涓嶅悎鐞嗭紝鏇存鏌ヨ骞跺啀娆″皾璇曘傚惁鍒欙紝搴斾娇鐢ㄢ--quick鈥濋夐」璋冪敤mysql銆傝繖鏍凤紝灏嗕娇鐢mysql_use_result() C API鍑芥暟鏉ユ绱㈢粨鏋滈泦锛岃繖绫诲嚱鏁拌兘澶熼檷浣庡鎴风涓婄殑璐熻浇锛堜絾浼氬姞閲嶆湇鍔″櫒涓婄殑璐熻浇锛夈
鍦ㄦ湰鑺備腑锛岃繕浠嬬粛浜嗗嚭鐜版煡璇㈤敊璇湡闂达紝涓庝涪澶变簡鏈嶅姟鍣ㄨ繛鎺ユ湁鍏崇殑浜嬪疁銆
MySQL鏈嶅姟鍣ㄤ笉鍙敤閿欒鐨勬渶甯歌鍘熷洜鏄湇鍔″櫒瓒呮椂浠ュ強杩炴帴宸插叧闂傚湪璇ユ儏鍐典笅锛岄氬父鑳借鍒颁笅杩伴敊璇唬鐮佷箣涓锛堝叿浣撶殑閿欒浠g爜涓庢搷浣滅郴缁熸湁鍏筹級锛
閿欒浠g爜 |
鎻忚堪 |
CR_SERVER_GONE_ERROR |
瀹㈡埛绔棤娉曞皢闂鍙戦佽嚦鏈嶅姟鍣ㄣ |
CR_SERVER_LOST |
鍐欏叆鏈嶅姟鍣ㄦ椂瀹㈡埛绔湭鏀跺埌閿欒锛屼絾涔熸湭鑾峰緱闂鐨勫畬鏁寸瓟妗堬紙鎴栦换浣曠瓟妗堬級銆 |
鍦ㄩ粯璁ゆ儏鍐典笅锛屽鏋滄湭鍙戠敓浠讳綍浜嬶紝8灏忔椂鍚庢湇鍔″櫒灏嗗叧闂繛鎺ャ備篃鍙互鍦ㄥ惎鍔mysqld鏃讹紝閫氳繃璁剧疆wait_timeout鍙橀噺鏇存敼鏃堕棿闄愬埗銆傝鍙傝5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥.
濡傛灉鏈1涓剼鏈紝浣犱粎闇瑕佸啀娆″彂鍑烘煡璇紝璁╁鎴风鍐嶆杩涜鑷姩杩炴帴鍗冲彲銆傚叾涓紝鍋囧畾鍦ㄥ鎴风涓惎鐢ㄤ簡鑷姩鍐嶈繛鎺ュ姛鑳斤紙瀵逛簬mysql鍛戒护琛屽鎴风锛岃繖鏄粯璁よ缃級銆
MySQL鏈嶅姟鍣ㄤ笉鍙敤閿欒鐨勪竴浜涘叾浠栧父瑙佸師鍥犲涓嬶細
路 浣狅紙鎴db绯荤粺绠$悊鍛橈級浣跨敤KILL璇彞鎴mysqladmin kill鍛戒护鏉姝讳簡姝e湪杩愯鐨勭嚎绋嬨
路 浣犺瘯鍥惧湪鍏抽棴浜嗕笌鏈嶅姟鍣ㄧ殑杩炴帴鍚庤繍琛屾煡璇€傝繖琛ㄦ槑搴旀洿姝e簲鐢ㄧ▼搴忎腑鐨勯昏緫閿欒銆
路 浣犲湪瀹㈡埛绔竴渚ч亣鍒TCP/IP杩炴帴瓒呮椂閿欒銆傚鏋滀綘浣跨敤浜嗗懡浠わ細mysql_options(..., MYSQL_OPT_READ_TIMEOUT,...)鎴mysql_options(..., MYSQL_OPT_WRITE_TIMEOUT,...)锛屽氨鍙兘鍑虹幇璇ラ棶棰樸鍦ㄨ鎯呭喌涓嬶紝澧炲姞瓒呮椂鍊煎彲鑳芥湁鍔╀簬闂鐨勮В鍐炽
路 浣犲湪鏈嶅姟鍣ㄧ閬囧埌瓒呮椂閿欒锛岃屼笖绂佹浜嗗鎴风涓殑鑷姩鍐嶈繛鎺ュ姛鑳斤紙MYSQL缁撴瀯涓殑鍐嶈繛鎺ユ爣蹇楃瓑浜0锛夈
路 浣犳鍦ㄤ娇鐢Windows瀹㈡埛绔紝鑰屼笖鍦ㄥ彂鍑哄懡浠や箣鍓嶆湇鍔″櫒鎾ら攢浜嗚繛鎺ワ紙鎴栬鏄洜涓哄凡瓒呰繃wait_timeout锛銆
鍦Windows骞冲彴涓婂嚭鐜伴棶棰樼殑鍘熷洜锛屽湪鏌愪簺鎯呭喌涓嬶紝灏TCP/IP杩炴帴鍐欏叆鏈嶅姟鍣ㄦ椂锛MySQL鏈敹鍒版潵鑷搷浣滅郴缁熺殑閿欒锛屼絾褰撹瘯鍥句粠杩炴帴璇诲彇绛旀鏃跺嚭鐜伴敊璇
鍦ㄨ鎯呭喌涓嬶紝鍗充娇MYSQL缁撴瀯涓殑鍐嶈繛鎺ユ爣蹇楃瓑浜1锛MySQL涔熶笉浼氭墽琛岃嚜鍔ㄥ啀杩炴帴骞跺啀娆″彂鍑烘煡璇紝杩欐槸鍥犱负瀹冧笉鐭ラ亾鏈嶅姟鍣ㄦ槸鍚︽敹鍒板師濮嬫煡璇€
瀵规鐨勮В鍐虫柟寮忔槸锛氬鏋滆嚜涓婁竴娆℃煡璇互鏉ョ粡杩囦簡杈冮暱鏃堕棿锛屽湪杩炴帴涓婃墽琛mysql_ping锛堟鏄MyODBC鎵浣滅殑锛夛紱鎴栧湪mysqld鏈嶅姟鍣ㄤ笂灏wait_timeout璁剧疆寰楀緢楂橈紝浣夸箣瀹為檯涓婁笉瀛樺湪瓒呮椂銆
路 濡傛灉浣犲悜鏈嶅姟鍣ㄥ彂鍑轰簡涓嶆纭垨杩囧ぇ鐨勬煡璇紝涔熶細閬囧埌杩欑被闂銆傚鏋mysqld鏀跺埌杩囧ぇ鎴栨棤搴忕殑淇℃伅鍖咃紝瀹冧細璁や负瀹㈡埛绔嚭閿欙紝骞跺叧闂繛鎺ャ傚鏋滈渶瑕佹墽琛岃緝澶х殑鏌ヨ锛堜緥濡傦紝姝e湪澶勭悊澶х殑BLOB鍒楋級锛鍙氳繃璁剧疆鏈嶅姟鍣ㄧ殑max_allowed_packet鍙橀噺锛屽鍔犳煡璇㈤檺鍒跺硷紝璇ュ彉閲忕殑榛樿鍊间负1MB銆傛垨璁革紝浣犺繕闇澧炲姞瀹㈡埛绔笂鐨勬渶澶т俊鎭寘澶у皬銆傚叧浜庤缃俊鎭寘澶у皬鐨勬洿澶氫俊鎭紝璇峰弬瑙A.2.9鑺傦紝鈥滀俊鎭寘杩囧ぇ鈥銆
路 濡傛灉浣犵殑瀹㈡埛绔綆浜4.0.8鑰屼笖浣犵殑鏈嶅姟鍣ㄩ珮浜4.0.8锛屽綋浣犳帴鏀16MB鎴栨洿澶х殑淇℃伅鍖呮椂锛屽彲鑳戒細涓㈠け杩炴帴銆
路 濡傛灉MySQL鏄敤鈥--skip-networking鈥濋夐」鍚姩鐨勶紝涔熶細瑙佸埌MySQL鏈嶅姟鍣ㄤ笉鍙敤閿欒銆
路 浣犻亣鍒颁簡鎵ц鏌ヨ鏃舵湇鍔″櫒瀹曟満鐨勭己闄枫
閫氳繃鎵цmysqladmin version骞舵鏌ユ湇鍔″櫒鐨勬甯稿伐浣滄椂闂达紝鍙鏌ユ湇鍔″櫒鏄惁瀹曟満骞堕噸鍚傚鏋滃鎴风杩炴帴鏄洜mysqld宕╂簝鍜岄噸鍚屾柇寮鐨勶紝搴斿皢閲嶇偣鏀惧湪鏌ユ壘宕╂簝浣犳柟闈€傞鍏堝簲鍐嶆妫鏌ュ彂鍑虹殑鏌ヨ鏄惁鍐嶆鏉姝讳簡鏈嶅姟鍣ㄣ傝鍙傝A.4.2鑺傦紝鈥滃鏋淢ySQL渚濈劧宕╂簝锛屽簲浣滀簺浠涔堚銆
鐢ㄢ--log-warnings=2鈥閫夐」鍚姩mysqld锛屽彲鑾峰緱鍏充簬杩炴帴鐨勬洿澶氫俊鎭傝繖鏍凤紝灏辫兘灏嗘煇浜涙柇寮杩炴帴閿欒璁板綍鍒hostname.err鏂囦欢涓銆傝鍙傝5.11.1鑺傦紝鈥滈敊璇棩蹇椻銆
濡傛灉浣犳墦绠楀垱寤轰笌璇ラ棶棰樻湁鍏崇殑缂洪櫡鎶ュ憡锛屽姟蹇呭寘鍚笅杩颁俊鎭細
1. 鎸囨槑MySQL鏈嶅姟鍣ㄦ槸鍚﹀畷鏈恒傞氳繃鏈嶅姟鍣ㄩ敊璇棩蹇楀彲鍙戠幇杩欐柟闈㈢殑淇℃伅銆傝鍙傝A.4.2鑺傦紝鈥滃鏋淢ySQL渚濈劧宕╂簝锛屽簲浣滀簺浠涔堚銆
2. 濡傛灉鐗瑰畾鏌ヨ鏉姝讳簡mysqld锛岃屼笖鍦ㄨ繍琛屾煡璇㈠墠鐢CHECK TABLE妫鏌ヤ簡娑夊強鐨勮〃锛屼綘鏄惁鑳芥彁渚涘彲閲嶅鐨勬祴璇曡寖渚嬶紵璇峰弬瑙E.1.6鑺傦紝鈥滃鏋滃嚭鐜拌〃宕╂簝锛岃鐢熸垚娴嬭瘯妗堜緥鈥銆
3. 鍦MySQL鏈嶅姟鍣ㄤ腑锛岀郴缁熷彉閲wait_timeout鐨勫兼槸浠涔堬紵锛mysqladmin variables缁欏嚭浜嗚鍙橀噺鐨勫硷級銆
4. 浣犳槸鍚﹀皾璇曚娇鐢ㄢ--log鈥濋夐」鏉ヨ繍琛mysqld锛屼互纭畾鏄惁鍦ㄦ棩蹇椾腑鍑虹幇闂锛
鍙﹁鍙傝A.2.10鑺傦紝鈥滈氫俊閿欒鍜屽け鏁堣繛鎺モ銆
閫氫俊淇℃伅鍖呮槸鍙戦佽嚦MySQL鏈嶅姟鍣ㄧ殑鍗曚釜SQL璇彞锛屾垨鍙戦佽嚦瀹㈡埛绔殑鍗曚竴琛屻
鍦MySQL 5.1鏈嶅姟鍣ㄥ拰瀹㈡埛绔箣闂存渶澶ц兘鍙戦佺殑鍙兘淇℃伅鍖呬负1GB銆
褰MySQL瀹㈡埛绔垨mysqld鏈嶅姟鍣ㄦ敹鍒板ぇ浜max_allowed_packet瀛楄妭鐨勪俊鎭寘鏃讹紝灏嗗彂鍑鈥淇℃伅鍖呰繃澶鈥閿欒锛屽苟鍏抽棴杩炴帴銆傚浜庢煇浜涘鎴风锛屽鏋滈氫俊淇℃伅鍖呰繃澶э紝鍦ㄦ墽琛屾煡璇㈡湡闂达紝浜嗚兘鍥為亣鍒鈥涓㈠け涓MySQL鏈嶅姟鍣ㄧ殑杩炴帴鈥閿欒銆
瀹㈡埛绔拰鏈嶅姟鍣ㄥ潎鏈夎嚜宸辩殑max_allowed_packet鍙橀噺锛鍥犳锛屽浣犳墦绠楀鐞嗗ぇ鐨勪俊鎭寘锛屽繀椤诲鍔犲鎴风鍜屾湇鍔″櫒涓婄殑璇ュ彉閲忋
濡傛灉浣犳鍦ㄤ娇鐢mysql瀹㈡埛绔▼搴忥紝鍏max_allowed_packet鍙橀噺鐨勯粯璁ゅ间负16MB銆傝鎯宠缃緝澶х殑鍊硷紝鍙敤涓嬭堪鏂瑰紡鍚姩mysql锛
mysql> mysql --max_allowed_packet=32M
瀹冨皢淇℃伅鍖呯殑澶у皬璁剧疆涓32MB銆
鏈嶅姟鍣ㄧ殑榛樿max_allowed_packet鍊间负1MB銆傚鏋滄湇鍔″櫒闇瑕佸鐞嗗ぇ鐨勬煡璇紝鍙鍔犺鍊硷紙渚嬪锛屽鏋滃噯澶囧鐞嗗ぇ鐨BLOB鍒楋級銆備緥濡傦紝瑕佹兂灏嗚璁剧疆涓16MB锛屽彲閲囩敤涓嬭堪鏂瑰紡鍚姩鏈嶅姟鍣細
mysql> mysqld --max_allowed_packet=16M
涔熻兘浣跨敤閫夐」鏂囦欢鏉ヨ缃max_allowed_packet銆瑕佹兂灏嗘湇鍔″櫒鐨勮鍙橀噺璁剧疆涓16MB锛屽彲鍦ㄩ夐」鏂囦欢涓鍔犱笅琛屽唴瀹癸細
[mysqld]
max_allowed_packet=16M
澧炲姞璇ュ彉閲忕殑鍊煎崄鍒嗗畨鍏紝杩欐槸鍥犱负浠呭綋闇瑕佹椂鎵嶄細鍒嗛厤棰濆鍐呭瓨銆備緥濡傦紝浠呭綋浣犲彂鍑洪暱鏌ヨ鎴mysqld蹇呴』杩斿洖澶х殑缁撴灉琛屾椂mysqld鎵嶄細鍒嗛厤鏇村鍐呭瓨銆傝鍙橀噺涔嬫墍浠ュ彇杈冨皬榛樿鍊兼槸涓绉嶉闃叉帾鏂斤紝浠ユ崟鑾峰鎴风鍜屾湇鍔″櫒涔嬮棿鐨勯敊璇俊鎭寘锛屽苟纭繚涓嶄細鍥犲伓鐒朵娇鐢ㄥぇ鐨勪俊鎭寘鑰屽鑷村唴瀛樻孩鍑恒
濡傛灉浣犳鏄敤澶х殑BLOB鍊硷紝鑰屼笖鏈负mysqld鎺堜簣涓哄鐞嗘煡璇㈣岃闂冻澶熷唴瀛樼殑鏉冮檺锛屼篃浼氶亣鍒颁笌澶т俊鎭寘鏈夊叧鐨勫鎬棶棰樸傚鏋滄鐤戝嚭鐜颁簡璇ユ儏鍐碉紝璇峰皾璇曞湪mysqld_safe鑴氭湰寮濮嬪鍔ulimit -d 256000锛屽苟閲嶅惎mysqld銆
瀵逛簬杩炴帴闂锛屾湇鍔″櫒閿欒鏃ュ織鏄湁鐢ㄧ殑淇℃伅婧愩傝鍙傝5.11.1鑺傦紝鈥滈敊璇棩蹇椻銆傚鏋滄湇鍔″櫒鏄敤鈥--log-warnings鈥濋夐」鍚姩鐨勶紝鍦ㄩ敊璇棩蹇椾腑鍙兘浼氬彂鐜颁笅杩版秷鎭細
010301 14:38:23 Aborted connection 854 to db: 'users' user: 'josh'
濡傛灉鈥Aborted connections鈥锛堟斁寮冭繛鎺ワ級娑堟伅鍑虹幇鍦ㄩ敊璇棩蹇椾腑锛屽彲鑳界殑鍘熷洜鏄細
1. 瀹㈡埛绔▼搴忓湪閫鍑轰箣鍓嶆湭璋冪敤mysql_close()銆
2. 瀹㈡埛绔殑绌洪棽鏃堕棿瓒呰繃wait_timeout鎴interactive_timeout绉掞紝鏈悜鏈嶅姟鍣ㄥ彂鍑轰换浣曡姹傘璇峰弬瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆
3. 瀹㈡埛绔湪鏁版嵁浼犺緭涓旂獊鐒剁粨鏉熴
鍑虹幇杩欑被鎯呭喌鏃讹紝鏈嶅姟鍣ㄥ皢澧炲姞鈥Aborted_clients鈥锛堟斁寮冨鎴风锛夌姸鎬佸彉閲忋
鍑虹幇涓嬭堪鎯呭喌鏃讹紝鏈嶅姟鍣ㄥ皢澧炲姞鈥Aborted_clients鈥锛堟斁寮冨鎴风锛夌姸鎬佸彉閲忋
路 瀹㈡埛绔笉鍏锋湁杩炴帴鑷虫暟鎹簱鐨勬潈闄愩
路 瀹㈡埛绔噰鐢ㄤ簡涓嶆纭殑瀵嗙爜銆
路 杩炴帴淇℃伅鍖呬笉鍚纭俊鎭
路 鑾峰彇杩炴帴淇℃伅鍖呯殑鏃堕棿瓒呰繃connect_timeout绉掋璇峰弬瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆
濡傛灉鍑虹幇杩欑被鎯呭喌锛屽彲鑳借〃鏄庢煇浜烘璇曞浘渚靛叆浣犵殑鏈嶅姟鍣紒
瀵逛簬鏀惧純瀹㈡埛绔垨鏀惧純杩炴帴闂锛屽叾浠栧彲鑳界殑婧愬簲鍖呮嫭锛
路 涓Linux涓璧蜂娇鐢ㄤ互澶綉鍗忚锛屽崐鍙屽伐鎴栧叏鍙屽伐銆傚緢澶Linux浠ュお缃戦┍鍔ㄥ潎瀛樺湪璇ョ己闄枫傚簲閫氳繃FTP鍦ㄥ鎴风鍜屾湇鍔″櫒鏈哄櫒涔嬮棿浼犺緭澶ф枃浠舵潵娴嬭瘯璇ョ己闄枫傚鏋滀紶杈撳浜burst-pause-burst-pause锛堢垎鍙-鏆傚仠-鐖嗗彂-鏆傚仠锛夋ā寮忥紝琛ㄦ槑浣犻亣鍒颁簡Linux鍙屽伐鏁呴殰銆傚敮涓鐨勮В鍐虫柟娉曟槸锛屽皢缃戝崱鍜Hub/浜ゆ崲鍣ㄧ殑鍙屽伐妯″紡鍒囨崲涓哄叏鍙屽伐鎴栧崐鍙屽伐锛屽苟瀵圭粨鏋滆繘琛屾祴璇曚互纭畾鏈浣宠缃
路 涓庣嚎绋嬪簱鏈夊叧鐨勬煇浜涢棶棰樺鑷磋鍙栦腑鏂
路 閰嶇疆涓嶈壇鐨TCP/IP銆
路 鏈夐棶棰樼殑浠ュお缃戙Hub銆佷氦鎹㈠櫒銆佺數缂嗙瓑銆備粎鑳介氳繃鏇存崲纭欢鎵嶈兘鎭板綋璇婃柇銆
路 鍙橀噺max_allowed_packet杩囧皬鎴鏌ヨ瑕佹眰鐨勫唴瀛樿秴杩囦负mysqld鍒嗛厤鐨勫唴瀛樸傝鍙傝A.2.9鑺傦紝鈥滀俊鎭寘杩囧ぇ鈥銆
鍙﹁鍙傝A.2.8鑺傦紝鈥淢ySQL鏈嶅姟鍣ㄤ笉鍙敤鈥銆
琛ㄥ凡婊¢敊璇嚭鐜扮殑鏂瑰紡鏈夋暟绉嶏細
路 浣犳鍦ㄤ娇鐢ㄤ綆浜3.23鐗堢殑MySQL鏈嶅姟鍣紝鑰屼笖鈥滃唴瀛樹腑鈥濅复鏃惰〃瓒呰繃浜tmp_table_size瀛楄妭銆瑕佹兂閬垮厤璇ラ棶棰橈紝鍙娇鐢ㄢ-O tmp_table_size=val鈥濋夐」浠ヤ究mysqld澧炲姞涓存椂琛ㄧ殑澶у皬锛屾垨鍦ㄥ彂鍑烘湁闂鐨勬煡璇箣鍓嶏紝浣跨敤SQL閫夐」SQL_BIG_TABLES銆璇峰弬瑙13.5.3鑺傦紝鈥淪ET璇硶鈥銆
涔熷彲浠ヤ娇鐢ㄢ--big-tables鈥濋夐」鍚姩mysqld銆傚畠涓庝娇鐢ㄩ拡瀵规墍鏈夋煡璇㈢殑SQL_BIG_TABLES瀹屽叏鐩稿悓銆
鑷MySQL 3.23璧凤紝璇ラ棶棰樺簲涓嶅啀鍑虹幇銆傚鏋溾滃唴瀛樹腑鈥濅复鏃惰〃瓒呰繃tmp_table_size锛屾湇鍔″櫒浼氳嚜鍔ㄥ皢鍏惰浆鎹负鍩轰簬纾佺洏鐨MyISAM琛ㄣ
路
浣犳鍦ㄤ娇鐢InnoDB琛紝骞惰秴鍑轰簡InnoDB琛ㄧ┖闂淬鍦ㄨ鎯呭喌涓嬶紝瑙e喅鏂规硶鏄鍔InnoDB琛ㄧ┖闂淬傝鍙傝15.2.7鑺傦紝鈥滄坊鍔犲拰鍒犻櫎InnoDB鏁版嵁鍜屾棩蹇楁枃浠鈥銆
路 浣犳鍦ㄤ粎鏀寔2GB鏂囦欢鐨勬搷浣滅郴缁熶笂浣跨敤ISAM鎴MyISAM琛紝鏁版嵁鏂囦欢鎴栫储寮曟枃浠惰揪鍒颁簡璇ラ檺鍒跺笺
路 浣犳鍦ㄤ娇鐢MyISAM琛紝鑰屼笖琛ㄦ墍闇鐨勭┖闂磋秴杩囧唴閮ㄦ寚閽堝厑璁哥殑澶у皬銆傚鏋滃湪鍒涘缓琛ㄦ椂鏈寚瀹MAX_ROWS琛紝MySQL灏嗕娇鐢myisam_data_pointer_size绯荤粺鍙橀噺銆榛樿鍊间负6瀛楄妭锛屽畠瓒充互瀹圭撼65536TB鏁版嵁銆傝鍙傝5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆
浣跨敤璇ヨ鍙ワ紝鍙鏌ユ渶澶ф暟鎹/绱㈠紩澶у皬锛
SHOW TABLE STATUS FROM database LIKE 'tbl_name';
涔熷彲浠ヤ娇鐢myisamchk -dv /path/to/table-index-file銆
濡傛灉鎸囬拡澶у皬杩囧皬锛屽彲浣跨敤ALTER TABLE鏇存璇ラ棶棰橈細
ALTER TABLE tbl_name MAX_ROWS=1000000000 AVG_ROW_LENGTH=nnn;
浠呭簲涓哄叿鏈BLOB鎴TEXT鍒楃殑琛ㄦ寚瀹AVG_ROW_LENGTH銆鍦ㄨ鎯呭喌涓嬶紝MySQL涓嶈兘浠呮牴鎹鏁颁紭鍖栨墍闇鐨勭┖闂淬
濡傛灉瀵规煇浜涙煡璇㈤亣鍒颁笅杩扮被鍨嬬殑閿欒锛屽畠鎰忓懗鐫MySQL涓嶈兘涓轰复鏃剁洰褰曚笅鐨勭粨鏋滈泦鍒涘缓涓存椂鏂囦欢锛
鏃犳硶鍒涘缓/鍐欏叆鏂囦欢'\\sqla3fe_0.ism'銆
鍓嶈堪閿欒鏄Windows骞冲彴涓婄殑鍏稿瀷娑堟伅锛Unix骞冲彴涓婄殑娑堟伅涓庝箣绫讳技銆
涓绉嶆洿姝f柟寮忔槸浣跨敤鈥--tmpdir鈥濋夐」鍚姩mysqld锛屾垨鍦ㄩ夐」鏂囦欢鐨[mysqld]閮ㄥ垎澧炲姞璇ラ夐」銆渚嬪锛岃鎯虫寚瀹氱洰褰C:\temp锛屽彲浣跨敤锛
[mysqld]
tmpdir=C:/temp
鐩綍C:\temp蹇呴』瀛樺湪锛骞舵湁瓒冲鐨勭┖闂村厑璁MySQL鍐欏叆瀹冦傝鍙傝4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥銆
璇ラ敊璇殑鍙︿竴涓師鍥犲彲鑳芥槸璁稿彲浜嬪疁銆傝纭MySQL鏈嶅姟鍣ㄨ兘澶熷啓鍏tmpdir鐩綍銆
姝ゅ锛岃繕鐢ㄤ娇鐢perror妫鏌ラ敊璇唬鐮併傛湇鍔″櫒鏃犳硶鍐欏叆琛ㄧ殑涓涓師鍥犳槸鏂囦欢绯荤粺宸叉弧銆
shell> perror 28
閿欒浠g爜28锛氱鐩樹笂鏃犲墿浣欑┖闂淬
濡傛灉閬囧埌涓嬭堪閿欒锛岃〃绀哄綋鍚姩mysqld鏃舵垨閲嶆柊鍔犺浇鎺堟潈琛ㄦ椂锛屽湪鐢ㄦ埛琛ㄤ腑鍙戠幇鍏锋湁闈炴硶瀵嗙爜鐨勮处鎴枫
鍙戠幇鐢ㄦ埛'some_user'@'some_host'瀵嗙爜閿欒锛氬拷鐣ョ敤鎴枫
浣滀负鍏剁粨鏋滐紝璁稿彲绯荤粺灏嗙畝鍗曞拷鐣ヨ处鎴枫
鍦ㄤ笅闈㈢殑浠嬬粛涓紝鎸囨槑浜嗗彲鑳界殑鍘熷洜鍜岄棶棰樼殑鏇存鎺柦锛
1. 鎴栬锛屼綘姝f墦绠楃敤鏃х殑鐢ㄦ埛琛ㄨ繍琛屾柊鐗堟湰鐨mysqld銆傛墽琛mysqlshow mysql user妫鏌Password锛堝瘑鐮侊級鍒楁槸鍚︾煭浜16涓瓧绗︼紝閫氳繃璇ユ柟寮忓彲妫鏌ヨ闂銆傚鏋滅粨鏋滄槸鑲畾鐨勶紝鍙繍琛岃剼鏈/add_long_password鑴氭湰鏇存璇ラ棶棰樸
2. 璐︽埛鍏锋湁鏃х殑瀵嗙爜锛8瀛楃闀匡級锛岃屼笖鏈娇鐢ㄢ--old-protocol鈥濋夐」鍚姩mysqld銆傛洿鏂扮敤鎴疯〃涓殑璐︽埛锛屼娇涔嬪叿鏈夋柊鐨勫瘑鐮侊紝鎴栦娇鐢ㄢ--old-protocol鈥濋夐」閲嶅惎mysqld銆
3. 鍦ㄧ敤鎴疯〃涓湭浣跨敤PASSWORD()鍑芥暟鎸囧畾浜嗗瘑鐮併浣跨敤mysql鐢ㄦ柊瀵嗙爜鏇存柊鐢ㄦ埛琛ㄤ腑鐨勮处鎴凤紝鍔″繀浣跨敤PASSWORD()鍑芥暟锛
4. mysql> UPDATE user SET Password=PASSWORD('newpwd')
5. -> WHERE User='some_user' AND Host='some_host';
濡傛灉閬囧埌涓嬭堪閿欒涔嬩竴锛岄氬父鎰忓懗鐫褰撳墠鏁版嵁搴撲腑涓嶅瓨鍦ㄥ叿鏈夌粰瀹氬悕绉扮殑琛細
琛'tbl_name'涓嶅瓨鍦
鏃犳硶鎵惧埌鏂囦欢锛'tbl_name' (errno: 2)
鍦ㄦ煇浜涙儏鍐典笅锛岃〃鎴栬瀛樺湪锛屼絾鏈纭紩鐢ㄥ畠锛
路 鐢变簬MySQL浣跨敤鐩綍鍜屾枃浠舵潵淇濆瓨鏁版嵁搴撳拰琛紝濡傛灉瀹冧滑浣嶄簬鍖哄垎鏂囦欢鍚嶅ぇ灏忓啓鐨勬枃浠剁郴缁熶笂锛屾暟鎹簱鍜岃〃鍚嶄篃鍖哄垎鏂囦欢澶у皬鍐欍
路 鍗充娇瀵逛簬涓嶅尯鍒嗗ぇ灏忓啓鐨勬枃浠剁郴缁燂紝濡Windows锛屽湪鏌ヨ鍐呭缁欏畾琛ㄧ殑鎵鏈夊紩鐢ㄥ繀椤讳娇鐢ㄧ浉鍚岀殑澶у皬鍐欍
鍙互浣跨敤SHOW TABLES妫鏌ヤ綅浜庡綋鍓嶆暟鎹簱涓殑琛銆傝鍙傝13.5.4鑺傦紝鈥淪HOW璇硶鈥銆
濡傛灉瀛樺湪瀛楃闆嗛棶棰橈紝鍙兘浼氶亣鍒颁笅杩伴敊璇細
MySQL杩炴帴澶辫触锛氭棤娉曞垵濮嬪寲瀛楃闆charset_name銆
瀵艰嚧璇ラ敊璇殑鍘熷洜锛
路 瀛楃闆嗕负澶氬瓧鑺傚瓧绗﹂泦锛屼絾瀹㈡埛绔笉鏀寔璇ュ瓧绗﹂泦銆傚湪璇ユ儏鍐典笅锛岄渶瑕佷娇鐢ㄢ--with-charset=charset_name鈥濇垨鈥--with-extra-charsets=charset_name鈥濋夐」杩愯configure浠ラ噸鏂扮紪璇戝鎴风銆傝鍙傝2.8.2鑺傦紝鈥滃吀鍨嬮厤缃夐」鈥銆
鎵鏈夌殑鏍囧噯MySQL浜岃繘鍒舵枃浠跺潎鏄噰鐢ㄢ--with-extra-character-sets=complex鈥濈紪璇戠殑锛岃兘澶熸敮鎸佹墍鏈夌殑澶氬瓧鑺傚瓧绗﹂泦銆傝鍙傝5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥銆
路 瀛楃闆嗘槸鏈紪璇戝埌mysqld涓殑绠鍗曞瓧绗﹂泦锛岃屼笖瀛楃闆嗗畾涔夋枃浠朵笉鍦ㄥ鎴风棰勬湡鐨勪綅缃
鍦ㄨ鎯呭喌涓嬶紝闇瑕侀噰鍙栦笅杩版柟娉曚箣涓瑙e喅闂锛
1. 閲嶆柊缂栬瘧瀹㈡埛绔紝浣夸箣鏀寔瀛楃闆嗐傝鍙傝2.8.2鑺傦紝鈥滃吀鍨嬮厤缃夐」鈥銆
2. 涓哄鎴风鎸囧畾瀛楃闆嗗畾涔夋枃浠舵墍鍦ㄧ殑鐩綍銆傚浜庡緢澶氬鎴风锛屽彲浣跨敤鈥--character-sets-dir鈥濋夐」瀹屾垚璇ヤ换鍔°
3. 灏嗗瓧绗﹂泦瀹氫箟鏂囦欢澶嶅埗鍒板鎴风棰勬湡鐨勪綅缃
濡傛灉閬囧埌鈥ERROR '...'鏈彂鐜(errno: 23)鈥锛鈥鏃犳硶鎵撳紑鏂囦欢锛... (errno: 24)鈥锛屾垨鏉ヨ嚜MySQL鐨勫叿鏈errno 23鎴errno 24鐨勫叾瀹冮敊璇紝瀹冭〃绀烘湭涓MySQL鏈嶅姟鍣ㄥ垎閰嶈冻澶熺殑鏂囦欢鎻忚堪绗銆備綘鍙互浣跨敤perror瀹炵敤宸ュ叿鏉ヤ簡瑙i敊璇紪鍙风殑鍚箟锛
shell> perror 23
閿欒浠g爜23锛氭枃浠惰〃婧㈠嚭
shell> perror 24
閿欒浠g爜24锛氭墦寮鏂囦欢杩囧
shell> perror 11
閿欒浠g爜11锛氳祫婧愭殏鏃朵笉鍙敤
杩欓噷鐨勯棶棰樻槸锛mysqld姝h瘯鍥惧悓鏃舵墦寮杩囧鐨勬枃浠躲備綘鍙互閫氱煡mysqld涓嶈涓娆℃墦寮杩囧鏂囦欢锛屾垨澧炲姞mysqld鍙敤鏂囦欢鎻忚堪绗︾殑鏁扮洰銆
瑕佹兂閫氱煡mysqld灏嗕竴娆℃墦寮鐨勬枃浠舵帶鍒跺湪杈冨皬鐨勬暟鐩笂锛屽彲闄嶄綆table_cache绯荤粺鍙橀噺鐨勫硷紙锛夛紝浠庤屽噺灏戣〃楂橀熺紦鍐诧紙榛樿鍊间负64锛夈傞檷浣max_connections鐨勫间篃鑳介檷浣鎵撳紑鏂囦欢鐨勬暟鐩紙榛樿鍊间负100锛夈
瑕佹兂鏇存敼mysqld鍙敤鐨勬枃浠舵弿杩扮鐨勬暟鐩紝鍙湪mysqld_safe涓婁娇鐢ㄢ--open-files-limit鈥閫夐」鎴栬缃锛堣嚜MySQL 3.23.30寮濮嬶級open_files_limit绯荤粺鍙橀噺銆傝鍙傝5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆傝缃繖浜涘肩殑鏈绠鍗曟柟寮忔槸鍦ㄩ夐」鏂囦欢涓鍔1涓夐」銆傝鍙傝4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥銆傚鏋mysqld鐨勭増鏈緝浣庯紝涓嶆敮鎸佽缃墦寮鏂囦欢鐨勬暟鐩紝鍙紪杈mysqld_safe鑴氭湰銆傚湪鑴氭湰涓湁1涓敞閲婃帀鐨勮ulimit -n 256銆備綘鍙互鍒犻櫎鈥#鈥欏瓧绗﹀彇娑堝璇ヨ鐨勬敞閲婏紝鏇存敼鏁板256锛屼互璁剧疆mysqld鍙敤鐨勬枃浠舵弿杩扮鏁扮洰銆
鈥--open-files-limit鈥鍜ulimit鑳藉澧炲姞鏂囦欢鎻忚堪绗︾殑鏁扮洰锛屼絾鏈楂樹笉鑳借秴杩囨搷浣滅郴缁熼檺鍒剁殑鏁扮洰銆傛澶栬繕鏈1涓滅‖鈥濋檺鍒讹紝浠呭綋浠ユ牴鐢ㄦ埛韬唤鍚姩mysqld_safe鎴mysqld鏃舵墠鑳借鐩栧畠锛堣璁颁綇锛屽湪璇ユ儏鍐典笅锛岃繕闇浣跨敤鈥--user鈥濋夐」鍚姩鏈嶅姟鍣紝浠ヤ究鍦ㄥ惎鍔ㄥ悗涓嶅啀浠ユ牴鐢ㄦ埛韬唤缁х画杩愯锛夈傚鏋滈渶瑕佸鍔犳搷浣滅郴缁熼檺鍒剁殑瀵瑰悇杩涚▼鍙敤鏂囦欢鎻忚堪绗︾殑鏁扮洰锛岃鍙傞槄绯荤粺鏂囨。銆
娉ㄩ噴锛濡傛灉杩愯tcsh shell锛ulimit涓嶅伐浣滐紒璇锋眰褰撳墠闄愬埗鍊兼椂锛tcsh杩樿兘閫氭姤涓嶆纭殑鍊笺傚湪璇ユ儏鍐典笅锛屽簲浣跨敤sh鍚姩mysqld_safe銆
褰撲綘閾炬帴鍒板簲鐢ㄧ▼搴忎互浣跨敤MySQL瀹㈡埛绔簱鏃讹紝鍙兘浼氶亣鍒颁互mysql_寮濮嬬殑鏈畾涔夊紩鐢ㄩ敊璇紝濡備笅鎵绀猴細
/tmp/ccFKsdPa.o: 鍦ㄥ嚱鏁`main'涓:
/tmp/ccFKsdPa.o(.text+0xb): 瀵`mysql_init'鐨勬湭瀹氫箟寮曠敤銆
/tmp/ccFKsdPa.o(.text+0x31): 瀵`mysql_real_connect'鐨勬湭瀹氫箟寮曠敤銆
/tmp/ccFKsdPa.o(.text+0x57): 瀵`mysql_real_connect'鐨勬湭瀹氫箟寮曠敤銆
/tmp/ccFKsdPa.o(.text+0x69): 瀵`mysql_error'鐨勬湭瀹氫箟寮曠敤銆
/tmp/ccFKsdPa.o(.text+0x9a): 瀵`mysql_close'鐨勬湭瀹氫箟寮曠敤銆
閫氳繃鍦ㄩ摼鎺ュ懡浠ゅ悗澧炲姞鈥-Ldir_path -lmysqlclient鈥濋夐」锛屽簲鑳借В鍐宠闂锛屽叾涓紝dir_path浠h〃瀹㈡埛绔簱鎵鍦ㄧ洰褰曠殑璺緞鍚嶃傝鎯崇‘瀹氭纭殑鐩綍锛屽彲灏濊瘯涓嬭堪鍛戒护锛
shell> mysql_config --libs
鏉ヨ嚜mysql_config鐨勮緭鍑哄彲鑳戒細鎸囨槑搴斿湪閾炬帴鍛戒护涓婃寚瀹氱殑鍏朵粬搴撱
瀵逛簬闈炲帇缂╂垨鍘嬬缉鍑芥暟锛屽鏋滈亣鍒版湭瀹氫箟寮曠敤閿欒锛屽彲鍦ㄩ摼鎺ュ懡浠ゅ悗娣诲姞-lz锛屽苟鍐嶆灏濊瘯銆
瀵逛簬搴斿湪绯荤粺涓婂瓨鍦ㄧ殑鍑芥暟锛堝connect锛夛紝濡傛灉閬囧埌鏈畾涔夊紩鐢ㄩ敊璇紝璇锋鏌ョ浉鍏冲嚱鏁扮殑鎵嬪唽椤碉紝浠ヤ究纭畾搴斿湪閾炬帴鍛戒护涓婂鍔犲摢浜涘簱銆
瀵逛簬绯荤粺涓婁笉瀛樺湪鐨勫嚱鏁帮紝鍙兘浼氶亣鍒版湭瀹氫箟寮曠敤閿欒锛屽涓嬫墍绀猴細
mf_format.o(.text+0x201): 瀵`__lxstat'鐨勬湭瀹氫箟寮曠敤銆
瀹冮氬父鎰忓懗鐫浣犵殑MySQL瀹㈡埛绔簱鏄湪涓庝綘鐨勭郴缁熶笉100锛呭吋瀹圭殑绯荤粺涓婄紪璇戠殑銆傚湪璇ユ儏鍐典笅锛屽簲涓嬭浇鏈鏂扮殑MySQL婧愮爜鍒嗗彂鐗堬紝骞惰嚜宸辩紪璇MySQL銆傝鍙傝2.8鑺傦紝鈥滀娇鐢ㄦ簮鐮佸垎鍙戠増瀹夎MySQL鈥銆
褰撲綘璇曞浘鎵цMySQL绋嬪簭鏃讹紝鍙兘浼氶亣鍒拌繍琛屾椂鏈畾涔夊紩鐢ㄩ敊璇傚鏋滆繖绫婚敊璇寚鏄庝簡浠mysql_寮濮嬬殑绗﹀彿锛鎴栨寚鏄庢湭鍙戠幇mysqlclient搴锛岃繖鎰忓懗鐫浣犵殑绯荤粺鏃犳硶鎵惧埌鍏变韩鐨libmysqlclient.so搴撱瀵瑰叾鐨勬洿姝f柟寮忔槸锛岄氱煡绯荤粺鍦ㄥ簱鎵鍦ㄤ綅缃悳绱㈠叡浜簱銆傝浣跨敤涓庣郴缁熺浉閫傚簲鐨勪笅杩版柟娉曪細
路 灏libmysqlclient.so鎵鍦ㄧ洰褰曠殑璺緞娣诲姞鍒LD_LIBRARY_PATH鐜鍙橀噺涓
路 灏libmysqlclient.so鎵鍦ㄧ洰褰曠殑璺緞娣诲姞鍒LD_LIBRARY鐜鍙橀噺涓
路 灏libmysqlclient.so鎷疯礉鍒板彲琚郴缁熸悳绱㈢殑鐩綍涓嬶紝濡/lib锛岀劧鍚庨氳繃鎵цldconfig鏇存柊鍏变韩搴撲俊鎭
瑙e喅璇ラ棶棰樼殑鍙︿竴绉嶆柟娉曟槸锛屼互闈欐佹柟寮忓皢浣犵殑绋嬪簭涓庘-static鈥濋夐」閾炬帴鍦ㄤ竴璧凤紝鎴栧湪閾炬帴浠g爜涔嬪墠鍒犻櫎鍔ㄦMySQL搴撱備娇鐢ㄧ2绉嶆柟娉曚箣鍓嶏紝搴旂‘淇濇病鏈変娇鐢ㄥ姩鎬佸簱鐨勫叾瀹冪▼搴忋
鍦Windows骞冲彴涓婏紝鑳藉浣跨敤鏅氱敤鎴疯处鎴蜂互Windows鏈嶅姟鏂瑰紡杩愯鏈嶅姟鍣ㄣ
鍦Unix骞冲彴涓婏紝涓嶆槸浠讳綍鐢ㄦ埛閮借兘鍚姩骞惰繍琛MySQL鏈嶅姟鍣mysqld鐨銆備絾鏄紝澶勪簬瀹夊叏鏂归潰鐨勫師鍥狅紝搴旈伩鍏嶄互Unix鏍圭敤鎴疯韩浠借繍琛屾湇鍔″櫒銆傝鎯虫洿鏀mysqld锛屼娇涔嬭兘浠ユ甯哥殑鏃犵壒鏉Unix鐢ㄦ埛user_name韬唤杩愯锛屽繀椤婚噰鍙栦笅杩版楠わ細
濡傛灉鏈嶅姟鍣ㄦ鍦ㄨ繍琛岋紝鍋滄瀹冿紙浣跨敤mysqladmin shutdown锛夈
鏇存敼鏁版嵁搴撶洰褰曞拰鏂囦欢锛屽厑璁user_name璇诲啓鍏朵腑鐨勬枃浠讹紙鍙兘闇瑕佷互Unix鏍圭敤鎴疯韩浠藉畬鎴愯繖绫昏缃級锛
shell> chown -R user_name /path/to/mysql/datadir
濡傛灉鏈繖鏍峰仛锛屽綋浠user_name韬唤杩愯鏃讹紝鏈嶅姟鍣ㄦ棤娉曡闂暟鎹簱鎴栬〃銆
濡傛灉MySQL鏁版嵁鐩綍涓嬬殑鐩綍鎴栨枃浠堕噰鐢ㄧ殑鏄鍙烽摼鎺ワ紝杩橀渶璺熻釜杩欎簺閾炬帴锛屽苟鏇存敼瀹冧滑鎸囧悜鐨勭洰褰曞拰鏂囦欢銆chown 鈥揜鍙府鍔╀綘璺熻釜绗﹀彿閾炬帴銆
浠user_name韬唤鍚姩鏈嶅姟鍣ㄣ傚鏋滀綘姝e湪浣跨敤MySQL 3.22鎴栨洿楂樼増鏈紝鍙︿竴绉嶅彲閫夋柟寮忔槸锛屼互Unix鏍圭敤鎴疯韩浠藉惎鍔mysqld锛屽苟浣跨敤--user=user_name閫夐」銆mysqld鍚姩锛岀劧鍚庡湪鎺ュ彈浠讳綍杩炴帴鍓嶏紝鍒囨崲鑷Unix鐢ㄦ埛user_name骞朵互璇ョ敤鎴疯韩浠借繍琛屻
瑕佹兂鍦ㄧ郴缁熷惎鍔ㄦ椂鑷姩浠ョ粰瀹氱殑鐢ㄦ埛韬唤鍚姩鏈嶅姟鍣紝鍙湪鏈嶅姟鍣ㄦ暟鎹洰褰曚笅鐨/etc/my.cnf閫夐」鏂囦欢鎴my.cnf閫夐」鏂囦欢鐨[mysqld]缁勪腑锛岄氳繃澧炲姞鐢ㄦ埛閫夐」鏉ユ寚瀹氱敤鎴峰悕銆銆備緥濡傦細
[mysqld]
user=user_name
濡傛灉浣犵殑Unix鏈哄櫒鏈韩骞朵笉瀹夊叏锛屽簲鍦ㄦ巿鏉冭〃涓负MySQL鏍硅处鎴锋寚瀹氬瘑鐮併傚涓嶇劧锛屼换浣曞湪璇ユ満鍣ㄤ笂鍏锋湁鐧诲綍璐︽埛鐨勭敤鎴烽兘鑳戒娇鐢ㄢ--user=root鈥濋夐」杩愯mysql瀹㈡埛绔紝骞舵墽琛屼换浣曟搷浣溿傚湪浠讳綍鎯呭喌涓嬪潎搴斾负MySQL璐︽埛鎸囧畾瀵嗙爜锛岃繖鏄釜濂戒富鎰忥紝灏ゅ叾鏄湪鏈嶅姟鍣ㄤ富鏈轰笂瀛樺湪鍏朵粬鐧诲綍璐︽埛鏃讹紝鏇存槸濡傛銆傝鍙傝2.9鑺傦紝鈥滃畨瑁呭悗鐨勮缃拰娴嬭瘯鈥銆
濡傛灉閬囧埌涓庢枃浠惰鍙湁鍏崇殑闂锛屽彲鑳芥暟鍚姩mysqld鏃UMASK鐜鍙橀噺璁剧疆寰椾笉姝g‘銆備緥濡傦紝褰撲綘鍒涘缓琛ㄦ椂锛MySQL鍙兘浼氬彂鍑轰笅杩伴敊璇秷鎭細
ERROR: 鏃犳硶鎵惧埌鏂囦欢锛'path/with/filename.frm' (Errcode: 13)
UMASK鐨勯粯璁ゅ兼槸0660銆傞氳繃涓嬭堪鏂瑰紡鍚姩mysqld_safe锛屽彲鏀瑰彉璇ユ儏鍐碉細
shell> UMASK=384 # = 600 in octal
shell> export UMASK
shell> mysqld_safe &
鍦ㄩ粯璁ゆ儏鍐典笅锛MySQL鐢0700鐨勮鍙垱寤烘暟鎹簱鍜RAID鐩綍銆備綘鍙互閫氳繃璁剧疆UMASK_DIR鍙橀噺鏇存敼璇ヨ涓恒傚鏋滀綘璁剧疆浜嗗畠鐨勫硷紝灏嗕娇鐢ㄧ粍鍚堢殑UMASK鍜UMASK_DIR鍊煎垱寤烘柊鐩綍銆備緥濡锛屽鏋滀綘鎵撶畻涓烘墍鏈夋柊鐨勭洰褰曟巿浜堢粍璁块棶鏉冮檺锛屽彲锛
shell> UMASK_DIR=504 # = 770 in octal
shell> export UMASK_DIR
shell> mysqld_safe &
鍦MySQL 3.23.25鍜屾洿楂樼増鏈腑锛屽鏋滄槸浠0寮濮嬬殑锛MySQL灏嗚涓UMASK鍜UMASK_DIR鐨勫煎潎閲囩敤鍏繘鍒跺舰寮忋
濡傛灉浣犱粠鏈负MySQL璁剧疆鏍圭敤鎴峰瘑鐮侊紝鏈嶅姟鍣ㄥ湪浠ユ牴鐢ㄦ埛韬唤杩涜杩炴帴鏃朵笉闇瑕佸瘑鐮併備絾鏄紝寤鸿浣犱负姣忎釜璐︽埛璁剧疆瀵嗙爜銆傝鍙傝5.6.1鑺傦紝鈥滈氱敤瀹夊叏鎸囧崡鈥銆
濡傛灉浣犱互鍓嶈缃簡鏍圭敤鎴峰瘑鐮侊紝浣嗗嵈蹇樿浜嗚瀵嗙爜锛屽彲璁剧疆鏂扮殑瀵嗙爜銆備笅杩版楠ゆ槸閽堝Windows骞冲彴鐨勩傚湪鏈妭鍚庨潰鐨勫唴瀹逛腑锛屼粙缁嶄簡閽堝Unix骞冲彴鐨勬楠ゃ
鍦Windows骞冲彴涓嬶紝璇ユ楠ゆ槸锛
浠ョ郴缁熺鐞嗗憳韬唤鐧诲綍鍒扮郴缁熴
濡傛灉MySQL鏈嶅姟鍣ㄦ鍦ㄨ繍琛岋紝鍋滄瀹冦傚浜庝綔涓Windows鏈嶅姟杩愯鐨勬湇鍔″櫒锛岃繘鍏ユ湇鍔$鐞嗗櫒锛
寮濮嬭彍鍗->鎺у埗闈㈡澘->绠$悊宸ュ叿->鏈嶅姟
鐒跺悗鍦ㄥ垪琛ㄤ腑鎵惧嚭MySQL鏈嶅姟鍣紝骞跺仠姝㈠畠銆
濡傛灉鏈嶅姟鍣ㄤ笉鏄綔涓烘湇鍔¤岃繍琛岀殑锛屽彲鑳介渶瑕佷娇鐢ㄤ换鍔$鐞嗗櫒鏉ュ己鍒跺仠姝㈠畠銆
鍒涘缓1涓枃鏈枃浠讹紝骞跺皢涓嬭堪鍛戒护缃簬鍗曚竴琛屼腑锛
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
鐢ㄤ换鎰忓悕绉颁繚瀛樿鏂囦欢銆傚湪鏈緥涓紝璇ユ枃浠朵负C:\mysql-init.txt銆
鎵撳紑鎺у埗鍙扮獥鍙o紝杩涘叆DOS鍛戒护鎻愮ず锛
寮濮嬭彍鍗->杩愯-> cmd
鍋囧畾浣犲凡灏MySQL瀹夎鍒C:\mysql銆傚鏋滀綘灏MySQL瀹夎鍒颁簡鍙︿竴浣嶇疆锛岃瀵逛笅杩板懡浠よ繘琛岀浉搴旂殑璋冩暣銆
鍦DOS鍛戒护鎻愮ず绗︿笅锛屾墽琛屽懡浠わ細
C:\> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
鍦ㄦ湇鍔″櫒鍚姩鏃讹紝鎵ц鐢扁--init-file鈥濋夐」鍛藉悕鐨勬枃浠剁殑鍐呭锛屾洿鏀规牴鐢ㄦ埛瀵嗙爜銆傚綋鏈嶅姟鍣ㄦ垚鍔熷惎鍔ㄥ悗锛屽簲鍒犻櫎C:\mysql-init.txt銆
濡傛灉浣犱娇鐢MySQL瀹夎鍚戝瀹夎浜MySQL锛屾垨璁搁渶瑕佹寚瀹氣--defaults-file鈥閫夐」锛
C:\> C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld-nt.exe
--defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini"
--init-file=C:\mysql-init.txt
浣跨敤鏈嶅姟绠$悊鍣紝鍙壘鍒版伆褰撶殑鈥--defaults-file鈥璁剧疆锛
寮濮嬭彍鍗->鎺у埗闈㈡澘->绠$悊宸ュ叿->鏈嶅姟
鍦ㄥ垪琛ㄤ腑鎵惧嚭MySQL鏈嶅姟锛屽彸鍑伙紝骞堕夋嫨鈥滃睘鎬р濋夐」銆傚湪鍙墽琛屽瓧娈电殑Path锛堣矾寰勶級涓寘鍚鈥--defaults-file鈥璁剧疆銆
鍋滄MySQL鏈嶅姟鍣紝鐒跺悗鍦ㄦ甯告ā寮忎笅閲嶅惎瀹冦傚鏋滀互鏈嶅姟鏂瑰紡杩愯鏈嶅姟鍣紝搴斾粠Windows鏈嶅姟绐楀彛鍚姩瀹冦傚鏋滀互鎵嬪姩鏂瑰紡鍚姩浜嗘湇鍔″櫒锛岃兘澶熷儚姝e父鎯呭舰涓嬩竴鏍蜂娇鐢ㄥ懡浠ゃ
搴旇兘浣跨敤鏂板瘑鐮佽繘琛岃繛鎺ャ
鍦Unix鐜涓嬶紝閲嶇疆鏍圭敤鎴峰瘑鐮佺殑姝ラ濡備笅锛
浠Unix鏍圭敤鎴疯韩浠姐佹垨浠ヨ繍琛mysqld鏈嶅姟鍣ㄧ殑鐩稿悓韬唤鐧诲綍鍒扮郴缁熴
鎵惧埌鍖呭惈鏈嶅姟鍣ㄨ繘绋ID鐨.pid鏂囦欢銆傝鏂囦欢鐨勫噯纭綅缃拰鍚嶇О鍙栧喅浜庝綘鐨勫垎鍙戠増銆佷富鏈哄悕鍜岄厤缃傚父瑙佷綅缃槸/var/lib/mysql/銆/var/run/mysqld/鍜/usr/local/mysql/data/銆涓鑸儏鍐典笅锛屾枃浠跺悕鐨勬墿灞曞悕涓.pid锛屽苟浠mysqld鎴栫郴缁熺殑涓绘満鍚嶅紑濮嬨
鍦ㄤ笅杩板懡浠や腑浣跨敤.pid鏂囦欢鐨勮矾寰勫悕锛屽悜mysqld杩涚▼鍙戝嚭姝e父鐨kill锛堣屼笉鏄kill -9锛夛紝鍙仠姝MySQL鏈嶅姟鍣細
shell> kill `cat /mysql-data-directory/host_name.pid`
娉ㄦ剰锛cat鍛戒护浣跨敤绗﹀彿鈥`鈥濊屼笉鏄溾欌濓細杩欎細浣cat鐨勮緭鍑轰唬鍏ュ埌kill鍛戒护涓
鍒涘缓鏂囨湰鏂囦欢锛屽苟灏嗕笅杩板懡浠ゆ斁鍦ㄦ枃浠跺唴鐨1琛屼笂锛
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
鐢ㄤ换鎰忓悕绉颁繚瀛樻枃浠躲傚浜庢湰渚嬶紝鏂囦欢涓~/mysql-init銆
鐢ㄧ壒娈婄殑鈥--init-file=~/mysql-init鈥濋夐」閲嶅惎MySQL鏈嶅姟鍣細
shell> mysqld_safe --init-file=~/mysql-init &
鏂囦欢init-file鐨勫唴瀹瑰湪鏈嶅姟鍣ㄥ惎鍔ㄦ椂鎵ц锛屾洿鏀规牴鐢ㄦ埛瀵嗙爜銆傛湇鍔″櫒鎴愬姛鍚姩鍚庯紝搴斿垹闄~/mysql-init銆
搴旇兘浣跨敤鏂板瘑鐮佽繘琛岃繛鎺ャ
浣滀负鍙夋柟寮忥紝鍦ㄤ换浣曞钩鍙颁笂锛屽彲浣跨敤mysql瀹㈡埛绔缃柊瀵嗙爜锛堜絾璇ユ柟娉曚笉澶熷畨鍏級锛
鍋滄mysqld锛屽苟鐢ㄢ--skip-grant-tables --user=root鈥閫夐」閲嶅惎瀹锛Windows鐢ㄦ埛鍙渷鐣--user=root閮ㄥ垎锛夈
浣跨敤涓嬭堪鍛戒护杩炴帴鍒mysqld鏈嶅姟鍣細
shell> mysql -u root
鍦mysql瀹㈡埛绔彂鍑轰笅杩拌鍙ワ細
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
鐢ㄦ墦绠椾娇鐢ㄧ殑瀹為檯鏍圭敤鎴峰瘑鐮佹浛鎹⑩newpwd鈥濄
搴旇兘浣跨敤鏂板瘑鐮佽繘琛岃繛鎺ャ
姝e紡鍙戝竷涔嬪墠锛屾瘡涓MySQL鐗堟湰鍧囧湪寰堝骞冲彴涓婅繘琛屼簡娴嬭瘯銆傝繖涓嶈〃绀MySQL涓笉瀛樺湪缂洪櫡锛屼絾鏄紝濡傛灉瀛樺湪缂洪櫡锛屽畠浠簲寰堝皯锛岃屼笖寰堥毦鍙戠幇銆傚鏋滀綘閬囧埌闂锛屽鏋滀綘灏濊瘯鎵惧嚭瀵艰嚧绯荤粺宕╂簝鐨勫噯纭師鍥狅紝杩欏缁堝緢鏈夊府鍔╋紝杩欐槸鍥犱负锛屽鏋滆繖鏍风殑璇濓紝蹇熻В鍐抽棶棰樼殑鏈轰細寰堝ぇ銆
棣栧厛锛屽簲灏濊瘯鎵惧嚭闂鏄惁涓mysqld鏈嶅姟鍣ㄦ湁鍏筹紝鎴栨槸鍚︿笌瀹㈡埛绔湁鍏炽傞氳繃鎵цmysqladmin version锛屽彲妫鏌mysqld鏈嶅姟鍣ㄨ繍琛屼簡澶氶暱鏃堕棿銆傚鏋mysqld瀹曟満骞堕噸鍚紝搴旀煡鐪嬫湇鍔″櫒鐨勯敊璇棩蹇椾互鎵惧嚭鍘熷洜銆傝鍙傝5.11.1鑺傦紝鈥滈敊璇棩蹇椻銆
鍦ㄦ煇浜涚郴缁熶笂锛屽湪閿欒鏃ュ織涓紝鍙彂鐜mysqld瀹曟満鐨勫爢鏍堣窡韪紝鍙娇鐢resolve_stack_dump绋嬪簭瑙e喅瀹銆傝鍙傝E.1.4鑺傦紝鈥滀娇鐢ㄥ爢鏍堣窡韪銆傛敞鎰忥紝閿欒鏃ュ織涓殑鍙橀噺鍊煎苟闈炲缁堟槸100锛呮纭殑銆
寰堝鏈嶅姟鍣ㄥ穿婧冩槸鍥犳崯鍧忕殑鏁版嵁鏂囦欢鎴栫储寮曟枃浠惰屽鑷寸殑锛屾瘡娆℃墽琛屽畬SQL璇彞涔嬪悗骞跺湪鍚戝鎴风閫氬憡缁撴灉涔嬪墠锛MySQL灏嗕娇鐢write()绯荤粺璋冪敤鏇存柊纾佺洏涓婄殑鏂囦欢锛堝鏋滀綘浣跨敤浜嗏--delay-key-write鈥濋夐」锛屾儏鍐靛苟闈炲姝わ紝姝ゆ椂灏嗗啓鍏ユ暟鎹枃浠惰屼笉鏄储寮曟枃浠讹級銆傝繖鎰忓懗鐫锛屽嵆浣mysqld宕╂簝锛屾暟鎹枃浠剁殑鍐呭涔熸槸瀹夊叏鐨勶紝杩欐槸鍥犱负鎿嶄綔绯荤粺鑳戒繚璇佸皢鏈埛鏂扮殑鏁版嵁鍐欏叆纾佺洏銆備娇鐢ㄢ--flush鈥濋夐」鍚姩mysqld锛岃繖鏍凤紝姣忔鎵ц瀹SQL璇彞鍚庯紝鍙己鍒MySQL灏嗘墍鏈夊唴瀹瑰啓鍏ョ鐩樸
鍓嶈堪浠嬬粛琛ㄦ槑锛屽湪姝e父鎯呭喌涓嬩笉浼氬嚭鐜版崯鍧忕殑琛紝闄ら潪鍑虹幇浜嗕笅杩版儏鍐典箣涓锛
鍦ㄦ洿鏂拌繃绋嬩腑锛MySQL鏈嶅姟鍣ㄦ垨鏈嶅姟鍣ㄤ富鏈鸿鍋滄銆
浣犲彂鐜颁簡mysqld涓瓨鍦ㄧ殑1涓己闄凤紝璇ョ己闄峰鑷mysqld鍦ㄦ洿鏂颁腑閫斾腑姝€
鍦mysqld鎿嶄綔鐨勫悓鏃讹紝鏌愪簺澶栭儴绋嬪簭姝e湪鎿嶆帶鏁版嵁鏂囦欢鎴栫储寮曟枃浠讹紝鏈伆褰撻攣瀹氳〃銆
浣犳浣跨敤绯荤粺涓婄殑鐩稿悓鏁版嵁鐩綍杩愯寰堝mysqld鏈嶅姟鍣紝璇ョ郴缁熶笉鏀寔鑹ソ鐨勬枃浠剁郴缁熼攣瀹氾紙閫氬父鏄敱lockd閿佸畾绠$悊鍣ㄨ礋璐g殑锛夛紝鎴栦娇鐢ㄢ--skip-external-locking鈥濋夐」杩愯浜嗗涓湇鍔″櫒銆
宕╂簝鐨勬暟鎹枃浠舵垨绱㈠紩鏂囦欢锛屽叾涓寘鍚鑷mysqld娣蜂贡鐨勬崯鍧忓緢涓ラ噸鐨勬暟鎹
鍦ㄦ暟鎹瓨鍌ㄨ妭鐐瑰彂鐜扮己闄枫傝繖绉嶅彲鑳芥т笉澶э紝浣嗚嚦灏戞槸鍙兘鐨勩傚湪璇ユ儏鍐典笅锛屽彲鍦ㄤ慨澶嶇殑琛ㄥ壇鏈笂锛岄氳繃浣跨敤ALTER TABLE锛灏濊瘯灏嗚〃绫诲瀷鏇存敼涓哄彟涓绉嶅瓨鍌ㄥ紩鎿庛
鐢变簬寰堥毦寰楃煡涓轰粈涔堟煇浜嬩細鍑虹幇宕╂簝锛岄鍏堣妫鏌ョ敤浜庡叾浠栨柟闈㈢殑浜嬮」鏄惁宕╂簝銆傝灏濊瘯閲囧彇涓嬭堪鎺柦锛
鐢mysqladmin shutdown鍋滄mysqld鏈嶅姟鍣紝浠庢暟鎹洰褰曡繍琛myisamchk --silent --force */*.MYI锛屾鏌ユ墍鏈夌殑MyISAM琛紝骞堕噸鍚mysqld銆傝繖鏍凤紝灏辫兘纭繚浠庡共鍑鐨勭姸鎬佽繍琛屾湇鍔″櫒銆傝鍙傝绗5绔狅細鏁版嵁搴撶鐞銆
浣跨敤鈥--log鈥濋夐」鍚姩mysqld锛屽苟鏍规嵁鍐欏叆鏃ュ織鐨勪俊鎭‘瀹氭槸鍚︽煇浜涚壒娈婄殑鏌ヨ鏉姝讳簡鏈嶅姟鍣ㄣ傜害95%鐨勭己闄蜂笌鐗瑰畾鐨勬煡璇㈡湁鍏炽傛甯告儏鍐典笅锛岃繖鏄湇鍔″櫒閲嶅惎鍓嶆棩蹇楁枃浠朵腑鏈澶熸暟涓煡璇腑鐨1涓傝鍙傝5.11.2鑺傦紝鈥滈氱敤鏌ヨ鏃ュ織鈥銆傚鏋滆兘澶熺敤鐗规畩鏌ヨ閲嶅鏉姝MySQL锛屽嵆浣垮湪鍙戝嚭鏌ヨ鍓嶆鏌ヤ簡鎵鏈夎〃鐨勬儏鍐典笅涔熷悓鏍凤紝閭d箞浣犲氨搴旇兘纭畾缂洪櫡锛屽苟搴旀彁浜ゅ叧浜庤缂洪櫡鐨勭己闄锋姤鍛娿傝鍙傝1.7.1.3鑺傦紝鈥滃浣曢氭姤缂洪櫡鍜岄棶棰樷銆
灏濊瘯鎻愪緵涓涓祴璇曡寖渚嬶紝鎴戜滑搴旇兘鍒╃敤璇ヨ寖渚嬮噸澶嶉棶棰樸傝鍙傝E.1.6鑺傦紝鈥滃鏋滃嚭鐜拌〃宕╂簝锛岃鐢熸垚娴嬭瘯妗堜緥鈥銆
璇峰湪mysql-test鐩綍涓嬪苟鏍规嵁MySQL鍩哄噯杩涜娴嬭瘯銆璇峰弬瑙27.1.2鑺傦紝鈥淢ySQL娴嬭瘯濂椾欢鈥銆傚畠浠兘鐩稿綋鑹ソ鍦版祴璇MySQL銆備綘涔熷彲浠ヤ负鍩哄噯娴嬭瘯澧炲姞浠g爜锛屼互妯℃嫙浣犵殑搴旂敤绋嬪簭銆傚熀鍑嗘祴璇曞彲鍦ㄦ簮鐮佸垎鍙戠増鐨sql-bench鐩綍涓嬫壘鍒帮紝瀵逛簬浜岃繘鍒跺垎鍙戠増锛屽彲鍦MySQL瀹夎鐩綍涓嬬殑sql-bench鐩綍涓嬫壘鍒般
灏濊瘯浣跨敤fork_big.pl鑴氭湰锛堝畠浣嶄簬婧愮爜鍒嗗彂鐗堢殑娴嬭瘯鐩綍涓嬶級銆
濡傛灉浣犲皢MySQL閰嶇疆涓鸿皟璇曟ā寮忥紝濡傛灉鏌愪簨鍑洪敊锛屽彲鏇翠负瀹规槗鍦版悳闆嗗叧浜庡彲鑳介敊璇殑淇℃伅銆傚鏋滃皢MySQL閰嶇疆涓鸿皟璇曟ā寮忥紝鍙敓鎴1涓畨鍏ㄧ殑鍐呭瓨鍒嗛厤绋嬪簭锛屽彲浣跨敤瀹冨彂鐜版煇浜涢敊璇傛澶栵紝瀹冭繕鎻愪緵浜嗗緢澶氳緭鍑猴紝杩欑被杈撳嚭涓庡嚭鐜扮殑闂鐩稿叧銆傚湪configure涓婁娇鐢ㄢ--with-debug鈥濇垨鈥--with-debug=full鈥濋夐」閲嶆柊閰嶇疆MySQL锛岀劧鍚庡啀缂栬瘧瀹冦傝鍙傝E.1鑺傦紝鈥滆皟璇昅ySQL鏈嶅姟鍣ㄢ銆
纭繚涓轰綘鐨勬搷浣滅郴缁熷簲鐢ㄤ簡鏈鏂扮殑琛ヤ竵銆
瀵mysqld浣跨敤鈥--skip-external-locking鈥濋夐」銆傚湪鏌愪簺绯荤粺涓婏紝lockd閿佸畾绠$悊鍣ㄤ笉鑳芥纭伐浣滐紝鈥--skip-external-locking鈥閫夐」閫氱煡mysqld涓嶄娇鐢ㄥ閮ㄩ攣瀹氥傦紙杩欐剰鍛崇潃锛屼綘涓嶈兘鍦ㄧ浉鍚岀殑鏁版嵁鐩綍涓婅繍琛2涓mysqld鏈嶅姟鍣紝濡傛灉浣跨敤myisamchk锛屽繀椤昏皑鎱庛傜劧鑰岋紝灏濊瘯灏嗚閫夐」鐢ㄤ綔娴嬭瘯涔熸槸鏈夌泭鐨勶級銆
褰mysqld鐪嬩笂鍘绘鍦ㄨ繍琛屼絾骞舵湭鍝嶅簲鏃讹紝鏄惁杩愯浜mysqladmin -u root processlist锛熸煇浜涙椂鍊欙紝鍗充娇浣犺涓mysqld澶勪簬闂茬疆鐘舵佹椂锛屽疄闄呮儏鍐靛苟闈炲姝ゃ傞棶棰樺彲鑳芥槸鍥犱负鎵鏈夎繛鎺ュ潎宸蹭娇鐢紝鎴栧瓨鍦ㄦ煇浜涘唴閮ㄩ攣瀹氶棶棰樸傚嵆浣垮湪璇ユ儏鍐典笅锛mysqladmin -u root processlist閫氬父鑳藉杩涜杩炴帴锛屽苟鑳芥彁渚涘叧浜庡綋鍓嶈繛鎺ユ暟浠ュ強鍏剁姸鎬佺殑鏈夌敤淇℃伅銆
鍦ㄨ繍琛屽叾浠栨煡璇㈢殑鍚屾椂锛屽湪鍗曠嫭鐨勭獥鍙d腑杩愯鍛戒护mysqladmin -i 5 status鎴mysqladmin -i 5 -r status锛屼互鐢熸垚缁熻淇℃伅銆
灏濊瘯閲囩敤涓嬭堪鏂规硶锛
浠gdb锛堟垨鍙︿竴涓皟璇曞櫒锛夊惎鍔mysqld銆傝鍙傝E.1.3鑺傦紝鈥滃湪gdb鐜涓嬭皟璇昺ysqld鈥銆
杩愯娴嬭瘯鑴氭湰銆
鍦3涓緝浣庡眰闈笂杈撳嚭backtrace锛堝悜鍚庤窡韪級鍜屽眬閮ㄥ彉閲忋傚湪gdb涓紝褰mysqld鍦gdb鍐呭穿婧冩椂锛屽彲浣跨敤涓嬭堪鍛戒护瀹屾垚璇ヤ换鍔★細
backtrace
info local
up
info local
up
info local
浣跨敤gdb锛屼綘杩樿兘妫鏌ヤ笌info绾跨▼鍏卞瓨鐨勭嚎绋嬶紝骞跺垏鎹㈣嚦鐗瑰畾鐨勭嚎绋N锛屽叾涓紝N鏄嚎绋ID銆
灏濊瘯鐢Perl鑴氭湰妯℃嫙浣犵殑搴旂敤绋嬪簭锛屽己鍒MySQL宕╂簝鎴栬涓哄紓甯搞
鍙戦佹甯哥殑缂洪櫡鎶ュ憡銆傝鍙傝1.7.1.3鑺傦紝鈥滃浣曢氭姤缂洪櫡鍜岄棶棰樷銆傚簲姣旈氬父鐨勬姤鍛婃洿璇︾粏銆傜敱浜MySQL鏄负寰堝浜烘彁渚涙湇鍔$殑锛屽畠鍙兘鍥犱粎瀛樺湪浜庝綘鐨勮绠楁満涓婄殑鏌愪簨宕╂簝锛堜緥濡傦紝涓庝綘鐨勭壒瀹氱郴缁熷簱鏈夊叧鐨勯敊璇級銆
濡傛灉浣犻亣鍒颁笌鍖呭惈鍔ㄦ侀暱搴﹁鐨勮〃鏈夊叧鐨勯棶棰橈紝鑰屼笖浣犱粎浣跨敤VARCHAR鍒锛堣屼笉鏄BLOB鎴TEXT鍒楋級锛屽彲灏濊瘯鐢ALTER TABLE灏嗘墍鏈VARCHAR鍒楁洿鏀逛负CHAR鍒椼傝繖鏍凤紝灏变細寮哄埗MySQL浣跨敤鍥哄畾澶у皬鐨勮銆傚浐瀹氬ぇ灏忕殑琛屽崰鐢ㄧ殑绌洪棿鐣ュ锛屼絾瀵规崯鍧忕殑瀹瑰繊搴︽洿楂樸
鐩墠鐨勫姩鎬佽浠g爜鍦MySQL AB宸蹭娇鐢ㄥ骞达紝寰堝皯閬囧埌闂锛屼絾浠庢湰璐ㄤ笂鐪嬶紝鍔ㄦ侀暱搴﹁鏇村惧悜浜庡嚭鐜伴敊璇紝鍥犳锛屼笉濡ㄥ皾璇曢噰鐢ㄨ绛栫暐浠ユ煡鐪嬪畠鏄惁鏈夊府鍔╋紝杩欎笉澶变负涓涓ソ涓绘剰銆
璇婃柇闂鏃朵笉瑕佸皢浣犵殑鏈嶅姟鍣ㄧ‖浠舵帓闄ゅ湪澶栥傛湁缂洪櫡鐨勭‖浠惰兘澶熷鑷存暟鎹崯鍧忋傚纭欢杩涜鏁呴殰璇婃柇涓庢帓闄ゆ搷浣滄椂锛屽挨鍏跺簲娉ㄦ剰RAM鍜岀‖鐩橀┍鍔ㄥ櫒銆
鍦ㄦ湰鑺備腑锛屼粙缁嶄簡MySQL鍝嶅簲纾佺洏婊¢敊璇殑鏂瑰紡锛堝鈥滆澶囦笂鏃犲墿浣欑┖闂粹濓級锛屼互鍙婂搷搴旇秴閰嶉閿欒鐨勬柟寮忥紙濡傗滃啓鍏ュけ璐モ濇垨鈥滆揪鍒颁簡鐢ㄦ埛灞忚斀闄愬埗鈥濓級銆
鏈妭浠嬬粛鐨勫唴瀹逛笌鍐欏叆MyISAM琛ㄦ湁鍏炽傚畠涔熼傜敤浜庡啓鍏ヤ簩杩涘埗鏃ュ織鏂囦欢鍜屼簩杩涘埗绱㈠紩鏂囦欢锛屼絾瀵鈥row鈥濆拰鈥record鈥濈殑搴旂敤搴旇瑙嗕负鈥event鈥濄
鍑虹幇纾佺洏婊$姸鍐垫椂锛MySQL灏嗭細
姣忓垎閽熸鏌ヤ竴娆★紝鏌ョ湅鏄惁鏈夎冻澶熺┖闂村啓鍏ュ綋鍓嶈銆傚鏋滄湁瓒冲绌洪棿锛屽皢缁х画锛屽氨鍍忎粈涔堜篃鏈彂鐢熶竴鏍枫
姣10鍒嗛挓灏1涓潯鐩啓鍏ユ棩蹇楁枃浠讹紝鎻愰啋纾佺洏婊$姸鍐点
涓轰簡鍑忚交闂锛屽彲閲囧彇涓嬭堪鎺柦锛
瑕佹兂缁х画锛屼粎闇鏈夎冻澶熺殑纾佺洏绌洪棿浠ユ彃鍏ユ墍鏈夎褰曘
瑕佹兂鏀惧純绾跨▼锛屽繀椤讳娇鐢mysqladmin kill銆備笅娆℃鏌ョ鐩樻椂灏嗘斁寮冪嚎绋嬶紙1鍒嗛挓锛夈
鍏朵粬绾跨▼鍙兘浼氭鍦ㄧ瓑寰呭鑷寸鐩樻弧鐘跺喌鐨勮〃銆傚鏋滄湁鏁颁釜鈥滃凡閿佸畾鈥濈殑绾跨▼锛屾潃姝绘鍦ㄧ鐩樻弧鐘跺喌涓嬬瓑寰呯殑鏌愪竴绾跨▼锛屼互渚垮厑璁稿叾浠栫嚎绋嬬户缁
瀵瑰墠杩拌涓虹殑渚嬪鏄紝褰撲綘浣跨敤REPAIR TABLE鎴OPTIMIZE TABLE鏃讹紝鎴栧綋绱㈠紩鏄湪LOAD DATA INFILE鎴ALTER TABLE璇彞鍚庛佸湪鎵规搷浣滀腑鍒涘缓鐨勩傛墍鏈夎繖浜涜鍙ヨ兘鍒涘缓澶х殑涓存椂鏂囦欢锛屽鏋滀繚鐣欒繖浜涙枃浠讹紝浼氬鑷寸郴缁熷叾浠栭儴鍒嗗嚭鐜板ぇ闂銆傚鏋滃湪MySQL鎵ц杩欑被鎿嶄綔鐨勫悓鏃剁鐩樺凡婊★紝瀹冨皢鍒犻櫎澶х殑涓存椂鏂囦欢锛屽苟灏嗚〃鏍囨敞涓哄穿婧冦備絾瀵逛簬ALTER TABLE渚嬪锛屾棫琛ㄤ繚鎸佷笉鍙樸
MySQL浣跨敤鐜鍙橀噺TMPDIR鐨勫间綔涓轰繚瀛樹复鏃舵枃浠剁殑鐩綍鐨勮矾寰勫悕銆傚鏋滄湭璁剧疆TMPDIR锛MySQL灏嗕娇鐢ㄧ郴缁熺殑榛樿鍊硷紝閫氬父涓/tmp銆/var/tmp鎴/usr/tmp銆傚鏋滃寘鍚复鏃舵枃浠剁洰褰曠殑鏂囦欢绯荤粺杩囧皬锛屽彲瀵mysqld浣跨敤鈥鈥攖mpdir鈥閫夐」锛鍦ㄥ叿鏈夎冻澶熺┖闂寸殑鏂囦欢绯荤粺鍐呮寚瀹1涓洰褰曘
鍦MySQL 5.1涓紝鈥鈥攖mpdir鈥閫夐」鍙璁剧疆涓烘暟涓矾寰勭殑鍒楄〃锛屼互寰幆鏂瑰紡浣跨敤銆傚湪Unix骞冲彴涓婏紝璺緞鐢ㄥ啋鍙峰瓧绗鈥:鈥闅斿紑锛屽湪Windows銆NetWare鍜OS/2骞冲彴涓婏紝璺緞鐢ㄥ垎鍙峰瓧绗鈥;鈥闅斿紑銆傛敞鎰忥紝涓轰簡鏈夋晥鍒嗗竷璐熻浇锛岃繖浜涜矾寰勫簲浣嶄簬涓嶅悓鐨勭墿鐞嗙鐩樹笂锛岃屼笉鏄綅浜庣浉鍚岀鐩樼殑涓嶅悓鍒嗗尯涓
濡傛灉MySQL鏈嶅姟鍣ㄦ浣滀负澶嶅埗浠庢湇鍔″櫒浣跨敤锛屼笉搴斿皢鈥--tmpdir鈥璁剧疆涓烘寚鍚戝熀浜庡唴瀛樼殑鏂囦欢绯荤粺鐨勭洰褰曪紝鎴栧綋鏈嶅姟鍣ㄤ富鏈洪噸鍚椂灏嗘竻绌虹殑鐩綍銆傚浜庡鍒朵粠鏈嶅姟鍣紝闇瑕佸湪鏈哄櫒閲嶅惎鏃朵粛淇濈暀涓浜涗复鏃舵枃浠讹紝浠ヤ究鑳藉澶嶅埗涓存椂琛ㄦ垨鎵цLOAD DATA INFILE鎿嶄綔銆傚鏋滃湪鏈嶅姟鍣ㄩ噸鍚椂涓㈠け浜嗕复鏃舵枃浠剁洰褰曚笅鐨勬枃浠讹紝澶嶅埗灏嗗け璐ャ
MySQL浼氫互闅愬惈鏂瑰紡鍒涘缓鎵鏈夌殑涓存椂鏂囦欢銆傝繖鏍凤紝灏辫兘纭繚涓mysqld鏃朵細鍒犻櫎鎵鏈変复鏃舵枃浠躲備娇鐢ㄩ殣鍚枃浠剁殑缂虹偣鍦ㄤ簬锛屽湪涓存椂鏂囦欢鐩綍鎵鍦ㄧ殑浣嶇疆涓紝鐪嬩笉鍒板崰鐢ㄤ簡鏂囦欢绯荤粺鐨勫ぇ涓存椂鏂囦欢銆
杩涜鎺掑簭鏃讹紙ORDER BY鎴GROUP BY锛夛紝MySQL閫氬父浼氫娇鐢1涓垨澶氫釜涓存椂鏂囦欢銆傛墍闇鐨勬渶澶х鐩樼┖闂寸敱涓嬭堪琛ㄨ揪寮忓喅瀹氾細
(length of what is sorted + sizeof(row pointer))
* number of matched rows
* 2
鈥row pointer鈥濓紙琛屾寚閽堬級鐨勫ぇ灏忛氬父鏄4瀛楄妭锛屼絾鍦ㄤ互鍚庯紝瀵逛簬澶х殑琛紝璇ュ煎彲鑳戒細澧炲姞銆
瀵逛簬鏌愪簺SELECT鏌ヨ锛MySQL杩樹細鍒涘缓涓存椂SQL琛ㄣ傚畠浠笉鏄殣鍚〃锛屽苟鍏锋湁SQL_*褰㈠紡鐨勫悕绉般
ALTER TABLE浼氬湪涓庡師濮嬭〃鐩綍鐩稿悓鐨勭洰褰曚笅鍒涘缓涓存椂琛ㄣ
瀵逛簬鏈嶅姟鍣ㄧ敤鏉ヤ笌鏈湴瀹㈡埛绔繘琛岄氫俊鐨Unix濂楁帴瀛楁枃浠讹紝鍏堕粯璁や綅缃槸/tmp/mysql.sock銆傝繖鏈夊彲鑳藉鑷撮棶棰橈紝鍘熷洜鍦ㄤ簬锛屽湪鏌愪簺鐗堟湰鐨Unix涓婏紝浠讳綍浜洪兘鑳藉垹闄/tmp鐩綍涓嬬殑鏂囦欢銆
鍦ㄥぇ澶氭暟Unix鐗堟湰涓紝鍙/tmp鐩綍杩涜淇濇姢锛屼娇寰楁枃浠跺彧鑳借鍏舵墍鏈夎繖鎴栬秴绾х敤鎴凤紙鏍圭敤鎴凤級鍒犻櫎銆備负姝わ紝浠ユ牴鐢ㄦ埛韬唤鐧诲綍锛屽苟浣跨敤涓嬭堪鍛戒护鍦/tmp鐩綍涓婅缃矘鐫浣嶏細
shell> chmod +t /tmp
閫氳繃鎵цls -ld /tmp锛屽彲妫鏌ユ槸鍚﹁缃簡绮樼潃浣嶃傚鏋滄渶鍚庝竴涓鍙瓧绗︽槸鈥渢鈥锛岃〃鏄庤缃簡绮樼潃浣嶃
鍙︿竴绉嶆柟娉曟槸鏀瑰彉鏈嶅姟鍣ㄥ垱寤Unix濂楁帴瀛楁枃浠剁殑浣嶇疆銆傚鏋滆繘琛屼簡杩欑被鎿嶄綔锛岃繕搴旇瀹㈡埛绔▼搴忕煡閬撴枃浠剁殑浣嶇疆銆傝兘澶熶互澶氱涓嶅悓鏂瑰紡鎸囧畾鏂囦欢浣嶇疆锛
鍦ㄥ叏灞鎴栧眬閮ㄩ夐」鏂囦欢涓寚瀹氳矾寰勩備緥濡傦紝灏嗕笅杩拌缃簬鏂囦欢/etc/my.cnf涓細
[mysqld]
socket=/path/to/socket
[client]
socket=/path/to/socket
璇峰弬瑙4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥銆
鍦ㄨ繍琛屽鎴风绋嬪簭鏃讹紝鍦ㄥ懡浠よ涓婁负mysqld_safe鎸囧畾鈥--socket鈥閫夐」銆
灏MYSQL_UNIX_PORT鐜鍙橀噺璁剧疆涓Unix濂楁帴瀛楁枃浠剁殑璺緞銆
閲嶆柊浠庢簮鐮佺紪璇MySQL锛屼互浣跨敤涓嶅悓鐨勯粯璁Unix濂楁帴瀛楁枃浠朵綅缃傝繍琛configure鏃讹紝鐢ㄢ--with-unix-socket-path鈥濋夐」瀹氫箟鏂囦欢璺緞銆傝鍙傝2.8.2鑺傦紝鈥滃吀鍨嬮厤缃夐」鈥銆
鐢ㄤ笅杩板懡浠よ繛鎺ユ湇鍔″櫒锛岃兘澶熸祴璇曟柊鐨勫鎺ュ瓧浣嶇疆鏄惁宸ヤ綔锛
shell> mysqladmin --socket=/path/to/socket version
濡傛灉閬囧埌涓SELECT NOW()鏈夊叧鐨勯棶棰橈紝瀹冭繑鍥GMT鍊艰屼笉鏄綋鍦版椂闂达紝灏卞簲閫氱煡鏈嶅姟鍣ㄤ綘鐨勫綋鍓嶅け鍘汇傚鏋UNIX_TIMESTAMP()杩斿洖閿欒鍊硷紝涓婅堪鏂瑰紡鍚屾牱閫傜敤銆傚簲涓烘湇鍔″櫒鎵杩愯鐨勭幆澧冭繘琛岃繖绫昏缃紝渚嬪锛屽湪mysqld_safe鎴mysql.server涓傝鍙傝闄勫綍F锛鐜鍙橀噺銆
涔熷彲浠ュmysqld_safe浣跨敤鈥--timezone=timezone_name鈥濋夐」锛屼负鏈嶅姟鍣ㄨ缃け鍘汇備篃鍙互鍦ㄥ惎鍔mysqld涔嬪墠锛岄氳繃璁剧疆TZ鐜鍙橀噺瀹屾垚璇ヨ缃
鈥--timezone鈥濇垨TZ鐨勫厑璁稿间笌绯荤粺鏈夊叧銆傚叧浜庡彲鎺ュ彈鐨勫硷紝璇峰弬瑙佹搷浣滅郴缁熸枃妗c
鍦ㄩ粯璁ゆ儏鍐典笅锛MySQL鎼滅储涓嶅尯鍒嗗ぇ灏忓啓锛堜絾鏌愪簺瀛楃闆嗗缁堝尯鍒嗗ぇ灏忓啓锛屽czech锛夈傝繖鎰忓懗鐫锛屽鏋滀綘浣跨敤col_name LIKE 'a%'杩涜鎼滅储锛屼綘灏嗚幏寰椾互A鎴a寮濮嬬殑鎵鏈夊垪銆傚鏋滄墦绠椾娇鎼滅储鍖哄垎澶у皬鍐欙紝璇风‘淇濇搷浣滄暟涔嬩竴鍏锋湁鍖哄垎澶у皬鍐欑殑鎴栦簩杩涘埗鏍″銆備緥濡傦紝濡傛灉浣犳鍦ㄦ瘮杈冨潎閫傜敤latin1瀛楃闆嗙殑鍒楀拰瀛楃涓诧紝鍙娇鐢COLLATE鎿嶄綔绗锛屼娇1涓搷浣滄暟鍏锋湁latin1_general_cs鎴latin1_bin鏍″鐗规с備緥濡傦細
col_name COLLATE latin1_general_cs LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_general_cs
col_name COLLATE latin1_bin LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_bin
濡傛灉甯屾湜鎬绘槸浠ュ尯鍒嗗ぇ灏忓啓鐨勬柟寮忓鐞嗗垪锛屽彲浣跨敤鍖哄垎澶у皬鍐欑殑鎴栦簩杩涘埗鏍″澹版槑瀹冦傝鍙傝13.1.5鑺傦紝鈥淐REATE TABLE璇硶鈥銆
绠鍗曠殑姣旇緝鎿嶄綔锛>=, >, =, <, <=, 鎺掑簭鍜屽垎缁勶級鍩轰簬姣忎釜瀛楃鐨勨滄帓搴忓尖濄傚叿鏈夌浉鍚屾帓搴忓肩殑瀛楃锛堝鈥E鈥, 鈥e鈥,鍜屸脙漏鈥欙級灏嗚褰撲綔鐩稿悓鐨勫啓瀛楃銆
DATE鍊肩殑鏍煎紡鏄'YYYY-MM-DD'銆鎸夌収鏍囧噯鐨SQL锛屼笉鍏佽鍏朵粬鏍煎紡銆傚湪UPDATE琛ㄨ揪寮忎互鍙SELECT璇彞鐨WHERE瀛愬彞涓簲浣跨敤璇ユ牸寮忋備緥濡傦細
mysql> SELECT * FROM tbl_name WHERE date >= '2003-05-05';
涓轰簡鏂逛究锛屽鏋滄棩鏈熸槸鍦ㄦ暟鍊肩幆澧冧笅浣跨敤鐨勶紝MySQL浼氳嚜鍔ㄥ皢鏃ユ湡杞崲涓烘暟鍊硷紙鍙嶄箣浜︾劧锛夈傚畠杩樺叿鏈夌浉褰撶殑鏅鸿兘锛屽湪鏇存柊鏃舵垨鍦ㄤ笌TIMESTAMP銆DATE鎴DATETIME鍒楁瘮杈冩棩鏈熺殑WHERE瀛愬彞涓紝鍏佽鈥瀹芥澗鐨鈥瀛楃涓插舰寮忥紙鈥瀹芥澗褰㈠紡鈥琛ㄧず锛屼换浣曟爣鐐瑰瓧绗﹀潎鑳界敤浣滃悇閮ㄥ垎涔嬮棿鐨勫垎闅旂銆備緥濡傦紝'2004-08-15'鍜'2004#08#15'鏄瓑鍚岀殑锛夈MySQL杩樿兘杞崲涓嶅惈浠讳綍鍒嗛殧绗︾殑瀛楃涓诧紙濡'20040815'锛夛紝鍓嶄綋鏄畠蹇呴』鏄湁鎰忎箟鐨勬棩鏈熴
浣跨敤<銆<=銆=銆>=銆>銆佹垨BETWEEN鎿嶄綔绗﹀皢DATE銆TIME銆DATETIME鎴TIMESTAMP涓庡父閲忓瓧绗︿覆杩涜姣旇緝鏃讹紝MySQL閫氬父浼氬皢瀛楃涓茶浆鎹负鍐呴儴闀挎暣鏁帮紝浠ヤ究杩涜蹇熸瘮杈冿紙浠ュ強鐣ヤ负鈥滃鏉锯濈殑瀛楃涓叉鏌ワ級銆備絾鏄紝璇ヨ浆鎹㈠叿鏈変笅杩颁緥澶栵細
姣旇緝涓ゅ垪鏃
灏DATE銆TIME銆DATETIME鎴TIMESTAMP鍒椾笌琛ㄨ揪寮忚繘琛屾瘮杈冩椂
浣跨敤鍏朵粬姣旇緝鏂规硶鏃讹紝濡IN鎴STRCMP()銆
瀵逛簬杩欎簺渚嬪鎯呭舰锛屼細灏嗗璞¤浆鎹负瀛楃涓插苟鎵ц瀛楃涓叉瘮杈冿紝閲囩敤璇ユ柟寮忚繘琛屾瘮杈冦
涓轰簡淇濇寔瀹夊叏锛屽亣瀹氭寜瀛楃涓叉瘮杈冨瓧绗︿覆锛屽鏋滀綘鎵撶畻姣旇緝涓存椂鍊煎拰瀛楃涓诧紝灏嗕娇鐢ㄦ伆褰撶殑瀛楃涓插嚱鏁般
瀵逛簬鐗规畩鏃ユ湡'0000-00-00'锛岃兘澶熶互'0000-00-00'褰㈠紡淇濆瓨鍜屾绱€傚湪MyODBC涓娇鐢'0000-00-00'鏃ユ湡鏃讹紝瀵逛簬MyODBC 2.50.12鎴栨洿楂樼増鏈紝璇ユ棩鏈熷皢琚嚜鍔ㄨ浆鎹负NULL锛岃繖鏄洜涓ODBC涓嶈兘澶勭悊杩欑被鏃ユ湡銆
鐢变簬MySQL鑳藉鎵ц鍓嶉潰鎵浠嬬粛鐨勮浆鎹紝涓嬭堪璇彞鍧囪兘姝e父宸ヤ綔锛
mysql> INSERT INTO tbl_name (idate) VALUES (19970505);
mysql> INSERT INTO tbl_name (idate) VALUES ('19970505');
mysql> INSERT INTO tbl_name (idate) VALUES ('97-05-05');
mysql> INSERT INTO tbl_name (idate) VALUES ('1997.05.05');
mysql> INSERT INTO tbl_name (idate) VALUES ('1997 05 05');
mysql> INSERT INTO tbl_name (idate) VALUES ('0000-00-00');
mysql> SELECT idate FROM tbl_name WHERE idate >= '1997-05-05';
mysql> SELECT idate FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT MOD(idate,100) FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT idate FROM tbl_name WHERE idate >= '19970505';
浣嗘槸锛屼笅杩拌鍙ヤ笉鑳芥甯稿伐浣滐細
mysql> SELECT idate FROM tbl_name WHERE STRCMP(idate,'20030505')=0;
STRCMP()鏄竴绉嶅瓧绗︿覆鍑芥暟锛屽畠鑳藉皢idate杞崲涓'YYYY-MM-DD'鏍煎紡鐨勫瓧绗︿覆锛骞舵墽琛屽瓧绗︿覆姣旇緝銆傚畠涓嶈兘灏'20030505'杞崲涓鏃ユ湡'2003-05-05'骞惰繘琛屾棩鏈熸瘮杈冦
濡傛灉浣犳鍦ㄤ娇鐢ALLOW_INVALID_DATES SQL妯″紡锛MySQL鍏佽浠ヤ粎鎵ц缁欏畾鐨勬湁闄愭鏌ユ柟寮忎繚瀛樻棩鏈燂細MySQL浠呬繚璇佸ぉ浣嶄簬1锝31鐨勮寖鍥村唴锛屾湀浣嶄簬1锝12鐨勮寖鍥村唴銆
杩欐牱灏变娇寰MySQL寰堥傚悎浜Web搴旂敤绋嬪簭锛屽叾涓紝浣犺兘鑾峰緱涓変釜涓嶅悓瀛楁涓殑骞淬佹湀銆佹棩鍊硷紝涔熻兘鍑嗙‘淇濆瓨鐢ㄦ埛鎻掑叆鐨勫硷紙鏃犳棩鏈熼獙璇侊級銆
濡傛灉鏈娇鐢NO_ZERO_IN_DATE SQL妯″紡锛屸滃ぉ鈥濆拰鈥滄湀鈥濋儴鍒嗗彲鑳戒负0銆傚鏋滀綘鎵撶畻灏嗙敓鏃ヤ繚瀛樺湪DATE鍒楄屼笖浠呯煡閬撻儴鍒嗘棩鏈燂紝瀹冨崄鍒嗘柟渚裤
濡傛灉鏈娇鐢NO_ZERO_DATE SQL妯″紡锛MySQL涔熷厑璁镐綘灏'0000-00-00'淇濆瓨涓衡滀吉鏃ユ湡鈥濄傚湪鏌愪簺鎯呭喌涓嬶紝瀹冩瘮浣跨敤NULL鍊兼洿鏂逛究銆
濡傛灉鏃犳硶灏嗘棩鏈熻浆鎹负浠讳綍鍚堢悊鍊硷紝鈥0鈥濆皢淇濆瓨鍦DATE鍒椾腑锛屽苟琚绱负'0000-00-00'銆傝繖鏄吋椤鹃熷害鍜屼究鍒╂х殑浜嬪疁銆傛垜浠涓猴紝鏁版嵁搴撴湇鍔″櫒鐨勮亴璐f槸妫绱笌浣犱繚瀛樼殑鏃ユ湡鐩稿悓鐨勬棩鏈锛堝嵆浣垮湪浠讳綍鎯呭喌涓嬶紝鏁版嵁鍦ㄩ昏緫涓婁笉姝g‘涔熷悓鏍凤級銆傛垜浠涓猴紝瀵规棩鏈熺殑妫鏌ュ簲鐢卞簲鐢ㄧ▼搴忚屼笉鏄湇鍔″櫒璐熻矗銆
濡傛灉浣犲笇鏈MySQL妫鏌ユ墍鏈夋棩鏈熷苟浠呮帴鍙楀悎娉曟棩鏈燂紙闄ら潪鐢IGNORE瑕嗙洊锛夛紝搴斿皢sql_mode璁剧疆涓"NO_ZERO_IN_DATE,NO_ZERO_DATE"銆
瀵逛簬SQL鐨勬柊鎵嬶紝NULL鍊肩殑姒傚康甯稿父浼氶犳垚娣锋穯锛屼粬浠父璁や负NULL鏄笌绌哄瓧绗︿覆''鐩稿悓鐨勪簨銆鎯呭喌骞堕潪濡傛銆備緥濡傦紝涓嬭堪璇彞鏄畬鍏ㄤ笉鍚岀殑锛
mysql> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ('');
杩欎袱鏉¤鍙ュ潎浼氬皢鍊兼彃鍏phone锛堢數璇濓級鍒楋紝浣嗙1鏉¤鍙ユ彃鍏ョ殑鏄NULL鍊硷紝绗2鏉¤鍙ユ彃鍏ョ殑鏄┖瀛楃涓层傜1绉嶆儏鍐电殑鍚箟鍙瑙i噴涓衡滅數璇濆彿鐮佹湭鐭モ濓紝鑰岀2绉嶆儏鍐电殑鍚箟鍙瑙i噴涓衡滆浜哄憳娌℃湁鐢佃瘽锛屽洜姝ゆ病鏈夌數璇濆彿鐮佲濄
涓轰簡杩涜NULL澶勭悊锛屽彲浣跨敤IS NULL鍜IS NOT NULL鎿嶄綔绗︿互鍙IFNULL()鍑芥暟銆
鍦SQL涓紝NULL鍊涓庝换浣曞叾瀹冨肩殑姣旇緝锛堝嵆浣挎槸NULL锛夋案杩滀笉浼氫负鈥滅湡鈥濄傚寘鍚NULL鐨勮〃杈惧紡鎬绘槸浼氬鍑NULL鍊硷紝闄ら潪鍦ㄥ叧浜庢搷浣滅鐨勬枃妗d腑浠ュ強琛ㄨ揪寮忕殑鍑芥暟涓綔浜嗗叾浠栬瀹氥備笅杩扮ず渚嬩腑鐨勬墍鏈夊垪鍧囪繑鍥NULL锛
mysql> SELECT NULL, 1+NULL, CONCAT('Invisible',NULL);
濡傛灉鎵撶畻鎼滅储鍒楀间负NULL鐨勫垪锛屼笉鑳戒娇鐢expr = NULL娴嬭瘯銆備笅杩拌鍙ヤ笉杩斿洖浠讳綍琛岋紝杩欐槸鍥犱负锛屽浜庝换浣曡〃杈惧紡锛expr = NULL姘歌繙涓嶄负鈥鐪鈥锛
mysql> SELECT * FROM my_table WHERE phone = NULL;
瑕佹兂鏌ユ壘NULL鍊硷紝蹇呴』浣跨敤IS NULL娴嬭瘯銆鍦ㄤ笅闈㈢殑璇彞涓紝浠嬬粛浜嗘煡鎵NULL鐢佃瘽鍙风爜鍜岀┖鐢佃瘽鍙风爜鐨勬柟寮忥細
mysql> SELECT * FROM my_table WHERE phone IS NULL;
mysql> SELECT * FROM my_table WHERE phone = '';
鏇村淇℃伅鍜岀ず渚嬶紝璇峰弬瑙3.3.4.6鑺傦紝鈥滀娇鐢∟ULL鍊尖銆
濡傛灉浣犳鍦ㄤ娇鐢MyISAM銆InnoDB銆BDB銆佹垨MEMORY瀛樺偍寮曟搸锛岃兘澶熷湪鍙兘鍏锋湁NULL鍊肩殑鍒椾笂澧炲姞1鏉$储寮曘傚涓嶇劧锛屽繀椤诲0鏄庣储寮曞垪涓NOT NULL锛岃屼笖涓嶈兘灏NULL鎻掑叆鍒板垪涓
鐢LOAD DATA INFILE璇诲彇鏁版嵁鏃讹紝瀵逛簬绌虹殑鎴栦涪澶辩殑鍒楋紝灏嗙敤''鏇存柊瀹冧滑銆傚鏋滃笇鏈涘湪鍒椾腑鍏锋湁NULL鍊硷紝搴斿湪鏁版嵁鏂囦欢涓娇鐢\N銆傚湪鏌愪簺鎯呭喌涓嬶紝涔熷彲浠ヤ娇鐢ㄦ枃瀛楁у崟璇嶁NULL鈥濄傝鍙傝13.2.5 鈥LOAD DATA INFILE璇硶鈥銆
浣跨敤DISTINCT銆GROUP BY鎴ORDER BY鏃讹紝鎵鏈NULL鍊煎皢琚涓虹瓑鍚岀殑銆
浣跨敤ORDER BY鏃讹紝棣栧厛灏嗘樉绀NULL鍊硷紝濡傛灉鎸囧畾浜DESC鎸夐檷搴忔帓鍒楋紝NULL鍊煎皢鏈鍚庢樉绀恒
瀵逛簬鑱氬悎锛堢疮璁★級鍑芥暟锛屽COUNT()銆MIN()鍜SUM()锛屽皢蹇界暐NULL鍊笺瀵规鐨勪緥澶栨槸COUNT(*)锛屽畠灏嗚鏁拌鑰屼笉鏄崟鐙殑鍒楀笺備緥濡傦紝涓嬭堪璇彞浜х敓涓や釜璁℃暟銆傞鍏堣鏁拌〃涓殑琛屾暟锛屽叾娆¤鏁age鍒椾腑鐨勯潪NULL鍊兼暟鐩細
mysql> SELECT COUNT(*), COUNT(age) FROM person;
瀵逛簬鏌愪簺鍒楃被鍨嬶紝MySQL灏嗗NULL鍊艰繘琛岀壒娈婂鐞嗐傚鏋滃皢NULL鎻掑叆TIMESTAMP鍒楋紝灏嗘彃鍏ュ綋鍓嶆棩鏈熷拰鏃堕棿銆傚鏋滃皢NULL鎻掑叆鍏锋湁AUTO_INCREMENT灞炴х殑鏁存暟鍒楋紝灏嗘彃鍏ュ簭鍒椾腑鐨勪笅涓涓紪鍙枫
SELECT SQRT(a*b) AS root FROM tbl_name GROUP BY root HAVING root > 0;
SELECT id, COUNT(*) AS cnt FROM tbl_name GROUP BY id HAVING cnt > 0;
SELECT id AS 'Customer identity' FROM tbl_name;
鏍囧噯SQL涓嶅厑璁稿湪WHERE瀛愬彞涓凡鐢ㄥ垪鍒悕銆傝繖鏄洜涓猴紝鎵цWHERE浠g爜鏃讹紝鍙兘灏氭湭纭畾鍒楀笺備緥濡傦紝涓嬭堪鏌ヨ鏄潪娉曠殑锛
SELECT id, COUNT(*) AS cnt FROM tbl_name WHERE cnt > 0 GROUP BY id;
鎵цWHERE璇彞浠ョ‘瀹鍝簺琛屽簲琚寘鍚湪GROUP BY閮ㄥ垎涓紝鑰HAVING鐢ㄤ簬纭畾搴斾娇鐢ㄧ粨鏋滈泦涓殑鍝簺琛屻
鎵цROLLBACK锛堝洖婊氾級鏃讹紝濡傛灉鏀跺埌涓嬭堪娑堟伅锛岃〃绀轰簨鍔′腑浣跨敤鐨1涓垨澶氫釜琛ㄤ笉鏀寔浜嬪姟锛
璀﹀憡锛氭煇浜涙洿鏀圭殑闈炰簨鍔℃ц〃涓嶈兘琚洖婊氥
杩欎簺闈炰簨鍔℃ц〃涓嶅彈ROLLBACK璇彞鐨勫奖鍝嶃
濡傛灉鍦ㄤ簨鍔′腑鎰忓鍦版贩鍚堜簡浜嬪姟鎬ц〃鍜岄潪浜嬪姟鎬ц〃锛屽鑷磋娑堟伅鐨勬渶鍙兘鍘熷洜鏄紝浣犺涓烘湰搴旀槸浜嬪姟鎬х殑琛ㄥ疄闄呬笂涓嶆槸銆傚浣犺瘯鍥句娇鐢mysqld鏈嶅姟鍣ㄤ笉鏀寔鐨勪簨鍔℃у瓨鍌ㄥ紩鎿庯紙鎴栫敤鍚姩閫夐」绂佹浜嗗畠锛夊垱寤鸿〃锛屽氨鍙兘鍑虹幇璇ユ儏鍐点傚鏋mysqld涓嶆敮鎸佸瓨鍌ㄥ紩鎿庯紝瀹冨皢浠MyISAM琛ㄥ垱寤鸿〃锛岃繖鏄潪浜嬪姟鎬ц〃銆
鍙娇鐢ㄤ笅杩拌鍙ヤ箣涓妫鏌ヨ〃鐨勬爣绫诲瀷锛
SHOW TABLE STATUS LIKE 'tbl_name';
SHOW CREATE TABLE tbl_name;
璇峰弬瑙13.5.4.18鑺傦紝鈥淪HOW TABLE STATUS璇硶浠ュ強13.5.4.5鑺傦紝鈥淪HOW CREATE TABLE璇硶鈥銆
浣跨敤涓嬭堪璇彞锛屽彲妫鏌mysqld鏈嶅姟鍣ㄦ敮鎸佺殑瀛樺偍寮曟搸锛
SHOW ENGINES;
涔熷彲浠ヤ娇鐢ㄤ笅杩拌鍙ワ紝妫鏌ヤ笌浣犳劅鍏磋叮鐨勫瓨鍌ㄥ紩鎿庢湁鍏崇殑鍙橀噺鍊硷細
SHOW VARIABLES LIKE 'have_%';
渚嬪锛岃鎯崇‘瀹InnoDB瀛樺偍寮曟搸鏄惁鍙敤锛屽彲妫鏌have_innodb鍙橀噺鐨勫笺
璇峰弬瑙13.5.4.8鑺傦紝鈥淪HOW ENGINES璇硶鈥鍜13.5.4.21鑺傦紝鈥淪HOW VARIABLES璇硶鈥銆
濡傛灉鏈変娇鐢ㄤ簡寰堝琛ㄧ殑澶嶆潅鏌ヨ锛屼絾鏈繑鍥炰换浣曡锛屽簲閲囩敤涓嬭堪姝ラ鎵惧嚭浠涔堝嚭閿欙細
鐢EXPLAIN娴嬭瘯鏌ヨ锛屼互妫鏌鏄惁鍙戠幇鏌愪簨鏄剧劧鍑洪敊銆傝鍙傝7.2.1鑺傦紝鈥淓XPLAIN璇硶锛堣幏鍙栧叧浜嶴ELECT鐨勪俊鎭級鈥銆
浠呴夋嫨鍦WHERE瀛愬彞涓娇鐢ㄧ殑鍒椼
浠庢煡璇腑1娆″垹闄1涓〃锛岀洿鑷宠繑鍥炰簡鏌愪簺琛屼负姝€傚鏋滆〃寰堝ぇ锛岃緝濂界殑涓绘剰鏄湪鏌ヨ涓娇鐢LIMIT 10銆
瀵逛簬鍏锋湁涓庝笂娆′粠鏌ヨ涓垹闄ょ殑琛ㄥ尮閰嶇殑琛岀殑鍒楋紝鍙戝嚭SELECT鏌ヨ銆
濡傛灉灏FLOAT鎴DOUBLE鍒椾笌鍏锋湁鏁板肩被鍨嬬殑鏁板艰繘琛屾瘮杈冿紝涓嶈兘浣跨敤绛夊紡(=)姣旇緝銆傚湪澶у鏁拌绠楁満璇█涓紝璇ラ棶棰樺緢甯歌锛岃繖鏄洜涓猴紝骞堕潪鎵鏈夌殑娴偣鍊煎潎鑳戒互鍑嗙‘鐨勭簿搴︿繚瀛樸傚湪鏌愪簺鎯呭喌涓嬶紝灏FLOAT鏇存敼涓DOUBLE鍙洿姝h闂銆璇峰弬瑙A.5.8鑺傦紝鈥滀笌娴偣姣旇緝鏈夊叧鐨勯棶棰樷銆
濡傛灉浠嶄笉鑳芥壘鍑洪棶棰樹箣鎵鍦紝璇峰垱寤鸿兘涓庢樉绀洪棶棰樼殑鈥mysql test < query.sql鈥濅竴璧疯繍琛岀殑鏈灏忔祴璇曘傞氳繃浣跨敤mysqldump --quick db_name tbl_name_1 ... tbl_name_n > query.sql杞偍琛紝鍙垱寤烘祴璇曟枃浠躲傚湪缂栬緫鍣ㄤ腑鎵撳紑鏂囦欢锛屽垹闄ゆ煇浜涙彃鍏ョ殑琛岋紙濡傛灉鏈夎秴鍑烘紨绀洪棶棰樻墍闇鐨勮锛夛紝骞跺湪鏂囦欢鏈熬娣诲姞SELECT璇彞銆
閫氳繃鎵ц涓嬭堪鍛戒护锛岄獙璇佹祴璇曟枃浠惰兘婕旂ず闂锛
shell> mysqladmin create test2
shell> mysql test2 < query.sql
浣跨敤mysqlbug灏嗘祴璇曟枃浠跺紶璐村埌鍝熷閫氱敤MySQL閭欢鍒楄〃銆傝鍙傝1.7.1.1鑺傦紝鈥淭he MySQL閭欢鍒楄〃鈥銆
娴偣鏁版湁鏃朵細瀵艰嚧娣锋穯锛岃繖鏄洜涓哄畠浠棤娉曚互鍑嗙‘鍊间繚瀛樺湪璁$畻鏈轰綋绯荤粨鏋勪腑銆備綘鍦ㄥ睆骞曚笂鎵鐪嬪埌鐨勫奸氬父涓嶆槸鏁板肩殑鍑嗙‘鍊笺傚浜FLOAT鍜DOUBLE鍒楃被鍨嬶紝鎯呭喌灏辨槸濡傛銆DECIMAL鍒楄兘淇濆瓨鍏锋湁鍑嗙‘绮惧害鐨勫硷紝杩欐槸鍥犱负瀹冧滑鏄敱瀛楃涓茶〃绀虹殑銆
鍦ㄤ笅闈㈢殑绀轰緥涓紝浠嬬粛浜嗕娇鐢DOUBLE鏃剁殑闂锛
mysql> CREATE TABLE t1 (i INT, d1 DOUBLE, d2 DOUBLE);
mysql> INSERT INTO t1 VALUES (1, 101.40, 21.40), (1, -80.00, 0.00),
-> (2, 0.00, 0.00), (2, -13.20, 0.00), (2, 59.60, 46.40),
-> (2, 30.40, 30.40), (3, 37.00, 7.40), (3, -29.60, 0.00),
-> (4, 60.00, 15.40), (4, -10.60, 0.00), (4, -34.00, 0.00),
-> (5, 33.00, 0.00), (5, -25.80, 0.00), (5, 0.00, 7.20),
-> (6, 0.00, 0.00), (6, -51.40, 0.00);
mysql> SELECT i, SUM(d1) AS a, SUM(d2) AS b
-> FROM t1 GROUP BY i HAVING a <> b;
+------+-------+------+
| i | a | b |
+------+-------+------+
| 1 | 21.4 | 21.4 |
| 2 | 76.8 | 76.8 |
| 3 | 7.4 | 7.4 |
| 4 | 15.4 | 15.4 |
| 5 | 7.2 | 7.2 |
| 6 | -51.4 | 0 |
+------+-------+------+
缁撴灉鏄纭殑銆傚敖绠″墠5涓褰曠湅涓婂幓涓嶅簲鑳借繘琛屾瘮杈冩祴璇曪紙a鍜b鐨勫肩湅涓婂幓娌℃湁浠涔堜笉鍚岋級锛屼絾瀹冧滑鑳借繘琛屾瘮杈冿紝杩欐槸鍥犱负鏄剧ず鐨勬暟鍊奸棿鐨勫樊寮傚湪鍗佸垎浣嶅乏鍙筹紝鍏蜂綋鎯呭喌鍙栧喅浜庤绠楁満鐨勪綋绯荤粨鏋勩
濡傛灉鍒d1鍜d2瀹氫箟涓DECIMAL鑰屼笉鏄DOUBLE锛SELECT鏌ヨ鐨勭粨鏋滀粎鍖呭惈1琛岋紝鍗充笂闈㈡樉绀虹殑鏈鍚1琛屻
MySQL閲囩敤浜嗗熀浜庡紑閿鐨勪紭鍖栧櫒锛屼互纭畾澶勭悊鏌ヨ鐨勬渶瑙f柟寮忋傚湪寰堝鎯呭喌涓嬶紝MySQL鑳藉璁$畻鏈浣崇殑鍙兘鏌ヨ璁″垝锛屼絾鍦ㄦ煇浜涙儏鍐典笅锛MySQL娌℃湁鍏充簬鏁版嵁鐨勮冻澶熶俊鎭紝涓嶅緱涓嶅氨鏁版嵁杩涜鈥滄湁鏁欏吇鈥濈殑浼版祴銆
褰MySQL鏈兘鍋氣滄纭殑鈥濅簨鏃讹紝鍙娇鐢ㄤ笅杩板伐鍏锋潵甯姪MySQL锛
浣跨敤EXPLAIN璇彞鑾峰彇鍏充簬MySQL濡備綍澶勭悊鏌ヨ鐨勪俊鎭傝鎯充娇鐢ㄥ畠锛屽彲鍦SELECT璇彞鍓嶆坊鍔犲叧閿瓧EXPLAIN锛
mysql> EXPLAIN SELECT * FROM t1, t2 WHERE t1.i = t2.i;
鍏充簬EXPLAIN鐨勮缁嗚璁猴紝璇峰弬瑙7.2.1鑺傦紝鈥淓XPLAIN璇硶锛堣幏鍙栧叧浜嶴ELECT鐨勪俊鎭級鈥銆
浣跨敤ANALYZE TABLE tbl_name锛屼负宸叉壂鎻忕殑琛ㄦ洿鏂伴敭鍒嗛厤銆傝鍙傝13.5.2.1鑺傦紝鈥淎NALYZE TABLE璇硶鈥銆
涓哄凡鎵弿鐨勮〃浣跨敤FORCE INDEX锛岄氱煡MySQL锛氫笌浣跨敤缁欏畾鐨勭储寮曠浉姣旓紝琛ㄦ壂鎻忓紑閿鏄傝吹銆傝鍙傝13.2.7鑺傦紝鈥淪ELECT璇硶鈥銆
SELECT * FROM t1, t2 FORCE INDEX (index_for_column)
WHERE t1.col_name=t2.col_name;
USE INDEX鍜IGNORE INDEX涔熸湁涓瀹氱殑甯姪銆
鍏充簬鍏ㄥ眬鍜岃〃绾у埆鐨STRAIGHT_JOIN銆傝鍙傝13.2.7鑺傦紝鈥淪ELECT璇硶鈥銆
浣犲彲浠ヨ皟鑺傚叏灞鎴栫嚎绋嬬被绯荤粺鍙橀噺銆備緥濡傦紝鐢ㄢ--max-seeks-for-key=1000鈥閫夐」鍚姩mysqld锛屾垨浣跨敤鈥淪ET max_seeks_for_key=1000鈥鏉ラ氱煡浼樺寲鍣細鍋囧畾浠讳綍琛ㄦ壂鎻忓潎涓嶄細瀵艰嚧1000涓互涓婄殑閿悳绱€璇峰弬瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆
ALTER TABLE灏嗚〃鏇存敼涓哄綋鍓嶅瓧绗﹂泦銆傚鏋滃湪鎵цALTER TABLE鎿嶄綔鏈熼棿閬囧埌閲嶅閿敊璇紝鍘熷洜鍦ㄤ簬鏂扮殑瀛楃闆嗗皢2涓敭鏄犲皠鍒颁簡鐩稿悓鍊硷紝鎴栨槸琛ㄥ凡鎹熷潖銆傚湪鍚庝竴绉嶆儏鍐典笅锛屽簲鍦ㄨ〃涓婅繍琛REPAIR TABLE銆
濡傛灉ALTER TABLE澶辫触骞剁粰鍑轰笅杩伴敊璇紝闂鍙兘鏄洜涓哄湪ALTER TABLE鎿嶄綔鐨勬棭鏈熼樁娈靛嚭鐜MySQL宕╂簝锛屾病鏈夊悕涓A-xxx鎴B-xxx鐨勬棫琛細
Error on rename of './database/name.frm'
to './database/B-xxx.frm' (Errcode: 17)
鍦ㄨ鎯呭喌涓嬶紝杩涘叆MySQL鏁版嵁鐩綍锛屽苟鍒犻櫎鍏跺悕绉颁负浠A-鎴B-寮濮嬬殑鎵鏈夋枃浠锛堟垨璁镐綘甯屾湜灏嗗畠浠Щ鍔ㄥ埌鍏朵粬鍦版柟鑰屼笉鏄垹闄ゅ畠浠級銆
ALTER TABLE鐨勫伐浣滄柟寮忓涓嬶細
濡傛灉鍦ㄩ噸鍛藉悕鎿嶄綔涓嚭閿欙紝MySQL灏嗗皾璇曟挙閿鏇存敼銆傚鏋滈敊璇緢涓ラ噸锛堝敖绠¤繖涓嶅簲鍑虹幇锛夛紝MySQL浼氬皢鏃ц〃淇濈暀涓B-xxx銆傜畝鍗曞湴鍦ㄧ郴缁熺骇鍒笂閲嶅懡鍚嶈〃鏂囦欢锛屽簲鑳戒娇鏁版嵁澶嶅師銆
濡傛灉鍦ㄤ簨鍔℃ц〃涓婁娇鐢ALTER TABLE锛屾垨姝e湪浣跨敤Windows鎴OS/2鎿嶄綔绯荤粺锛屽鏋滃凡鍦ㄨ〃涓婃墽琛屼簡LOCK TABLE鎿嶄綔锛ALTER TABLE灏嗗琛ㄦ墽琛岃В閿佹搷浣溿傝繖鏄洜涓InnoDB鍜岃繖绫绘搷浣滅郴缁熶笉鑳芥挙閿姝e湪浣跨敤鐨勮〃銆
棣栧厛锛岃鑰冭檻鏄惁鐨勭‘闇瑕佹洿鏀硅〃涓殑鍒楅『搴忋SQL鐨勬牳蹇冭鐐规槸浠庢暟鎹瓨鍌ㄦ牸寮忚幏鍙栧簲鐢ㄣ傛诲簲鎸囧畾妫绱㈡暟鎹殑椤哄簭銆傚湪涓嬮潰鐨勭1鏉¤鍙ヤ腑锛屼互col_name1銆col_name2銆col_name3椤哄簭杩斿洖鍒楋紱鍦ㄧ2鏉¤鍙ヤ腑锛屼互col_name1銆col_name3銆col_name2椤哄簭杩斿洖鍒楋細
mysql> SELECT col_name1, col_name2, col_name3 FROM tbl_name;
mysql> SELECT col_name1, col_name3, col_name2 FROM tbl_name;
濡傛灉鍐冲畾鏇存敼琛ㄥ垪鐨勯『搴忥紝鍙墽琛屼笅杩版搷浣滐細
mysql> INSERT INTO new_table
-> SELECT columns-in-new-order FROM old_table;
mysql> ALTER TABLE new_table RENAME old_table;
SELECT *鍗佸垎閫傚悎浜庢祴璇曟煡璇€備絾鏄紝鍦ㄥ簲鐢ㄧ▼搴忎腑锛屾案杩滀笉瑕佷緷璧SELECT *鐨勪娇鐢紝涓嶈渚濊禆鏍规嵁鍏朵綅缃绱㈠垪銆傚鏋滄坊鍔犮佺Щ鍔ㄦ垨鍒犻櫎浜嗗垪锛屾墍杩斿洖鐨勫垪鐨勯『搴忓拰浣嶇疆涓嶄細淇濇寔鐩稿悓銆傚琛ㄧ粨鏋勭殑绠鍗曟洿鏀逛篃浼氬鑷村簲鐢ㄧ▼搴忓け璐ャ
涓嬮潰浠嬬粛浜嗗浣跨敤TEMPORARY琛ㄧ殑闄愬埗锛
mysql> SELECT * FROM temp_table, temp_table AS t2;
閿欒1137锛氫笉鑳藉啀娆℃墦寮琛細'temp_table'
mysql> ALTER TABLE orig_name RENAME new_name;
鍦ㄦ湰鑺備腑锛屽垪鍑轰簡褰撳墠MySQL鐗堟湰涓殑宸茬煡浜嬪疁銆
鍏充簬骞冲彴鐩稿叧浜嬪疁鐨勬洿澶氫俊鎭紝璇峰弬瑙2.12鑺傦紝鈥滃叿浣撴搷浣滅郴缁熺浉鍏崇殑娉ㄦ剰浜嬮」鈥鍜闄勫綍E锛绉绘鍒板叾浠栫郴缁涓殑瀹夎鍜岀Щ妞嶈鏄庛
涓嬮潰鍒楀嚭浜嗗凡鐭ラ棶棰橈紝鏇存瀹冧滑鍏锋湁杈冮珮鐨勪紭鍏堢骇锛
001207 22:07:56 bdb: log_flush: LSN past current end-of-log
濡傛灉浠ョ壒瀹氱殑鏂瑰紡璁捐鏌ヨ锛屼娇寰楁暟鎹洿鏀规槸闈炲喅瀹氭э紙閫氬父涓嶆帹鑽愶紝鍗充娇鍦ㄥ鍒朵箣澶栦篃鍚屾牱锛夛紝涓绘湇鍔″櫒鍜屼粠鏈嶅姟鍣ㄤ笂鐨勬暟鎹皢鍙樺緱涓嶅悓銆
渚嬪锛
- 灏0鎴朜ULL鍊兼彃鍏UTO_INCREMENT鍒椾腑鐨凜REATE ... SELECT鎴朓NSERT ... SELECT璇彞銆
- DELETE锛屽鏋滀粠鍏锋湁ON DELETE CASCADE灞炴х殑澶栭敭鐨勮〃涓垹闄よ銆
- REPLACE ... SELECT銆両NSERT IGNORE ... SELECT锛屽鏋滃湪鎻掑叆鐨勬暟鎹腑鍏锋湁閲嶅閿
褰撲笖浠呭綋鍓嶈堪鏌ヨ娌℃湁淇濊瘉鍐冲畾琛岄『搴忕殑ORDER BY瀛愬彞鏃躲
渚嬪锛屽浜庝笉鍏锋湁ORDER BY鐨INSERT ... SELECT锛SELECT鍙兘浼氫互涓嶅悓鐨勯『搴忚繑鍥炶锛堝畠浼氬鑷村叿鏈変笉鍚岀瓑绾х殑琛岋紝浠庤屽鑷AUTO_INCREMENT鍒椾腑鐨勪笉鍚屾暟鍊硷級锛屽叿浣撴儏鍐靛彇鍐充簬浼樺寲鍣ㄥ湪涓绘湇鍔″櫒鍜屼粠鏈嶅姟鍣ㄤ笂鎵浣滅殑閫夋嫨銆
鍦ㄤ富鏈嶅姟鍣ㄥ拰浠庢湇鍔″櫒涓婏紝鏌ヨ灏嗚繘琛屼笉鍚岀殑浼樺寲锛屼粎褰擄細
- 浣跨敤涓嶅悓鐨勫瓨鍌ㄥ紩鎿庡湪涓绘湇鍔″櫒涓婅屼笉鏄粠鏈嶅姟鍣ㄤ笂淇濆瓨琛ㄣ傦紙鑳藉鍦ㄤ富鏈嶅姟鍣ㄥ拰浠庢湇鍔″櫒涓婁娇鐢ㄤ笉鍚岀殑瀛樺偍寮曟搸銆備緥濡傦紝濡傛灉浠庢湇鍔″櫒鍏锋湁杈冨皯鐨勫彲鐢ㄧ鐩樼┖闂达紝鍙互鍦ㄤ富鏈嶅姟鍣ㄤ笂浣跨敤InnoDB锛屼絾鍦 浠庢湇鍔″櫒妗戜娇鐢MyISAM锛夈
- 鍦ㄤ富鏈嶅姟鍣ㄥ拰浠庢湇鍔″櫒涓婏紝MySQL缂撳啿鍖哄ぇ灏忔槸涓嶅悓鐨勶紙key_buffer_size绛夛級銆
- 鍦ㄤ富鏈嶅姟鍣ㄥ拰浠庢湇鍔″櫒涓婅繍琛屼笉鍚岀殑MySQL鐗堟湰锛岀増鏈棿鐨勪紭鍖栧櫒浠g爜涔熶笉鍚屻
璇ラ棶棰樹篃浼氬奖鍝嶄娇鐢mysqlbinlog|mysql鐨勬暟鎹簱鎭㈠銆
閬垮厤璇ラ棶棰樼殑鏈绠鍗曟柟娉曟槸锛屼负鍓嶈堪鐨勯潪鍐冲畾鎬ф煡璇㈠鍔ORDER BY瀛愬彞锛屼互纭繚鎬绘槸浠ョ浉鍚岀殑椤哄簭淇濆瓨鎴栨洿鏀硅銆
鍦ㄥ皢鏉ョ殑MySQL鐗堟湰涓紝闇瑕佹椂锛屾垜浠皢鑷姩澧炲姞ORDER BY瀛愬彞銆
涓嬮潰鍒楀嚭浜嗗凡鐭ョ殑浜嬪疁锛岃繖浜涗簨瀹滃皢鍦ㄦ伆褰撶殑鏃跺欐洿姝o細
mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
mysql> SELECT * FROM temp_table, temp_table AS t2;
閿欒1137锛氫笉鑳藉啀娆℃墦寮琛細'temp_table'
渚嬪锛
SELECT DISTINCT mp3id FROM band_downloads
WHERE userid = 9 ORDER BY id DESC;
浠ュ強
SELECT DISTINCT band_downloads.mp3id
FROM band_downloads,band_mp3
WHERE band_downloads.userid = 9
AND band_mp3.id = band_downloads.mp3id
ORDER BY band_downloads.id DESC;
鍦ㄧ2绉嶆儏鍐典笅锛屼娇鐢MySQL鏈嶅姟鍣3.23.x锛屽彲鍦ㄧ粨鏋滈泦涓幏寰2涓瓑鍚岃锛堣繖鏄洜涓猴紝闅愯棌ID鍒椾腑鐨勫煎彲鑳戒笉鍚岋級銆
娉ㄦ剰锛屽湪缁撴灉闆嗕腑锛屼粎瀵逛笉鍚ORDER BY鍒楃殑鏌ヨ鎵嶄細鍑虹幇璇ユ儏鍐点
杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com銆傚師濮嬪弬鑰冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆