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

Chapter聽5.聽Database Administration - MySQL 5.1参考手册中文版

绗5绔狅細鏁版嵁搴撶鐞

鐩綍

5.1. MySQL鏈嶅姟鍣ㄥ拰鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈
5.1.1. 鏈嶅姟鍣ㄧ鑴氭湰鍜屽疄鐢ㄥ伐鍏锋杩
5.1.2. mysqld-max鎵╁睍MySQL鏈嶅姟鍣
5.1.3. mysqld_safe锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈
5.1.4. mysql.server锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈
5.1.5. mysqld_multi锛氱鐞嗗涓狹ySQL鏈嶅姟鍣ㄧ殑绋嬪簭
5.2. mysqlmanager锛歁ySQL瀹炰緥绠$悊鍣
5.2.1. 鐢∕ySQL瀹炰緥绠$悊鍣ㄥ惎鍔∕ySQL鏈嶅姟鍣
5.2.2. 杩炴帴鍒癕ySQL瀹炰緥绠$悊鍣ㄥ苟鍒涘缓鐢ㄦ埛璐︽埛
5.2.3. MySQL瀹炰緥绠$悊鍣ㄥ懡浠よ閫夐」
5.2.4. MySQL瀹炰緥绠$悊鍣ㄩ厤缃枃浠
5.2.5. MySQL瀹炰緥绠$悊鍣ㄨ瘑鍒殑鍛戒护
5.3. mysqld锛歁ySQL鏈嶅姟鍣
5.3.1. mysqld鍛戒护琛岄夐」
5.3.2. SQL鏈嶅姟鍣ㄦā寮
5.3.3. 鏈嶅姟鍣ㄧ郴缁熷彉閲
5.3.4. 鏈嶅姟鍣ㄧ姸鎬佸彉閲
5.4. mysql_fix_privilege_tables锛氬崌绾ySQL绯荤粺琛
5.5. MySQL鏈嶅姟鍣ㄥ叧鏈鸿繘绋
5.6. 涓鑸畨鍏ㄩ棶棰
5.6.1. 閫氱敤瀹夊叏鎸囧崡
5.6.2. 浣縈ySQL鍦ㄦ敾鍑昏呴潰鍓嶄繚鎸佸畨鍏
5.6.3. Mysqld瀹夊叏鐩稿叧鍚姩閫夐」
5.6.4. LOAD DATA LOCAL瀹夊叏闂
5.7. MySQL璁块棶鏉冮檺绯荤粺
5.7.1. 鏉冮檺绯荤粺鐨勪綔鐢
5.7.2. 鏉冮檺绯荤粺宸ヤ綔鍘熺悊
5.7.3. MySQL鎻愪緵鐨勬潈闄
5.7.4. 涓嶮ySQL鏈嶅姟鍣ㄨ繛鎺
5.7.5. 璁块棶鎺у埗, 闃舵1锛氳繛鎺ユ牳瀹
5.7.6. 璁块棶鎺у埗, 闃舵2锛氳姹傛牳瀹
5.7.7. 鏉冮檺鏇存敼浣曟椂鐢熸晥
5.7.8. 鎷掔粷璁块棶閿欒鐨勫師鍥
5.7.9. MySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊
5.8. MySQL鐢ㄦ埛璐︽埛绠$悊
5.8.1. MySQL鐢ㄦ埛鍚嶅拰瀵嗙爜
5.8.2. 鍚慚ySQL澧炲姞鏂扮敤鎴疯处鎴
5.8.3. 浠嶮ySQL鍒犻櫎鐢ㄦ埛璐︽埛
5.8.4. 闄愬埗璐︽埛璧勬簮
5.8.5. 璁剧疆璐︽埛瀵嗙爜
5.8.6. 浣夸綘鐨勫瘑鐮佸畨鍏
5.8.7. 浣跨敤瀹夊叏杩炴帴
5.9. 澶囦唤涓庢仮澶
5.9.1. 鏁版嵁搴撳浠
5.9.2. 绀轰緥鐢ㄥ浠戒笌鎭㈠绛栫暐
5.9.3. 鑷姩鎭㈠
5.9.4. 琛ㄧ淮鎶ゅ拰宕╂簝鎭㈠
5.9.5. myisamchk锛歁yISAM琛ㄧ淮鎶ゅ疄鐢ㄥ伐鍏
5.9.6. 寤虹珛琛ㄧ淮鎶よ鍒
5.9.7. 鑾峰彇鍏充簬琛ㄧ殑淇℃伅
5.10. MySQL鏈湴鍖栧拰鍥介檯搴旂敤
5.10.1. 鏁版嵁鍜屾帓搴忕敤瀛楃闆
5.10.2. 璁剧疆閿欒娑堟伅璇█
5.10.3. 娣诲姞鏂扮殑瀛楃闆
5.10.4. 瀛楃瀹氫箟鏁扮粍
5.10.5. 瀛楃涓叉瘮杈冩敮鎸
5.10.6. 澶氬瓧鑺傚瓧绗︽敮鎸
5.10.7. 瀛楃闆嗛棶棰
5.10.8. MySQL鏈嶅姟鍣ㄦ椂鍖烘敮鎸
5.11. MySQL鏃ュ織鏂囦欢
5.11.1. 閿欒鏃ュ織
5.11.2. 閫氱敤鏌ヨ鏃ュ織
5.11.3. 浜岃繘鍒舵棩蹇
5.11.4. 鎱㈤熸煡璇㈡棩蹇
5.11.5. 鏃ュ織鏂囦欢缁存姢
5.12. 鍦ㄥ悓涓鍙版満鍣ㄤ笂杩愯澶氫釜MySQL鏈嶅姟鍣
5.12.1. 鍦╓indows涓嬭繍琛屽涓湇鍔″櫒
5.12.2. 鍦║nix涓繍琛屽涓湇鍔″櫒
5.12.3. 鍦ㄥ鏈嶅姟鍣ㄧ幆澧冧腑浣跨敤瀹㈡埛绔▼搴
5.13. MySQL鏌ヨ楂橀熺紦鍐
5.13.1. 鏌ヨ楂橀熺紦鍐插浣曞伐浣
5.13.2. 鏌ヨ楂橀熺紦鍐睸ELECT閫夐」
5.13.3. 鏌ヨ楂橀熺紦鍐查厤缃
5.13.4. 鏌ヨ楂橀熺紦鍐茬姸鎬佸拰缁存姢

鏈珷娑电洊浜MySQL瀹夎绠$悊涓婚锛屼緥濡傞厤缃湇鍔″櫒銆佺鐞嗙敤鎴疯处鎴峰拰澶囦唤銆

5.1. MySQL鏈嶅姟鍣ㄥ拰鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈

MySQL鏈嶅姟鍣紝鍗mysqld锛屾槸鍦MySQL瀹夎涓礋璐eぇ閮ㄥ垎宸ヤ綔鐨勪富绋嬪簭銆傛湇鍔″櫒闅忛檮浜嗗嚑涓浉鍏宠剼鏈紝褰撲綘瀹夎MySQL鏃跺畠浠彲浠ユ墽琛岃缃搷浣滐紝鎴栬呮槸甯姪浣犲惎鍔ㄥ拰鍋滄鏈嶅姟鍣ㄧ殑甯姪绋嬪簭銆

鏈妭鎻愪緵浜嗘湇鍔″櫒鍜岀浉鍏崇▼搴忕殑姒傝堪锛屼互鍙婃湇鍔″櫒鍚姩鑴氭湰鐩稿叧淇℃伅銆傚叧浜庨厤缃湇鍔″櫒鐨勪俊鎭弬瑙5.3鑺傦紝鈥渕ysqld锛歁ySQL鏈嶅姟鍣ㄢ

5.1.1. 鏈嶅姟鍣ㄧ鑴氭湰鍜屽疄鐢ㄥ伐鍏锋杩

MySQL绋嬪簭閲囩敤鍚勭涓嶅悓鐨勯夐」銆備絾姣忎釜MySQL绋嬪簭鎻愪緵涓涓--help閫夐」,浣犲彲浠ョ敤鏉ユ煡闃呯▼搴忛夐」鐩稿叧璇存槑銆備緥濡傦紝浣犲彲浠ヨ瘯璇mysqld --help

浣犲彲浠ュ湪鍛戒护琛屼腑鎴栧湪閫夐」鏂囦欢涓寚瀹氶夐」鏉ユ浛鎹㈡墍鏈夋爣鍑嗙▼搴忎腑鐨勯粯璁ら夐」銆傚弬瑙4.3鑺傦紝鈥滄寚瀹氱▼搴忛夐」鈥

涓嬮潰绠鍗曟弿杩颁簡MySQL鏈嶅姟鍣ㄥ拰鏈嶅姟鍣ㄧ浉鍏崇▼搴忥細

         mysqld

SQL鍚庡彴绋嬪簭(MySQL鏈嶅姟鍣)銆傝鎯充娇鐢ㄥ鎴风绋嬪簭锛岃绋嬪簭蹇呴』杩愯锛屽洜涓哄鎴风閫氳繃杩炴帴鏈嶅姟鍣ㄦ潵璁块棶鏁版嵁搴撱傚弬瑙5.3鑺傦紝鈥渕ysqld锛歁ySQL鏈嶅姟鍣ㄢ

         mysqld-max

鍖呮嫭鏇村鐗规х殑涓涓湇鍔″櫒鐗堟湰銆傚弬瑙5.1.2鑺傦紝鈥渕ysqld-max鎵╁睍MySQL鏈嶅姟鍣ㄢ

         mysqld_safe

鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈傚鏋mysqld-max瀛樺湪,mysqld_safe璇曞浘鍚姩瀹冿紝鍚﹀垯鍚姩mysqld銆傚弬瑙5.1.3鑺傦紝鈥渕ysqld_safe锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈

         mysql.server

鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈傝鑴氭湰鐢ㄤ簬浣跨敤鍖呭惈涓虹壒瀹氱骇鍒殑杩愯鍚姩鏈嶅姟鐨勮剼鏈殑杩愯鐩綍鐨勭郴缁熴傚畠璋冪敤mysqld_safe鏉ュ惎鍔MySQL鏈嶅姟鍣ㄣ傚弬瑙5.1.4鑺傦紝鈥渕ysql.server锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈

         mysqld_multi

鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈紝鍙互鍚姩鎴栧仠姝㈢郴缁熶笂瀹夎鐨勫涓湇鍔″櫒銆傚弬瑙5.1.5鑺傦紝鈥渕ysqld_multi锛氱鐞嗗涓狹ySQL鏈嶅姟鍣ㄧ殑绋嬪簭鈥

         mysql_install_db

璇ヨ剼鏈敤榛樿鏉冮檺鍒涘缓MySQL鎺堟潈琛ㄣ傞氬父鍙槸鍦ㄧ郴缁熶笂棣栨瀹夎MySQL鏃舵墽琛屼竴娆°傚弬瑙2.9.2鑺傦紝鈥淯nix涓嬪畨瑁呭悗鐨勮繃绋嬧

         mysql_fix_ privilege_tables

鍦ㄥ崌绾у畨瑁呭悗锛屽鏋滄柊鐗堟湰MySQL涓殑 鎺堟潈琛ㄦ湁鏇存敼锛屽垯浣跨敤璇ヨ剼鏈潵鏇存敼鎺堟潈琛ㄣ傚弬瑙2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥

鏈嶅姟鍣ㄤ富鏈轰笂杩樿繍琛屽叾瀹冨嚑涓▼搴忥細

         myisamchk

鐢ㄦ潵鎻忚堪銆佹鏌ャ佷紭鍖栧拰缁存姢MyISAM琛ㄧ殑瀹炵敤宸ュ叿銆傚湪5.9.5鑺傦紝鈥渕yisamchk锛歁yISAM琛ㄧ淮鎶ゅ疄鐢ㄥ伐鍏封涓弿杩颁簡myisamchk

         make_binary_distribution

璇ョ▼搴忓彲浠ョ敓鎴愮紪璇戣繃鐨MySQL鐨勪簩杩涘埗鐗堟湰銆傚彲浠ラ氳繃FTP涓婁紶鍒ftp.mysql.com/pub/mysql/upload/锛屼緵鍏跺畠MySQL鐢ㄦ埛浣跨敤銆

         mysqlbug

MySQL 缂洪櫡鎶ュ憡鑴氭湰銆傚畠鍙互鐢ㄦ潵鍚MySQL閭欢绯荤粺鍙戦佺己闄锋姤鍛娿(浣犱篃鍙互璁块棶http://bugs.mysql.com/鍦ㄧ嚎鍒涘缓缂洪櫡鎶ュ憡鏂囦欢銆傚弬瑙1.7.1.3鑺傦紝鈥滃浣曢氭姤缂洪櫡鍜岄棶棰樷

5.1.2. mysqld-max鎵╁睍MySQL鏈嶅姟鍣

MySQL-Max鏈嶅姟鍣ㄦ槸mysqld MySQL鏈嶅姟鍣ㄧ殑涓涓増鏈紝鍖呭惈浜嗘洿澶氱殑鐗规с

璇ュ垎鍙戠増鐨勪娇鐢ㄥ彇鍐充簬浣犵殑骞冲彴锛

         瀵逛簬WindowsMySQL浜岃繘鍒跺垎鍙戠増鍖呮嫭鏍囧噯鏈嶅姟鍣 (mysqld.exe)MySQL-Max鏈嶅姟鍣(mysqld-max.exe)锛屽洜姝や綘涓嶅啀闇瑕佷笓鐢ㄥ垎鍙戠増銆傚彧闇瑕佷娇鐢ㄤ竴涓父瑙Windows鍒嗗彂鐗堬紝鍙互浠http://dev.mysql.com/downloads/鑾峰緱銆傚弬瑙2.3鑺傦紝鈥滃湪Windows涓婂畨瑁匨ySQL鈥

         瀵逛簬Linux锛屽鏋滀綘浣跨敤RPM鍒嗗彂鐗堝畨瑁MySQL锛岄鍏堜娇鐢ㄥ父瑙MySQL-server RPM鏉ュ畨瑁呮爣鍑mysqld鏈嶅姟鍣ㄣ傜劧鍚庝娇鐢MySQL-Max RPM鏉ュ畨瑁mysqld-max鏈嶅姟鍣ㄣMySQL-Max RPM鍋囧畾浣犲凡缁忓畨瑁呬簡甯歌鏈嶅姟鍣RPM銆傚叧浜Linux RPM杞欢鍖呯殑璇︾粏淇℃伅锛屽弬瑙2.4鑺傦紝鈥滃湪Linux涓嬪畨瑁匨ySQL鈥

         鎵鏈夊叾瀹MySQL-Max鍒嗗彂鐗堝寘鍚竴涓mysqld鏈嶅姟鍣紝浣嗗叿鏈夋洿澶氱殑鐗规с

浣犲彲浠ヤ粠MySQL AB缃戝潃http://dev.mysql.com/downloads/鎵惧埌MySQL-Max浜岃繘鍒剁増鏈

MySQL AB浣跨敤涓嬮潰鐨configure閫夐」鏋勫缓MySQL-Max鏈嶅姟鍣細

         --with-server-suffix=-max

璇ラ夐」涓mysqld鐗堟湰瀛楃涓叉坊鍔犱竴涓-max鍚庣紑銆

         --with-innodb

璇ラ夐」鍚敤InnoDB瀛樺偍寮曟搸鏀寔銆MySQL-Max鏈嶅姟鍣ㄥ寘鎷InnoDB鏀寔銆傚湪MySQL 4.0鍙婁互涓婄増鏈腑锛岄粯璁InnoDB鍖呮嫭鍦ㄦ墍鏈変簩杩涘埗鍒嗗彂鐗堜腑锛屽洜姝や綘涓嶉渶瑕佺敤MySQL-Max鏈嶅姟鍣ㄥ彧鏄敤鏉ヨ幏鍙InnoDB鏀寔銆

         --with-bdb

璇ラ夐」鍚敤Berkeley DB (BDB)瀛樺偍寮曟搸鏀寔銆

         --with-blackhole-storage-engine

璇ラ夐」鍚敤BLACKHOLE瀛樺偍寮曟搸鏀寔銆

         USE_SYMDIR

鍚敤璇ュ畾涔夋潵涓Windows鎵撳紑鏁版嵁搴撶鍙烽摼鎺ユ敮鎸併傜鍙烽摼鎺ユ敮鎸侀傜敤浜庢墍鏈Windows鏈嶅姟鍣紝鍥犳Max鏈嶅姟鍣ㄤ笉闇瑕佹敮鎸佽鐗规с

         --with-ndbcluster

璇ラ夐」鍚敤NDB Cluster瀛樺偍寮曟搸鏀寔銆傜洰鍓(5.1.2-alpha)鍙湁LinuxSolarisMac OS X鏀寔Cluster銆傚凡鏈変竴浜涚敤鎴锋姤鍛婂湪BSD 鎿嶄綔绯荤粺涓婃垚鍔熶娇鐢ㄤ簡浠庢簮鐮佹瀯寤虹殑MySQL Cluster锛屼絾鐩墠杩樻病鏈夊緱鍒板畼鏂规敮鎸併

MySQL-Max浜岃繘鍒跺垎鍙戠増瀵逛簬鎯宠瀹夎棰勭紪璇戠▼搴忕殑鐢ㄦ埛寰堟柟渚裤傚鏋滀綘浣跨敤婧愮爜鍒嗗彂鐗堟瀯寤MySQL锛屼綘鍙互閫氳繃鍦ㄩ厤缃椂鍚敤MySQL-Max浜岃繘鍒跺垎鍙戠増鏋勫缓鎵鐢ㄧ殑鐩稿悓鐨勭壒鎬ф潵鏋勫缓浣犺嚜宸辩殑Max-like鏈嶅姟鍣ㄣ

MySQL-Max鏈嶅姟鍣ㄥ寘鎷BerkeleyDB (BDB)瀛樺偍寮曟搸锛屼絾骞堕潪鎵鏈夊钩鍙版敮鎸BDB

SolarisMac OS XLinux(鍦ㄥぇ澶氭暟骞冲彴涓)MySQL-Max鏈嶅姟鍣ㄥ寘鎷NDB CLUSTER瀛樺偍寮曟搸鏀寔銆傝娉ㄦ剰蹇呴』鐢ndbcluster閫夐」鍚姩鏈嶅姟鍣紝浠ヤ究浣挎湇鍔″櫒鍋氫负MySQL Cluster鐨勪竴閮ㄥ垎鏉ヨ繍琛屻(璇︾粏淇℃伅鍙傝17.4鑺傦紝鈥淢ySQL绨囩殑閰嶇疆鈥

涓嬮潰鐨勮〃鏄剧ず浜MySQL-Max浜岃繘鍒跺湪鍝釜骞冲彴涓婂寘鎷BDB/NDB CLUSTER鏀寔锛

绯荤粺

BDB鏀寔

NDB鏀寔

AIX 4.3

N

N

HP-UX 11.0

N

N

Linux-Alpha

N

Y

Linux-IA-64

N

N

Linux-Intel

Y

Y

Mac OS X

N

N

NetWare

N

N

SCO OSR5

Y

N

Solaris-SPARC

Y

Y

Solaris-Intel

N

Y

UnixWare

Y

N

Windows NT/2000/XP

Y

N

瑕佹兂鎵惧嚭浣犵殑鏈嶅姟鍣ㄦ敮鎸佸摢涓瓨鍌ㄥ紩鎿庯紝鎵ц涓嬮潰鐨勮鍙ワ細

mysql> SHOW ENGINES;
+------------+---------+----------------------------------------------------------------+
| Engine     | Support | Comment                                                        |
+------------+---------+----------------------------------------------------------------+
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      |
| HEAP       | YES     | Alias for MEMORY                                               |
| MERGE      | YES     | Collection of identical MyISAM tables                          |
| MRG_MYISAM | YES     | Alias for MERGE                                                |
| ISAM       | NO      | Obsolete storage engine, now replaced by MyISAM                |
| MRG_ISAM   | NO      | Obsolete storage engine, now replaced by MERGE                 |
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys     |
| INNOBASE   | YES     | Alias for INNODB                                               |
| BDB        | YES     | Supports transactions and page-level locking                   |
| BERKELEYDB | YES     | Alias for BDB                                                  |
| NDBCLUSTER | NO      | Clustered, fault-tolerant, memory-based tables                 |
| NDB        | NO      | Alias for NDBCLUSTER                                           |
| EXAMPLE    | NO      | Example storage engine                                         |
| ARCHIVE    | YES     | Archive storage engine                                         |
| CSV        | NO      | CSV storage engine                                             |
| FEDERATED  | YES     | Federated MySQL storage engine                                 |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) |
+------------+---------+----------------------------------------------------------------+
18 rows in set (0.00 sec)

(鍙﹀弬瑙13.5.4.8鑺傦紝鈥淪HOW ENGINES璇硶鈥

浣犺繕鍙互浣跨敤涓嬮潰鐨勮鍙ヤ唬鏇SHOW ENGINES锛屽苟妫鏌ヤ綘鎰熷叴瓒g殑瀛樺偍寮曟搸鐨勫彉閲忓硷細

mysql> SHOW VARIABLES LIKE 'have%';
+-----------------------+----------+
| Variable_name         | Value    |
+-----------------------+----------+
| have_archive          | YES      |
| have_bdb              | NO       |
| have_blackhole_engine | YES      |
| have_compress         | YES      |
| have_crypt            | YES      |
| have_csv              | YES      |
| have_example_engine   | NO       |
| have_federated_engine | NO       |
| have_geometry         | YES      |
| have_innodb           | YES      |
| have_isam             | NO       |
| have_ndbcluster       | DISABLED |
| have_openssl          | NO       |
| have_partition_engine | YES      |
| have_query_cache      | YES      |
| have_raid             | NO       |
| have_rtree_keys       | YES      |
| have_symlink          | YES      |
+-----------------------+----------+
18 rows in set (0.01 sec)

SHOW鍛戒护鐨勭簿纭緭鍑洪殢浣跨敤鐨MySQL鐗堟湰(鍜屽惎鐢ㄧ殑鐗规)鐨勪笉鍚岃屾湁鍙樺寲銆傜2鍒楃殑鍊艰〃绀哄悇鐗规ф敮鎸佺殑鏈嶅姟鍣ㄧ骇鍒紝濡備笅鎵绀猴細

鍚箟

YES

 鏀寔璇ョ壒鎬у苟宸茬粡婵娲汇

NO

 涓嶆敮鎸佽鐗规с

DISABLED

 鏀寔璇ョ壒鎬т絾琚鐢ㄣ

NO鍊艰〃绀虹紪璇戠殑鏈嶅姟鍣ㄤ笉鏀寔璇ョ壒鎬э紝鍥犳鍦ㄨ繍琛屾椂涓嶈兘婵娲汇

鍑虹幇DISABLED鍊兼槸鍥犱负鏈嶅姟鍣ㄥ惎鍔ㄦ椂璇ョ壒鎬ц绂佺敤锛屾垨娌℃湁缁欏嚭鍚敤瀹冪殑鎵鏈夐夐」銆傚湪鍚庝竴绉嶆儏鍐碉紝host_.err閿欒鏃ュ織鏂囦欢搴斿寘鍚閫夐」琚鐢ㄧ殑鍘熷洜銆

濡傛灉鏈嶅姟鍣ㄦ敮鎸InnoDBBDB瀛樺偍寮曟搸锛屼綘杩樺彲浠ョ湅瑙DISABLED锛屼絾鍦ㄨ繍琛屽惎鍔ㄦ椂浣跨敤浜--skip-innodb--skip-bdb閫夐」銆傚浜NDB CLUSTER瀛樺偍寮曟搸锛DISABLED琛ㄧず鏈嶅姟鍣ㄦ敮鎸MySQL Cluster锛屼絾鍚姩鏃舵湭鍚敤--ndb-cluster閫夐」銆

鎵鏈MySQL鏈嶅姟鍣ㄦ敮鎸MyISAM琛紝鍥犱负MyISAM鏄 榛樿瀛樺偍寮曟搸銆

5.1.3. mysqld_safe锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈

UnixNetWare涓帹鑽愪娇鐢mysqld_safe鏉ュ惎鍔mysqld鏈嶅姟鍣mysqld_safe澧炲姞浜嗕竴浜涘畨鍏ㄧ壒鎬э紝渚嬪褰撳嚭鐜伴敊璇椂閲嶅惎鏈嶅姟鍣ㄥ苟鍚戦敊璇棩蹇楁枃浠跺啓鍏ヨ繍琛屾椂闂翠俊鎭傛湰鑺傚悗闈㈠垪鍑轰簡NetWare鐨勭壒瀹氳涓恒

閲婏細涓轰簡淇濇寔鍚屾棫鐗堟湰MySQL鐨勫悜鍚庡吋瀹规э紝MySQL浜岃繘鍒跺垎鍙戠増浠嶇劧鍖呮嫭safe_mysqld浣滀负mysqld_safe鐨勭鍙烽摼鎺ャ備絾鏄紝浣犱笉搴斿啀渚濊禆瀹冿紝鍥犱负鍐嶅皢鏉ュ皢鍒犳帀瀹冦

榛樿鎯呭喌涓嬶紝mysqld_safe灏濊瘯鍚姩鍙墽琛mysqld-max锛堝鏋滃瓨鍦級锛屽惁鍒欏惎鍔mysqld銆傝琛屼负鐨勫惈涔夋槸锛

         Linux涓紝MySQL-Max RPM渚濊禆璇mysqld_safe鐨勮涓恒RPM瀹夎鍙墽琛mysqld-max锛屼娇mysqld_safe浠庤鐐硅捣鑷姩浣跨敤鍙墽琛屽懡浠ゃ

         濡傛灉浣犲畨瑁呭寘鎷mysqld-max鏈嶅姟鍣ㄧ殑MySQL-Max鍒嗗彂鐗堬紝鍚庨潰鍗囩骇鍒伴潪-MaxMySQL鐗堟湰锛mysqld_safe浠嶇劧璇曞浘杩愯鏃х殑 mysqld-max鏈嶅姟鍣銆傚崌绾ф椂锛屼綘搴旀墜鍔ㄥ垹闄ゆ棫鐨mysqld-max鏈嶅姟鍣浠ョ‘淇mysqld_safe杩愯鏂扮殑mysqld鏈嶅姟鍣

瑕佹兂瓒婅繃榛樿琛屼负骞舵樉寮忔寚瀹氫綘鎯宠杩愯鍝釜鏈嶅姟鍣紝涓mysqld_safe鎸囧畾--mysqld--mysqld-version閫夐」銆

mysqld_safe鐨勮澶氶夐」涓mysqld鐨勭浉鍚岀殑銆傚弬瑙5.3.1鑺傦紝鈥mysqld鍛戒护琛岄夐」鈥

鎵鏈夊湪鍛戒护琛屼腑涓mysqld_safe鎸囧畾鐨勯夐」琚紶閫掔粰mysqld濡傛灉浣犳兂瑕佷娇鐢mysqld涓嶆敮鎸佺殑mysqld_safe閫夐」锛屼笉瑕佸湪鍛戒护琛屼腑鎸囧畾銆傜浉鍙嶏紝鍦ㄩ夐」鏂囦欢鐨[mysqld_safe]缁勫唴灏嗗畠浠垪鍑烘潵銆傚弬瑙4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥

mysqld_safe浠庨夐」鏂囦欢鐨[mysqld][server][mysqld_safe]閮ㄥ垎璇诲彇鎵鏈夐夐」銆備负浜嗕繚璇佸悜鍚庡吋瀹规э紝瀹冭繕璇诲彇 [safe_mysqld]閮ㄥ垎锛屽敖绠″湪MySQL 5.1瀹夎涓綘搴斿皢杩欓儴鍒嗛噸鏂板懡鍚嶄负[mysqld_safe]

mysqld_safe鏀寔涓嬮潰鐨勯夐」锛

         --help

鏄剧ず甯姪娑堟伅骞堕鍑恒

         --autoclose

(鍙湪NetWare)NetWare涓紝mysqld_safe鍙互淇濇寔绐楀彛銆傚綋浣犲叧鎺mysqld_safe NLM鏃讹紝绐楀彛涓嶆寜榛樿璁剧疆娑堝け銆傜浉鍙嶏紝瀹冩彁绀虹敤鎴疯緭鍏ワ細

*<NLM has terminated; Press any key to close the screen>*

濡傛灉浣犳兂璁NetWare鑷姩鍏抽棴绐楀彛锛屽湪mysqld_safe涓娇鐢--autoclose閫夐」銆

         --basedir=path

MySQL瀹夎鐩綍鐨勮矾寰勩

         --core-file-size=size

mysqld鑳藉鍒涘缓鐨勫唴鏍告枃浠剁殑澶у皬銆傞夐」鍊间紶閫掔粰ulimit -c

         --datadir=path

鏁版嵁鐩綍鐨勮矾寰勩

           --defaults-extra-file=path

闄や簡閫氱敤閫夐」鏂囦欢鎵璇诲彇鐨勯夐」鏂囦欢鍚嶃傚鏋滅粰鍑猴紝蹇呴』棣栭夎閫夐」銆

         --defaults-file=path

璇诲彇鐨勪唬鏇块氱敤閫夐」鏂囦欢鐨勯夐」鏂囦欢鍚嶃傚鏋滅粰鍑猴紝蹇呴』棣栭夎閫夐」銆

         --ledir=path

鍖呭惈mysqld绋嬪簭鐨勭洰褰曠殑璺緞銆備娇鐢ㄨ閫夐」鏉ユ樉寮忚〃绀烘湇鍔″櫒浣嶇疆銆

         --log-error=path

灏嗛敊璇棩蹇楀啓鍏ョ粰瀹氱殑鏂囦欢銆傚弬瑙5.11.1鑺傦紝鈥滈敊璇棩蹇椻

         --mysqld=prog_name

鎯宠鍚姩鐨勬湇鍔″櫒绋嬪簭鍚(ledir鐩綍)銆傚鏋滀綘浣跨敤MySQL浜岃繘鍒跺垎鍙戠増浣嗘湁浜岃繘鍒跺垎鍙戠増涔嬪鐨勬暟鎹洰褰曢渶瑕佽閫夐」銆

         --mysqld-version =suffix

璇ラ夐」绫讳技--mysqld閫夐」锛屼絾浣犲彧鎸囧畾鏈嶅姟鍣ㄧ▼搴忓悕鐨勫悗缂銆傚熀鏈悕鍋囧畾涓mysqld渚嬪锛屽鏋滀綘浣跨敤--mysqld-version =maxmysqld_safe鍚姩ledir鐩綍涓殑mysqld-max绋嬪簭銆傚鏋--mysqld-version鐨勫弬鏁颁负绌猴紝mysqld_safe浣跨敤鐩綍涓殑mysqld

         --nice=priority

浣跨敤nice绋嬪簭鏍规嵁缁欏畾鍊兼潵璁剧疆鏈嶅姟鍣ㄧ殑璋冨害浼樺厛绾с

         --no-defaults

涓嶈璇讳换浣曢夐」鏂囦欢銆傚鏋滅粰鍑猴紝蹇呴』棣栭夎閫夐」銆

         --open-files-limit=count

mysqld鑳藉鎵撳紑鐨勬枃浠剁殑鏁伴噺銆傞夐」鍊间紶閫掔粰 ulimit -n銆傝娉ㄦ剰浣犻渶瑕佺敤root鍚姩mysqld_safe鏉ヤ繚璇佹纭伐浣滐紒

         --pid-file=path

杩涚▼ID鏂囦欢鐨勮矾寰勩

         --port=port_num

 鐢ㄦ潵甯у惉TCP/IP杩炴帴鐨勭鍙e彿銆傜鍙e彿蹇呴』涓1024鎴栨洿澶у硷紝闄ら潪MySQLroot绯荤粺鐢ㄦ埛杩愯銆

         --skip-character-set-client-handshake

蹇界暐瀹㈡埛绔彂閫佺殑瀛楃闆嗕俊鎭紝浣跨敤鏈嶅姟鍣ㄧ殑榛樿瀛楃闆嗐(閫夋嫨璇ラ夐」锛MySQL鐨勫姩浣滀笌MySQL 4.0鐩稿悓锛

         --socket=path

鐢ㄤ簬鏈湴杩炴帴鐨Unix濂楁帴瀛楁枃浠躲

         --timezone=zone

涓虹粰瀹氱殑閫夐」鍊艰缃TZ鏃跺尯鐜鍙橀噺銆備粠鎿嶄綔绯荤粺鏂囨。鏌ラ槄鍚堟硶鐨勬椂鍖鸿瀹氭牸寮忋

         --user={user_name | user_id}

浠ョ敤鎴峰悕user_name鎴栨暟瀛楃敤鎴ID user_id杩愯mysqld鏈嶅姟鍣(鏈枃涓殑鈥鐢ㄦ埛鈥濇寚绯荤粺鐧诲綍璐︽埛锛岃屼笉鏄 鎺堟潈琛ㄤ腑鐨MySQL鐢ㄦ埛锛

鎵цmysqld_safe鏃讹紝蹇呴』鍏堢粰鍑--defaults-file--defaults-extra-option锛屾垨涓嶄娇鐢ㄩ夐」鏂囦欢銆備緥濡傦紝璇ュ懡浠ゅ皢涓嶄娇鐢ㄩ夐」鏂囦欢锛

mysqld_safe --port=port_num --defaults-file=file_name

鐩稿弽锛屼娇鐢ㄤ笅闈㈢殑鍛戒护锛

mysqld_safe --defaults-file=file_name --port=port_num

涓鑸儏鍐mysqld_safe鑴氭湰鍙互鍚姩浠庢簮鐮佹垨浜岃繘鍒MySQL鍒嗗彂鐗堝畨瑁呯殑鏈嶅姟鍣紝鍗充娇杩欎簺鍒嗗彂鐗堝皢鏈嶅姟鍣ㄥ畨瑁呭埌绋嶅井涓嶅悓鐨勪綅缃(鍙傝2.1.5鑺傦紝鈥滃畨瑁呭竷灞鈥 mysqld_safe鏈熸湜涓嬮潰鐨勫叾涓竴涓潯浠舵槸鐪熺殑锛

         鍙互鏍规嵁璋冪敤mysqld_safe鐨勭洰褰曟壘鍒版湇鍔″櫒鍜屾暟鎹簱銆傚湪浜岃繘鍒跺垎鍙戠増涓紝mysqld_safe鐪嬩笂鍘诲湪bindata鐩綍鐨勫伐浣滅洰褰曚笅銆傚浜庢簮鐮佸垎鍙戠増锛屼负libexecvar鐩綍銆傚鏋滀綘浠MySQL瀹夎鐩綍鎵цmysqld_safe搴旀弧瓒宠鏉′欢(渚嬪锛屼簩杩涘埗鍒嗗彂鐗堜负/usr/local/mysql)

         濡傛灉涓嶈兘鏍规嵁宸ヤ綔鐩綍鎵惧埌鏈嶅姟鍣ㄥ拰鏁版嵁搴擄紝mysqld_safe璇曞浘閫氳繃缁濆璺緞瀵瑰畠浠畾浣嶃傚吀鍨嬩綅缃负/usr/local/libexec/usr/local/var銆傚疄闄呬綅缃敱鏋勫缓鍒嗗彂鐗堟椂閰嶇疆鐨勫肩‘瀹氬鏋MySQL瀹夎鍒伴厤缃椂鎸囧畾鐨勪綅缃紝瀹冧滑搴旇鏄纭殑銆

鍥犱负mysqld_safe璇曞浘閫氳繃宸ヤ綔鐩綍鎵惧埌鏈嶅姟鍣ㄥ拰鏁版嵁搴擄紝鍙浣犱粠MySQL瀹夎鐩綍杩愯mysqld_safe鍙互灏MySQL浜岃繘鍒跺垎鍙戠増瀹夎鍒板叾瀹冧綅缃細

shell> cd mysql_installation_directory
shell> bin/mysqld_safe &

濡傛灉mysqld_safe澶辫触锛屽嵆浣夸粠MySQL瀹夎鐩綍璋冪敤浠嶇劧澶辫触锛屼綘鍙互鎸囧畾--ledir--datadir閫夐」鏉ユ寚绀烘湇鍔″櫒鍜屾暟鎹簱鍦ㄤ綘鐨勭郴缁熶腑鐨勫畨瑁呯洰褰曘

涓鑸儏鍐碉紝浣犱笉搴旂紪杈mysqld_safe鑴氭湰銆傜浉鍙嶏紝搴斾娇鐢ㄥ懡浠よ閫夐」鎴my.cnf閫夐」鏂囦欢鐨[mysqld_safe]閮ㄥ垎鐨勯夐」鏉ラ厤缃mysqld_safe銆備竴鑸笉闇瑕佺紪杈mysqld_safe鏉ユ纭惎鍔ㄦ湇鍔″櫒銆備絾鏄紝濡傛灉浣犵紪杈戯紝灏嗘潵鍗囩骇MySQL鍚庝細瑕嗙洊浣犱慨鏀圭殑mysqld_safe鐗堟湰锛屽洜姝や綘搴斿浣犱慨鏀圭殑鐗堟湰杩涜澶囦唤浠ヤ究灏嗘潵閲嶈銆

NetWare涓紝mysqld_safe鏄竴涓NetWare Loadable Module (NLM)锛屼粠鍘Unix shell鑴氭湰绉绘銆傚畠鎵ц锛

1.    妫鏌ョ郴缁熷拰閫夐」銆

2.    妫鏌MyISAM琛ㄣ

3.    淇濇寔MySQL鏈嶅姟鍣ㄧ獥鍙c

4.    鍚姩骞剁洃瑙mysqld锛屽鏋滃洜閿欒缁堟鍒欓噸鍚

5.    mysqld閿欒娑堟伅鍙戦佸埌鏁版嵁鐩綍涓殑host_name.err 鏂囦欢銆

6.    mysqld_safe鐨勫睆骞曡緭鍑哄彂閫佸埌鏁版嵁鐩綍涓殑host_name.safe鏂囦欢銆

5.1.4. mysql.server锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈

Unix涓殑MySQL鍒嗗彂鐗堝寘鎷mysql.server鑴氭湰銆傚畠鍙互鐢ㄤ簬浣跨敤System V-style杩愯鐩綍鏉ュ惎鍔ㄥ拰鍋滄绯荤粺鏈嶅姟鐨勭郴缁燂紝渚嬪LinuxSolaris銆傚畠杩樼敤浜MySQLMac OS X Startup Item

mysql.server浣嶄簬MySQL婧愮爜鏍MySQL瀹夎鐩綍涓嬬殑support-files鐩綍涓

濡傛灉浣犱娇鐢Linux 鏈嶅姟鍣RPM杞欢鍖(MySQL-server-VERSION.rpm)mysql.server鑴氭湰灏嗗畨瑁呭埌/etc/init.d鐩綍涓嬶紝鍚嶄负mysql銆備綘涓嶉渶瑕 鎵嬪姩瀹夎銆傚叧浜Linux RPM杞欢鍖呯殑璇︾粏淇℃伅鍙傝2.4鑺傦紝鈥滃湪Linux涓嬪畨瑁匨ySQL鈥

涓浜涘崠鏂规彁渚涚殑RPM杞欢鍖呭畨瑁呯殑鍚姩鑴氭湰鐢ㄥ叾瀹冨悕锛屼緥濡mysqld

濡傛灉浣犱粠涓嶈嚜鍔ㄥ畨瑁mysql.server鐨勬簮鐮佸垎鍙戠増鎴栦簩杩涘埗鍒嗗彂鐗堟牸寮忓畨瑁MySQL锛屼篃鍙互鎵嬪姩瀹夎銆傜浉鍏宠鏄庡弬瑙2.9.2.2鑺傦紝鈥滆嚜鍔ㄥ惎鍔ㄥ拰鍋滄MySQL鈥

mysql.server[mysql.server]鍜岄夐」鏂囦欢鐨[mysqld]閮ㄥ垎璇诲彇閫夐」銆(涓轰簡淇濊瘉鍚戝悗鍏煎鎬э紝瀹冭繕璇诲彇 [safe_mysqld]閮ㄥ垎锛屽敖绠″湪MySQL 5.1瀹夎涓綘搴斿皢杩欓儴鍒嗛噸鏂板懡鍚嶄负[mysqld_safe]

5.1.5. mysqld_multi锛氱鐞嗗涓狹ySQL鏈嶅姟鍣ㄧ殑绋嬪簭

mysqld_multi鍙互绠$悊澶氫釜甯у惉涓嶅悓Unix濂楁帴瀛楁枃浠跺拰TCP/IP绔彛鐨勮繛鎺ョ殑mysqld 杩涚▼銆傚畠鍙互鍚姩鎴栧仠姝㈡湇鍔″櫒锛屾垨鎶ュ憡瀹冧滑鐨勫綋鍓嶇姸鎬併

绋嬪簭瀵绘壘my.cnf涓殑[mysqldN](--config-file閫夐」鎸囧畾鐨勬枃浠)N 鍙互涓轰换浣曟鏁存暟銆傚湪涓嬮潰鐨勮璁轰腑璇ユ暟瀛楁寚閫夐」缁勫彿锛屾垨GNR銆傜粍鍙峰尯鍒悇閫夐」缁勶紝骞剁敤浣mysqld_multi鐨勫弬鏁版潵鎸囧畾鎯宠鍚姩銆佸仠姝㈠摢涓湇鍔″櫒鎴栬幏鍙栧摢涓湇鍔″櫒鐨勭姸鎬佹姤鍛娿傝繖浜涚粍涓殑閫夐」涓庡皢鐢ㄦ潵鍚姩mysqld[mysqld]缁勪腑鐨勭浉鍚屻(渚嬪锛屽弬瑙2.9.2.2鑺傦紝鈥滆嚜鍔ㄥ惎鍔ㄥ拰鍋滄MySQL鈥浣嗘槸锛屽綋浣跨敤澶氫釜鏈嶅姟鍣ㄦ椂锛岄渶瑕佹瘡涓湇鍔″櫒浣跨敤鑷繁鐨勯夐」鍊硷紝渚嬪Unix濂楁帴瀛楁枃浠跺拰TCP/IP绔彛鍙枫傚叧浜庡湪澶氭湇鍔″櫒鐜涓紝姣忎釜鏈嶅姟鍣ㄥ搴斿敮涓閫夐」鐨勮缁嗕俊鎭紝鍙傝5.12鑺傦紝鈥滃湪鍚屼竴鍙版満鍣ㄤ笂杩愯澶氫釜MySQL鏈嶅姟鍣ㄢ

瑕佹兂璋冪敤mysqld_multi锛屼娇鐢ㄤ笅闈㈢殑璇硶锛

shell> mysqld_multi [options] {start|stop|report} [GNR[,GNR] ...]

startstopreport琛ㄧず浣犳兂瑕佹墽琛岀殑鎿嶄綔銆備綘鍙互鍦ㄥ崟涓湇鍔″櫒鎴栧涓湇鍔″櫒涓婃墽琛屾寚瀹氱殑鎿嶄綔锛屽彇鍐充簬閫夐」鍚嶅悗闈㈢殑GNR 鍒椼傚鏋滄病鏈夎鍒楋紝mysqld_multi涓洪夐」鏂囦欢涓殑鎵鏈夋湇鍔″櫒鎵ц璇ユ搷浣溿

姣忎釜GNR鍊间唬琛ㄤ竴涓夐」缁勫彿鎴栫粍鍙疯寖鍥淬GNR鍊煎簲涓洪夐」鏂囦欢涓粍鍚嶆湯灏剧殑鍙枫備緥濡傦紝缁[mysqld17]GNR17銆傝鎯虫寚瀹氱粍鍙风殑鑼冨洿锛岀敤鐮存姌鍙烽棿闅斿紑绗1涓拰鏈鍚1涓彿銆GNR10-13浠h〃缁[mysqld10][mysqld13]銆傚彲浠ュ湪鍛戒护琛屼腑鎸囧畾澶氫釜缁勬垨缁勮寖鍥达紝鐢ㄩ楀彿闂撮殧寮銆GNR鍒椾笉鑳芥湁绌烘牸瀛楃(绌烘牸鎴tab)锛涚┖鏍煎瓧绗﹀悗闈㈢殑鍐呭灏嗚蹇界暐鎺夈

璇ュ懡浠や娇鐢ㄩ夐」缁[mysqld17]鍚姩鍗曚釜鏈嶅姟鍣細

shell> mysqld_multi start 17

璇ュ懡浠ゅ仠姝㈠涓湇鍔″櫒锛屼娇鐢ㄩ夐」缁[mysql8][mysqld10][mysqld13]

shell> mysqld_multi stop 8,10-13

浣跨敤璇ュ懡浠ゅ垪鍑鸿缃夐」鏂囦欢鐨勭ず渚嬶細

shell> mysqld_multi --example

mysqld_multi鏀寔涓嬮潰鐨勯夐」锛

         --config-file=name

鎸囧畾閫夐」鏂囦欢鍚嶃傝繖鍏崇郴鍒mysqld_multi浠庡摢閲屽鎵[mysqldN]閫夐」缁勩傛病鏈夎閫夐」锛屼粠閫氱敤my.cnf鏂囦欢璇绘墍鏈夐夐」銆傞夐」涓嶅奖鍝 mysqld_multi浠庡摢閲岃鍙栬嚜宸辩殑閫夐」锛屾绘槸浠庨氱敤my.cnf鏂囦欢鐨[mysqld_multi]缁勮鍙栥

         --example

鏄剧ず绀轰緥閫夐」鏂囦欢銆

         --help

鏄剧ず甯姪娑堟伅骞堕鍑恒

         --log=name

鎸囧畾鏃ュ織鏂囦欢鍚嶃傚鏋滆鏂囦欢瀛樺湪锛屽悗闈负鏃ュ織杈撳嚭銆

         --mysqladmin=prog_name

鐢ㄦ潵鍋滄鏈嶅姟鍣ㄧ殑mysqladmin浜岃繘鍒躲

         --mysqld=prog_name

鍙敤鐨mysqld浜岃繘鍒躲傝娉ㄦ剰浣犺繕鍙互灏嗚閫夐」鐨勫兼寚瀹氫负mysqld_safe銆傞夐」琚紶閫掔粰 mysqld纭繚鍦PATH鐜鍙橀噺璁惧畾鍊兼垨mysqld_safe涓湁mysqld鎵鍦ㄧ洰褰曘

         --no-log

鎸夌収鏍囧噯杈撳嚭鎵撳嵃鏃ュ織淇℃伅锛屼笉瑕佸啓鍏ユ棩蹇楁枃浠躲傞粯璁ゆ儏鍐典笅锛岃緭鍑哄啓鍏ユ棩蹇楁枃浠躲

         --password=password

璋冪敤mysqladmin鏃朵娇鐢ㄧ殑MySQL璐︽埛鐨勫瘑鐮併傝娉ㄦ剰璇ュ瘑鐮佸间笉鏄彲閫夐」锛屼笉璞″叾瀹MySQL绋嬪簭銆

         --silent

绂佺敤璀﹀憡銆

         --tcp-ip

閫氳繃TCP/IP绔彛鑰屼笉鏄Unix濂楁帴瀛楁枃浠舵潵杩炴帴姣忎釜MySQL鏈嶅姟鍣ㄣ(濡傛灉鎵句笉鍒板鎺ュ瓧鏂囦欢锛 鏈嶅姟鍣ㄤ粛鐒跺彲浠ヨ繍琛岋紝浣嗗彧鑳介氳繃 TCP/IP绔彛璁块棶锛榛樿鎯呭喌涓嬶紝浣跨敤Unix濂楁帴瀛楁枃浠惰繘琛岃繛鎺ャ傝閫夐」褰卞搷stopreport鎿嶄綔銆

         --user=user_name

璋冪敤mysqladmin鏃朵娇鐢ㄧ殑MySQL璐︽埛鐨勭敤鎴峰悕銆

         --verbose

鏇磋缁嗐

         --version

鏄剧ず鐗堟湰淇℃伅骞堕鍑恒

鍏充簬mysqld_multi鐨勪竴浜涙敞瑙o細

         纭繚鍋滄mysqld鏈嶅姟鍣(mysqladmin绋嬪簭)MySQL璐︽埛鍦ㄥ悇涓湇鍔″櫒涓殑鐢ㄦ埛鍚嶅拰瀵嗙爜鐩稿悓銆傚苟涓斿簲纭繚璐︽埛鍏锋湁SHUTDOWN鏉冮檺銆傚鏋滀綘鎯宠绠$悊鐨勬湇鍔″櫒鐨勭鐞嗚处鎴锋湁璁稿涓嶅悓鐨勭敤鎴峰悕鎴栧瘑鐮侊紝浣犻渶瑕佸湪姣忎釜鏈嶅姟鍣ㄤ笂鍒涘缓涓涓处鎴凤紝骞跺叿鏈夌浉鍚岀殑鐢ㄦ埛鍚嶅拰瀵嗙爜銆備緥濡傦紝浣犲彲浠ユ墽琛屼笅闈㈢殑鍛戒护涓烘瘡涓湇鍔″櫒璁剧疆涓涓櫘閫multi_admin璐︽埛锛

                shell> mysql -u root -S /tmp/mysql.sock -proot_password
                mysql> GRANT SHUTDOWN ON *.*
                    -> TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass'

鍙傝5.7.2鑺傦紝鈥滄潈闄愮郴缁熷伐浣滃師鐞嗏銆備綘蹇呴』涓烘瘡涓mysqld鏈嶅姟鍣ㄦ墽琛岃鎿嶄綔銆傚綋杩炴帴鏃堕傚綋鏇存敼杩炴帴鍙傛暟銆傝娉ㄦ剰璐︽埛鍚嶇殑涓绘満閮ㄥ垎蹇呴』鍏佽浣犵敤multi_admin浠庝綘鎯宠杩愯mysqld_multi鐨勪富鏈鸿繘琛岃繛鎺ャ

         濡傛灉浣犱娇鐢mysqld_safe鏉ュ惎鍔mysqld(渚嬪锛--mysqld=mysqld_safe)--pid-file閫夐」寰堥噸瑕併傛瘡涓mysqld搴旀湁鑷繁鐨勮繘绋ID鏂囦欢銆備娇鐢mysqld_safe鑰屼笉浣跨敤mysqld鐨勫ソ澶勬槸mysqld_safe瀹堟姢鈥濆叾mysqld杩涚▼锛屽鏋滅敤kill 9鍙戦佺殑淇″彿鎴栫敱浜庡叾瀹冨師鍥狅紙渚嬪鍒嗘鏁呴殰锛夎繘绋嬬粓姝紝鍒欓噸鍚繘绋嬨傝娉ㄦ剰mysqld_safe鑴氭湰闇瑕佷綘浠庢煇涓綅缃惎鍔ㄥ畠銆傝繖璇存槑杩愯mysqld_multi鍓嶄綘蹇呴』杩涘叆鏌愪釜鐩綍銆傚鏋滃惎鍔ㄦ椂鏈夐棶棰橈紝璇峰弬瑙mysqld_safe鑴氭湰銆傜壒鍒槸瑕佹鏌ヤ笅鍒楄锛

                ----------------------------------------------------------------
                MY_PWD=`pwd`
                # Check if we are starting this relative (for the binary release)
                if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
                -x ./bin/mysqld
                ----------------------------------------------------------------

鍙傝5.1.3鑺傦紝鈥渕ysqld_safe锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈銆備笂杩拌鎵ц鐨勬祴璇曞簲鎴愬姛锛屽惁鍒欎綘鍙兘閬囧埌浜嗛棶棰樸

         姣忎釜mysqldUnix濂楁帴瀛楁枃浠跺拰TCP/IP绔彛鍙峰繀椤讳笉鍚屻

         浣犲彲鑳芥兂瑕佷负mysqld浣跨敤--user閫夐」锛屼絾涓烘浣犻渶瑕佺敤Unix root鐢ㄦ埛杩愯mysqld_multi鑴氭湰銆傞夐」鏂囦欢涓湁閫夐」涓嶈绱э紱濡傛灉浣犱笉鏄秴绾х敤鎴凤紝骞朵笖浣犵敤鑷繁鐨Unix璐︽埛閲嶅惎mysqld杩涚▼锛屼綘鍙細寰楀埌璀﹀憡銆

         閲嶈锛氱‘淇mysqld杩涚▼鍚姩鎵鐢Unix璐︽埛鍙互瀹屽叏璁块棶鏁版嵁鐩綍銆涓嶈浣跨敤Unix root璐︽埛锛岄櫎闈炰綘鐭ラ亾浣犲湪鍋氫粈涔堛

         闈炲父閲嶈锛氫娇鐢mysqld_multi鍓嶏紝纭繚鐞嗚В浼犻掔粰mysqld鏈嶅姟鍣ㄧ殑閫夐」鐨勫惈涔変互鍙婁綘涓轰粈涔鎯宠鐙珛鐨mysqld杩涚▼銆傚簲娓呮 鍦ㄧ浉鍚岀殑鏁版嵁鐩綍涓嬩娇鐢ㄥ涓mysqld鏈嶅姟鍣鐨勫嵄闄┿備娇鐢ㄥ崟鐙殑鏁版嵁鐩綍锛岄櫎闈炰綘鐭ラ亾浣犲湪鍋氫粈涔堛傚湪绾跨▼绯荤粺涓紝鍦ㄧ浉鍚岀殑鏁版嵁鐩綍涓嬪惎鍔ㄥ涓湇鍔″櫒涓嶄細寰楀埌瓒呮ц兘銆傚弬瑙5.12鑺傦紝鈥滃湪鍚屼竴鍙版満鍣ㄤ笂杩愯澶氫釜MySQL鏈嶅姟鍣ㄢ

涓嬮潰鐨勭ず渚嬫樉绀轰簡浣犲浣曡缃夐」鏂囦欢鏉ヤ娇鐢mysqld_multi銆備笓闂ㄧ渷鍘荤1涓拰绗5[mysqldN]缁勬潵璇存槑浣犵殑閫夐」鏂囦欢鍙互绋嶆湁涓嶅悓銆傝繖鏍风粰浣犳洿澶х殑鐏垫椿鎬сmysqld绋嬪簭閲嶅惎鎴栧仠姝㈢殑椤哄簭鐢卞畠浠湪閫夐」鏂囦欢涓殑椤哄簭鍐冲畾銆

# This file should probably be in your home dir (~/.my.cnf)
# or /etc/my.cnf
# Version 2.1 by Jani Tolonen
 
[mysqld_multi]
mysqld     = /usr/local/bin/mysqld_safe
mysqladmin = /usr/local/bin/mysqladmin
user       = multi_admin
password   = multipass
 
[mysqld2]
socket     = /tmp/mysql.sock2
port       = 3307
pid-file   = /usr/local/mysql/var2/hostname.pid2
datadir    = /usr/local/mysql/var2
language   = /usr/local/share/mysql/english
user       = john
 
[mysqld3]
socket     = /tmp/mysql.sock3
port       = 3308
pid-file   = /usr/local/mysql/var3/hostname.pid3
datadir    = /usr/local/mysql/var3
language   = /usr/local/share/mysql/swedish
user       = monty
 
[mysqld4]
socket     = /tmp/mysql.sock4
port       = 3309
pid-file   = /usr/local/mysql/var4/hostname.pid4
datadir    = /usr/local/mysql/var4
language   = /usr/local/share/mysql/estonia
user       = tonu
 
[mysqld6]
socket     = /tmp/mysql.sock6
port       = 3311
pid-file   = /usr/local/mysql/var6/hostname.pid6
datadir    = /usr/local/mysql/var6
language   = /usr/local/share/mysql/japanese
user       = jani

鍙傝4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥

5.2. mysqlmanager锛歁ySQL瀹炰緥绠$悊鍣

MySQL瀹炰緥绠$悊鍣(IM)鏄氳繃TCP/IP绔彛杩愯鐨勫悗鍙扮▼搴忥紝鐢ㄦ潵鐩戣鍜岀鐞MySQL鏁版嵁搴撴湇鍔″櫒瀹炰緥銆MySQL瀹炰緥绠$悊鍣 閫傚悎Unix-绫绘搷浣滅郴缁熷拰Windows

鍙互鍦mysqld_safe鑴氭湰浣跨敤MySQL瀹炰緥绠$悊鍣ㄦ潵鍚姩鍜屽仠姝MySQL鏈嶅姟鍣紝鐢氳嚦鍙互浠庝竴涓繙绋嬩富鏈MySQL瀹炰緥绠$悊鍣ㄨ繕鎵цmysqld_multi鑴氭湰鐨勫姛鑳(鍜屽ぇ澶氭暟璇硶)銆備笅闈负MySQL瀹炰緥绠$悊鍣ㄧ殑璇︾粏鎻忚堪銆

5.2.1. 鐢∕ySQL瀹炰緥绠$悊鍣ㄥ惎鍔∕ySQL鏈嶅姟鍣

涓鑸儏鍐碉紝鐢mysql.server鑴氭湰鍚姩MySQL Database ServerMySQL鏁版嵁搴撴湇鍔″櫒锛夛紝閫氬父椹荤暀鍦/etc/init.d/ 鏂囦欢澶广傞粯璁ゆ儏鍐典笅璇ヨ剼鏈皟鐢mysqld_safe鑴氭湰銆備絾鏄紝浣犲彲浠ュ湪鑴氭湰涓皢use_mysqld_safe鍙橀噺璁剧疆涓0()浠ヤ究浣跨敤MySQL瀹炰緥绠$悊鍣ㄦ潵鍚姩鏈嶅姟鍣ㄣ

鍦ㄨ繖绉嶆儏鍐典笅锛Instance Manager鐨勮涓哄彇鍐充簬MySQL閰嶇疆鏂囦欢涓殑閫夐」銆傚鏋滄病鏈夐厤缃枃浠讹紝MySQL瀹炰緥绠$悊鍣ㄥ垱寤mysqld瀹炰緥骞惰瘯鍥剧敤榛樿(缂栬瘧宓屽叆鐨)閰嶇疆鏉ュ惎鍔ㄣ傝繖璇存槑濡傛灉mysqld娌℃湁瀹夎鍒 榛樿浣嶇疆锛IM涓嶈兘鐚滃嚭瀹冪殑浣嶇疆銆傚鏋滀綘宸茬粡鍦ㄩ潪鏍囧噯浣嶇疆瀹夎浜MySQL鏈嶅姟鍣紝浣犲簲浣跨敤閰嶇疆鏂囦欢銆傚弬瑙2.1.5鑺傦紝鈥滃畨瑁呭竷灞鈥

濡傛灉鏈夐厤缃枃浠讹紝IM灏嗗垎鏋愰厤缃枃浠舵悳绱[mysqld]閮ㄥ垎(渚嬪[mysqld][mysqld1][mysqld2])銆傛瘡涓儴鍒嗘寚瀹氫竴涓疄渚嬨傚惎鍔ㄦ椂IM灏嗗惎鍔ㄦ墍鏈夋壘鍒扮殑瀹炰緥銆IM鍏抽棴鏃堕粯璁ゅ仠姝㈡墍鏈夊疄渚嬨

璇锋敞鎰忔湁涓涓壒娈婇夐」mysqld-path(mysqld-path = path-to-mysqld- binary)锛屽彧鑳界敤IM璇嗗埆銆備娇鐢ㄨ鍙橀噺璁IM鐭ラ亾mysqld浜岃繘鍒堕┗鐣欏湪鍝効銆備綘杩樺簲璇ヤ负鏈嶅姟鍣ㄨ缃basedirdatadir閫夐」銆

鍚敤MySQL瀹炰緥绠$悊鍣ㄧ殑鍏稿瀷MySQL鏈嶅姟鍣ㄥ惎鍔/鍏抽棴寰幆涓猴細

          /etc/init.d/mysql鑴氭湰鍚姩MySQL瀹炰緥绠$悊鍣ㄣ

          MySQL瀹炰緥绠$悊鍣ㄥ惎鍔ㄦ墍鏈夊疄渚嬪苟鐩戣瀹冧滑銆

         濡傛灉鏌愪釜鏈嶅姟鍣ㄥ疄渚嬪け璐ワ紝MySQL瀹炰緥绠$悊鍣ㄩ噸鍚畠銆

         濡傛灉MySQL瀹炰緥绠$悊鍣ㄨ鍏抽棴(渚嬪鐢/etc/init.d/mysql stop鍛戒护)锛屾墍鏈夊疄渚嬭MySQL瀹炰緥绠$悊鍣ㄥ叧闂

5.2.2. 杩炴帴鍒癕ySQL瀹炰緥绠$悊鍣ㄥ苟鍒涘缓鐢ㄦ埛璐︽埛

浣跨敤MySQL瀹㈡埛绔-鏈嶅姟鍣ㄥ崗璁潵澶勭悊鍚MySQL瀹炰緥绠$悊鍣ㄤ箣闂寸殑閫氫俊銆備綘涓嶈兘浣跨敤鏍囧噯mysql瀹㈡埛绔▼搴忓拰MySQL C API鏉ヨ繛鎺IMIM鏀寔瀹㈡埛绔伐鍏峰拰mysql-4.1鎴栦互鍚庣殑鐗堟湰鎵鍒嗗彂鐨勫簱鎵鐢ㄧ殑MySQL瀹㈡埛绔-鏈嶅姟鍣ㄥ崗璁増鏈

IM灏嗙敤鎴蜂俊鎭繚瀛樺埌瀵嗙爜鏂囦欢涓傚瘑鐮佹枃浠剁殑榛樿浣嶇疆涓/etc/mysqlmanager.passwd

瀵嗙爜搴旂被浼间簬锛

petr:*35110DC9B4D8140F5DE667E28C72DD2597B5C848

瑕佹兂鐢熸垚瀵嗙爜鐢--passwd閫夐」璋冪敤IM銆傚垯杈撳嚭鍙互閲嶅畾鍚戝埌/etc/mysqlmanager.passwd鏂囦欢浠ユ坊鍔犳柊鐢ㄦ埛銆備笅闈负绀轰緥鍛戒护銆

./mysqlmanager --passwd >> /etc/mysqlmanager.passwd
Creating record for new user.
Enter user name: mike
Enter password: <password>
Re-type password: <password>

涓嬮潰鐨勮灏嗗姞鍒/etc/mysqlmanager.passwd

mike:*00A51F3F48415C7D4E8908980D443C29C69B60C9

濡傛灉/etc/mysqlmanager.passwd鏂囦欢涓病鏈夎鏉★紝鍒欎笉鑳借繛鎺IM

5.2.3. MySQL瀹炰緥绠$悊鍣ㄥ懡浠よ閫夐」

MySQL瀹炰緥绠$悊鍣ㄦ敮鎸佽澶氬懡浠よ閫夐」銆傛墽琛./mysqlmanager --help鍛戒护鍙互绠鍗曞垪鍑恒傛湁涓嬮潰鐨勯夐」锛

         --help-?

鏄剧ず甯姪娑堟伅骞堕鍑恒

         --bind-address=name

缁戝畾鍦板潃鐢ㄤ簬杩炴帴銆

         --default-mysqld-path=name

Unix涓紝濡傛灉瀹炰緥閮ㄥ垎娌℃湁璺緞锛屽垯涓哄鎵MySQL鏈嶅姟鍣ㄤ簩杩涘埗鐨勫湴鐐广備緥濡傦細default-mysqld-path = /usr/sbin/mysqld

         --defaults-file=file_name

浠庣粰瀹氭枃浠惰Instance ManagerMySQL鏈嶅姟鍣ㄨ瀹氬笺傛墍鏈Instance Manager鏇存敼鐨勯厤缃皢鍔犲叆璇ユ枃浠躲傚彧鑳界敤浜Instance Manager鐨勭涓閫夐」銆

         --install

Windows涓紝灏Instance Manager瀹夎涓Windows鏈嶅姟銆

         --log=name

IM鏃ュ織鏂囦欢鐨勮矾寰勩傜粨鍚--run-as-service閫夐」浣跨敤銆

         --monitoring-interval=Seconds

鐩戣瀹炰緥鐨勯棿闅旓紝鍗曚綅涓虹銆Instance Manager灏嗗皾璇曡繛鎺ユ瘡涓洃瑙嗙殑瀹炰緥鏉ユ鏌ュ畠浠槸鍚︽槸娲诲姩鐨/娌℃湁鎸傝捣銆傚嚭鐜版晠闅滐紝IM灏嗛噸鍚嚑娆(瀹為檯涓婃槸澶氭)瀹炰緥銆傚彲浠ョ敤nonguarded閫夐」涓虹壒瀹氬疄渚嬬鐢ㄨ琛屼负銆傚鏋滄湭缁欏畾浠讳綍鍊硷紝 榛樿浣跨敤20绉掋

         --passwd-P

缂栧啓passwd鏂囦欢骞堕鍑恒

         --password-file=name

浠庤鏂囦欢涓鎵Instance Manager鐢ㄦ埛鍜屽瘑鐮併傞粯璁ゆ枃浠舵槸/etc/mysqlmanager.passwd

         --pid-file=name

浣跨敤鐨勮繘绋ID鏂囦欢銆傞粯璁ゆ儏鍐典笅锛岃鏂囦欢鏂囦欢鍚嶄负mysqlmanager.pid

         -- port=port_num

鐢ㄤ簬杩炴帴鐨勭鍙e彿銆(IANA鍒嗛厤鐨 榛樿绔彛鍙蜂负2273)

         --print-defaults

鎵撳嵃褰撳墠鐨勯粯璁ゅ煎苟閫鍑恒傚彧鑳界敤浣Instance Manager鐨勭涓閫夐」銆

         --remove

Windows涓紝鍒犳帀Instance Manager Windows鏈嶅姟銆傚亣瀹氬墠闈㈠凡缁忕敤--install杩愯浜Instance Manager

         --run-as-service

浣垮畬鍠勮繘绋嬪彉涓哄悗鍙扮▼搴忓苟鍚姩銆傚畬鍠勮繘绋嬪緢绠鍗曪紝涓嶆槗宕╂簝銆傚嚭鐜版晠闅滃悗瀹冨皢鑷繁閲嶅惎IM

         --socket=name

Unix涓敤浜庤繛鎺ョ殑濂楁帴瀛楁枃浠躲傞粯璁ゆ儏鍐典笅锛屾枃浠跺悕涓/tmp/mysqlmanager.sock

         --standalone

Windows涓互鍗曟満妯″紡杩愯Instance Manager

         --user=name

鍚姩骞惰繍琛mysqlmanager鐨勭敤鎴峰悕銆傚缓璁娇鐢ㄨ繍琛mysqld鏈嶅姟鍣鐨勭敤鎴疯处鎴锋潵杩愯mysqlmanager

         --version, -V

杈撳嚭鐗堟湰淇℃伅骞堕鍑恒

5.2.4. MySQL瀹炰緥绠$悊鍣ㄩ厤缃枃浠

Instance Manager浣跨敤鏍囧噯my.cnf鏂囦欢銆傚畠浣跨敤[manager]閮ㄥ垎涓鸿嚜宸辫鍙栭夐」骞惰鍙[mysqld]閮ㄥ垎鏉ュ垱寤哄疄渚嬨[manager]閮ㄥ垎鍖呭惈涓婅堪鍒楀嚭鐨勯夐」銆備笅闈负[manager]閮ㄥ垎绀轰緥锛
# MySQL Instance Manager options section
[manager]
default-mysqld-path = /usr/local/mysql/libexec/mysqld
socket=/tmp/manager.sock
pid-file=/tmp/manager.pid
password-file = /home/cps/.mysqlmanager.passwd
monitoring-interval = 2
port = 1999
bind-address = 192.168.1.5

MySQL瀹炰緥绠$悊鍣ㄥ彧鍦Unix涓鍙栧苟绠$悊/etc/my.cnf鏂囦欢銆傚湪Windows涓紝MySQL瀹炰緥绠$悊鍣ㄤ粠Instance Manager鐨勫畨瑁呯洰褰曡鍙my.ini鏂囦欢銆傜敤--defaults-file=file_ name閫夐」鍙互鏇存敼榛樿閫夐」鏂囦欢鐨勪綅缃

瀹炰緥閮ㄥ垎鎸囧畾鍚姩鏃剁粰姣忎釜瀹炰緥鐨勯夐」銆傝繖浜涗富瑕佹槸鏅MySQL鏈嶅姟鍣ㄩ夐」锛屼絾鏈変竴浜IM-涓撶敤閫夐」锛

         mysqld-path = <path-to-mysqld-binary>

mysqld鏈嶅姟鍣浜岃繘鍒剁殑璺緞銆

         shutdown-delay = Seconds

IM搴旂瓑寰呭疄渚嬪叧闂殑绉掓暟銆 榛樿涓35绉掋傝秴杩囧欢杩熸椂闂村悗锛IM鍋囧畾瀹炰緥姝f寕璧峰苟璇曞浘鈥kill 9瀹冦傚鏋滀綘浣跨敤甯large琛ㄧ殑InnoDB锛屼綘搴斿綋澧炲姞璇ュ笺

         nonguarded

濡傛灉浣犳兂瑕佷负鏌愪釜瀹炰緥绂佺敤IM鐩戣鍔熻兘锛屽簲璁剧疆璇ラ夐」銆

涓嬮潰缁欏嚭浜嗗嚑涓疄渚嬬ず渚嬨

[mysqld]
mysqld-path=/usr/local/mysql/libexec/mysqld
socket=/tmp/mysql.sock
port=3307
server_id=1
skip-stack-trace
core-file
skip-bdb
log-bin
log-error
log=mylog
log-slow-queries
 
[mysqld2]
nonguarded
port=3308
server_id=2
mysqld-path= /home/cps/mysql/trees/mysql-5.1/sql/mysqld
socket     = /tmp/mysql.sock5
pid-file   = /tmp/hostname.pid5
datadir= /home/cps/mysql_data/data_dir1
language=/home/cps/mysql/trees/mysql-5.1/sql/share/english
log-bin

log=/tmp/fordel.log

5.2.5. MySQL瀹炰緥绠$悊鍣ㄨ瘑鍒殑鍛戒护

涓鏃︿綘宸茬粡涓MySQL瀹炰緥绠$悊鍣ㄨ缃簡涓涓瘑鐮佹枃浠跺苟涓IM姝e湪杩愯锛屼綘鍙互杩炴帴瀹冦備綘鍙互浣跨敤mysql瀹㈡埛绔伐鍏烽氳繃鏍囧噯MySQL API鏉ヨ繛鎺ャ備互涓嬫槸MySQL瀹炰緥绠$悊鍣ㄧ洰鍓嶅彲浠ユ帴鏀剁殑鍛戒护鐨勬竻鍗曞拰渚嬪瓙銆

         START INSTANCE <instance_name>

璇ュ懡浠ゅ皢璇曞浘鍚姩涓涓疄渚嬶細

mysql> START INSTANCE mysqld4;
Query OK, 0 rows affected (0,00 sec)

         STOP INSTANCE <instance_name>

灏嗚瘯鍥惧仠姝竴涓疄渚嬶細

mysql> STOP INSTANCE mysqld4;
Query OK, 0 rows affected (0,00 sec)

         SHOW INSTANCES

鏄剧ず鎵鏈夎浇鍏ョ殑瀹炰緥鍚嶏細

mysql> show instances;
+---------------+---------+
| instance_name | status  |
+---------------+---------+
| mysqld3       | offline |
| mysqld4       | online  |
| mysqld2       | offline |
+---------------+---------+
3 rows in set (0,04 sec)

         SHOW INSTANCE STATUS <instance_name>

鏄剧ず閫夊畾鐨勫疄渚嬬殑鐘舵佸拰鐗堟湰淇℃伅锛

mysql> SHOW INSTANCE STATUS mysqld3;
+---------------+--------+---------+
| instance_name | status | version |
+---------------+--------+---------+
| mysqld3       | online | unknown |
+---------------+--------+---------+
1 row in set (0.00 sec)

         SHOW INSTANCE OPTIONS <instance_name>

鏄剧ず瀹炰緥浣跨敤鐨勯夐」锛

mysql> SHOW INSTANCE OPTIONS mysqld3;
+---------------+---------------------------------------------------+
| option_name   | value                                             |
+---------------+---------------------------------------------------+
| instance_name | mysqld3                                           |
| mysqld-path   | /home/cps/mysql/trees/mysql-4.1/sql/mysqld        |
| port          | 3309                                              |
| socket        | /tmp/mysql.sock3                                  |
| pid-file      | hostname.pid3                                     |
| datadir       | /home/cps/mysql_data/data_dir1/                   |
| language      | /home/cps/mysql/trees/mysql-4.1/sql/share/english |
+---------------+---------------------------------------------------+
7 rows in set (0.01 sec)

         SHOW <instance_name> LOG FILES

璇ュ懡浠ゆ彁渚涘疄渚嬩娇鐢ㄧ殑鎵鏈夋棩蹇楁枃浠躲傜粨鏋滃寘鍚棩蹇楁枃浠剁殑璺緞鍜屾棩蹇楁枃浠剁殑澶у皬銆傚鏋滄病鏈夊湪閰嶇疆鏂囦欢涓寚瀹氭棩蹇楁枃浠剁殑璺緞 (渚嬪log=/var/mysql.log)IM璇曞浘鐚滃嚭瀹冪殑浣嶇疆銆傚鏋IM涓嶈兘鐚滃嚭鏃ュ織鏂囦欢鐨勪綅缃紝浣犲簲鏄庣‘鎸囧畾鏃ュ織鏂囦欢鐨勪綅缃

mysql> SHOW mysqld LOG FILES;
+-------------+------------------------------------+----------+
| Logfile     | Path                               | Filesize |
+-------------+------------------------------------+----------+
| ERROR LOG   | /home/cps/var/mysql/owlet.err      | 9186     |
| GENERAL LOG | /home/cps/var/mysql/owlet.log      | 471503   |
| SLOW LOG    | /home/cps/var/mysql/owlet-slow.log | 4463     |
+-------------+------------------------------------+----------+
3 rows in set (0.01 sec)

         SHOW <instance_name> LOG {ERROR | SLOW | GENERAL} size[,offset_from_end]

璇ュ懡浠ゆ煡鎵炬寚瀹氱殑鏃ュ織鏂囦欢鐨勪竴閮ㄥ垎銆傚洜涓哄ぇ澶氭暟鐢ㄦ埛鍏虫敞鏈鏂扮殑鏃ュ織娑堟伅锛岀敤size鍙傛暟瀹氫箟浣犳兂瑕佷粠鏃ュ織鏈熬寮濮嬬储鍙栫殑瀛楄妭鏁般備綘鍙互鎸囧畾鍙offset_from_end鍙傛暟浠庢棩蹇楁枃浠朵腑閮ㄧ储鍙栨暟鎹備笅闈㈢殑绀轰緥鍙互绱㈠彇21涓瓧鑺傜殑鏁版嵁锛屼粠鏃ュ織鏂囦欢鏈熬寮濮23涓瓧鑺傦紝2涓瓧鑺傜敤浜庣粨鏉燂細

mysql> SHOW mysqld LOG GENERAL 21, 2;
+---------------------+
| Log                 |
+---------------------+
| using password: YES |
+---------------------+
1 row in set (0.00 sec)

         SET instance_name.option_name=option_value

璇ュ懡浠ょ紪杈戞寚瀹氱殑瀹炰緥鐨勯厤缃枃浠朵互鏇存敼/澧炲姞瀹炰緥閫夐」銆IM鍋囧畾閰嶇疆鏂囦欢浣嶄簬/etc/my.cnf銆備綘搴旀鏌ユ枃浠舵槸鍚﹀瓨鍦紝骞跺叿鏈夊悎閫傜殑鏉冮檺銆

mysql> SET mysqld2.port=3322;
Query OK, 0 rows affected (0.00 sec)

MySQL鏈嶅姟鍣ㄩ噸鍚墠锛屽閰嶇疆鏂囦欢杩涜鐨勬洿鏀逛笉浼氱敓鏁堛傚苟涓旓紝鎵цFLUSH INSTANCES鍛戒护鍚庯紝鎵嶄細灏嗚繖浜涙洿鏀逛繚瀛樺埌Instance Manager鐨勫疄渚嬭瀹氬肩殑鏈湴缂撳瓨涓

         UNSET instance_name.option_name

璇ュ懡浠や粠瀹炰緥鐨勯厤缃枃浠跺垹闄や竴涓夐」銆

mysql> UNSET mysqld2.port;
Query OK, 0 rows affected (0.00 sec)

MySQL鏈嶅姟鍣ㄩ噸鍚墠锛屽閰嶇疆鏂囦欢杩涜鐨勬洿鏀逛笉浼氱敓鏁堛傚苟涓旓紝鎵цFLUSH INSTANCES鍛戒护鍚庯紝鎵嶄細灏嗚繖浜涙洿鏀逛繚瀛樺埌Instance Manager鐨勫疄渚嬭瀹氬肩殑鏈湴缂撳瓨涓

         FLUSH INSTANCES

璇ュ懡浠ゅ己鍒IM閲嶈閰嶇疆鏂囦欢骞舵竻绌哄唴閮ㄧ粨鏋勩傜紪杈戦厤缃枃浠跺悗搴旀墽琛岃鍛戒护銆傝鍛戒护涓嶉噸鍚疄渚嬶細

mysql> FLUSH INSTANCES;
Query OK, 0 rows affected (0.04 sec)

5.3. mysqld锛歁ySQL鏈嶅姟鍣

mysqldMySQL鏈嶅姟鍣ㄣ備笅闈㈣璁MySQL鏈嶅姟鍣ㄧ殑閰嶇疆锛

         鏈嶅姟鍣ㄦ敮鎸佺殑鍚姩閫夐」

         濡備綍璁剧疆鏈嶅姟鍣SQL妯″紡

         鏈嶅姟鍣ㄧ郴缁熷彉閲

         鏈嶅姟鍣ㄧ姸鎬佸彉閲

5.3.1.聽mysqld鍛戒护琛岄夐」

褰撳惎鍔mysqld鏈嶅姟鍣鏃讹紝浣犲彲浠ヤ娇鐢4.3鑺傦紝鈥滄寚瀹氱▼搴忛夐」鈥涓弿杩扮殑鏂规硶鎸囧畾绋嬪簭閫夐」銆傛渶甯哥敤鐨勬柟娉曟槸鍦ㄩ夐」鏂囦欢涓垨鍦ㄥ懡浠よ鎻愪緵閫夐」銆備絾鏄紝鍦ㄥぇ澶氭暟鎯呭喌涓嬶紝甯屾湜鏈嶅姟鍣ㄦ瘡娆¤繍琛屾椂浣跨敤鐩稿悓鐨勯夐」銆傛渶濂界殑鏂规硶鏄‘淇濆皢瀹冧滑鍒楀湪閫夐」鏂囦欢涓傚弬瑙4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥

mysqld[mysqld][server]缁勮鍙栭夐」銆mysqld_safe[mysqld][server][mysqld_safe][safe_mysqld]缁勮鍙栭夐」銆mysql.server[mysqld][mysql.server]缁勮鍙栭夐」銆傚祵鍏ュ紡MySQL鏈嶅姟鍣ㄩ氬父浠[server][embedded][xxxxx_SERVER]缁勮鍙栭夐」锛屽叾涓xxxxx鏄湇鍔″櫒宓屽叆鐨勫簲鐢ㄧ▼搴忓悕銆

mysqld鎺ュ彈璁稿鍛戒护琛岄夐」銆傛墽琛mysqld --help鍙互绠鍗曞垪鍑烘潵銆傝鎯崇湅鍏ㄩ儴鍒楄〃鍒楋紝浣跨敤鍛戒护mysqld --verbose --help

涓嬮潰鍒楀嚭浜嗕竴浜涙渶甯哥敤鐨勬湇鍔″櫒閫夐」銆傚叾瀹冪殑閫夐」鍦ㄥ叾瀹冨湴鏂规弿杩帮細

         褰卞搷瀹夊叏鐨勯夐」锛氬弬瑙5.6.3鑺傦紝鈥淢ysqld瀹夊叏鐩稿叧鍚姩閫夐」

         SSL-鐩稿叧閫夐」锛氬弬瑙5.8.7.6鑺傦紝鈥淪SL鍛戒护琛岄夐」鈥

         浜岃繘鍒舵棩蹇楁帶鍒堕夐」锛氬弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥

         澶嶅埗鐩稿叧閫夐」锛氬弬瑙6.8鑺傦紝鈥滃鍒跺惎鍔ㄩ夐」鈥

         鐗瑰畾瀛樺偍寮曟搸鐩稿叧閫夐」锛氬弬瑙15.1.1鑺傦紝鈥淢yISAM鍚姩閫夐」鈥15.5.3鑺傦紝鈥淏DB鍚姩閫夐」鈥15.2.4鑺傦紝鈥淚nnoDB鍚姩閫夐」鈥

浣犺繕鍙互灏嗗彉閲忓悕浣滀负涓涓夐」锛岃缃湇鍔″櫒绯荤粺鍙橀噺鐨勫硷紝濡傛湰鑺傚悗闈㈡墍杩般

         --help-?

鏄剧ず绠鐭殑甯姪娑堟伅骞堕鍑恒備娇鐢--verbose--help閫夐」鏉ョ湅鍏ㄩ儴鍐呭銆

         --allow-suspicious-udfs

璇ラ夐」鎺у埗鏄惁鐢ㄦ埛瀹氫箟鐨勫嚱鏁板彧鏈変竴涓xxx绗︼紝鐢ㄤ綔鍙浇鍏ョ殑涓诲嚱鏁般傞粯璁ゆ儏鍐典笅锛岃閫夐」琚叧闂紝鍙湁鑷冲皯鏈変竴涓檮灞炵鐨UDF  鍙互杞藉叆銆傝繖鏍峰彲浠ラ槻姝粠鏈寘鍚悎娉UDF鐨勫叡浜枃浠惰杞藉嚱鏁般傚弬瑙27.2.3.6鑺傦紝鈥滅敤鎴峰畾涔夊嚱鏁板畨鍏ㄦ敞鎰忎簨椤光

         --ansi

浣跨敤鏍囧噯(ANSI)SQL璇硶浠f浛MySQL璇硶銆傚弬瑙1.8.3鑺傦紝鈥滃湪ANSI妯″紡涓嬭繍琛孧ySQL鈥銆備娇鐢--sql-mode閫夐」鍙互鏇寸簿纭帶鍒舵湇鍔″櫒SQL妯″紡銆

         --basedir=path, -b path

MySQL瀹夎鐩綍鐨勮矾寰勩傞氬父鎵鏈夎矾寰勬牴鎹璺緞鏉ヨВ鏋愩

         --bind-address=IP

寰呯粦瀹氱殑IP鍦板潃銆

         --bootstrap

mysql_install_db鑴氭湰浣跨敤璇ラ夐」鏉ュ垱寤MySQL鎺堟潈琛紝涓嶉渶瑕佸惎鍔MySQL鏈嶅姟鍣ㄣ

         --console

灏嗛敊璇棩蹇楁秷鎭啓鍏stderrstdout锛屽嵆浣挎寚瀹氫簡--log-error銆傚湪Windows涓紝濡傛灉浣跨敤璇ラ夐」锛mysqld涓嶅叧闂帶鍒跺彴绐楀彛銆

         --character-sets-dir=path

瀛楃闆嗗畨瑁呯殑鐩綍銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --chroot=path

閫氳繃chroot()绯荤粺璋冪敤鍦ㄥ惎鍔ㄨ繃绋嬩腑灏mysqld鏈嶅姟鍣ㄦ斁鍏ヤ竴涓皝闂幆澧冧腑銆傝繖鏄帹鑽愮殑涓涓畨鍏ㄦ帾鏂姐傝娉ㄦ剰浣跨敤璇ラ夐」鍙互 闄愬埗LOAD DATA INFILESELECT ... INTO OUTFILE

         --character-set-server=charset

浣跨敤charset浣滀负 榛樿鏈嶅姟鍣ㄥ瓧绗﹂泦銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --core-file

濡傛灉mysqld缁堟锛屽啓鍐呮牳鏂囦欢銆傚湪鏌愪簺绯荤粺涓紝浣犺繕蹇呴』涓mysqld_safe鎸囧畾--core-file-size 閫夐」銆傚弬瑙5.1.3鑺傦紝鈥渕ysqld_safe锛歁ySQL鏈嶅姟鍣ㄥ惎鍔ㄨ剼鏈銆傝娉ㄦ剰瀵逛簬涓浜涚郴缁燂紝渚嬪Solaris锛屽鏋滀綘浣跨敤--user閫夐」涓嶄細鑾峰緱鍐呮牳鏂囦欢銆

         --collation-server=collation

浣跨敤collation浣滀负 榛樿鏈嶅姟鍣ㄦ牎瀵硅鍒欍傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --datadir=path, -h path

鏁版嵁鐩綍鐨勮矾寰勩

         --debug[=debug_options], -# [debug_options]

濡傛灉MySQL閰嶇疆浜--with-debug锛屼綘鍙互浣跨敤璇ラ夐」鏉ヨ幏寰椾竴涓窡韪枃浠讹紝璺熻釜mysqld姝h繘琛岀殑鎿嶄綔銆debug_options瀛楃涓查氬父涓'd:t:ofile_name'銆傚弬瑙E.1.2鑺傦紝鈥滃垱寤鸿窡韪枃浠垛

         (DEPRECATED) --default-character-set=charset

浣跨敤char璁剧疆浣滀负 榛樿瀛楃闆嗐傜敱浜--character-set-server锛屽弽瀵逛娇鐢ㄨ閫夐」銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --default-collation=collation

浣跨敤collation 浣滀负榛樿鏍″瑙勫垯銆傜敱浜--collation-server锛屽弽瀵逛娇鐢ㄨ閫夐」銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --default-storage-engine=type

璇ラ夐」涓--default-table-type鐨勫悓涔夎瘝銆

         --default-table-type=type

璁剧疆琛ㄧ殑榛樿绫诲瀷銆傚弬瑙绗15绔狅細瀛樺偍寮曟搸鍜岃〃绫诲瀷

         --default-time-zone=type

璁剧疆榛樿鏈嶅姟鍣ㄦ椂鍖恒傝閫夐」璁剧疆鍏ㄥ眬time_zone绯荤粺鍙橀噺銆傚鏋滄湭缁欏嚭璇ラ夐」锛 榛樿鏃跺尯涓庣郴缁熸椂鍖虹浉鍚(system_time_zone绯荤粺鍙橀噺鍊肩粰瀹)

         --delay-key-write[= OFF | ON | ALL]

濡備綍浣跨敤DELAYED KEYS閫夐」銆傞敭鍐欏叆寤惰繜浼氶犳垚鍐嶆鍐MyISAM琛ㄦ椂閿紦鍐插尯涓嶈兘琚竻绌恒OFF绂佺敤寤惰繜鐨勯敭鍐欏叆銆ON鍚敤鐢DELAYED KEYS閫夐」鍒涘缓鐨勮〃鐨勫欢杩熺殑閿啓鍏ャALL寤惰繜鎵鏈MyISAM琛ㄧ殑閿啓鍏ャ傚弬瑙7.5.2鑺傦紝鈥滆皟鑺傛湇鍔″櫒鍙傛暟鈥銆傚弬瑙15.1.1鑺傦紝鈥淢yISAM鍚姩閫夐」鈥

閲婏細濡傛灉浣犲皢璇ュ彉閲忚缃负ALL锛屼綘涓嶅簲浠庡彟涓涓浣跨敤MyISAM琛ㄧ殑绋嬪簭涓娇鐢MyISAM(渚嬪浠庡彟涓涓MySQL鏈嶅姟鍣ㄦ垨鐢myisamchk)銆傝繖鏍锋搷浣滀細瀵艰嚧绱㈠紩鐮村潖銆

         --des-key-file=file_name

浠庤鏂囦欢璇DES_ENCRYPT()DES_DECRYPT()浣跨敤鐨 榛樿閿

         --enable-named-pipe

鍚敤鍛藉悕绠¢亾鏀寔銆傝閫夐」鍙傜敤Windows NT2000XP2003绯荤粺锛屽苟涓斿彧閫傜敤鏀寔鍛藉悕绠¢亾杩炴帴鐨mysqld-ntmysqld-max-nt鏈嶅姟鍣ㄣ

 

         --exit-info[=flags], -T [flags]

杩欐槸涓嶅悓鏍囧織鐨勪竴涓綅鎺╃爜锛屼綘鍙互鐢ㄦ潵璋冭瘯mysqld鏈嶅姟鍣銆備笉瑕佷娇鐢ㄨ閫夐」锛岄櫎闈炰綘纭垏鐭ラ亾瀹冨湪鍋氫粈涔堬紒

         --external-locking

鍚敤绯荤粺閿佸畾銆傝娉ㄦ剰濡傛灉浣犲湪lockd涓嶈兘瀹屽叏宸ヤ綔鐨勭郴缁熶笂浣跨敤璇ラ夐」(渚嬪鍦Linux)mysqld瀹规槗姝婚攣銆傝閫夐」浠ュ墠鍙--enable-locking

閲婏細濡傛灉浣犲湪璁稿MySQL杩涚▼涓娇鐢ㄨ閫夐」鏉ユ洿鏂MyISAM琛紝浣犲繀椤荤‘淇濇弧瓒充笅杩版潯浠讹細

o        浣跨敤姝h鍙︿竴涓繘绋嬫洿鏂扮殑琛ㄧ殑鏌ヨ鐨勭紦瀛樹笉鍙娇鐢ㄣ

o        涓嶅簲鍦ㄥ叡浜〃涓娇鐢--delay-key-write=ALLDELAY_KEY_WRITE=1

鏈绠鍗曠殑鏂规硶鏄粨鍚堜娇鐢--external-locking--delay-key-write=OFF --query-cache-size=0

(榛樿涓嶈兘瀹炵幇锛屽洜涓哄湪璁稿璁剧疆涓紝缁撳悎浣跨敤涓婅堪閫夐」寰堟湁鐢級

         --flush

鎵цSQL璇彞鍚庡悜纭洏涓婃竻绌烘洿鏀广備竴鑸儏鍐垫墽琛SQL璇彞鍚 MySQL鍚戠‖鐩樺啓鍏ユ墍鏈夋洿鏀癸紝璁╂搷浣滅郴缁熷鐞嗕笌纭洏鐨勫悓姝ャ傚弬瑙A.4.2鑺傦紝鈥滃鏋淢ySQL渚濈劧宕╂簝锛屽簲浣滀簺浠涔堚

         --init-file=file

鍚姩鏃朵粠璇ユ枃浠惰SQL璇彞銆傛瘡涓鍙ュ繀椤诲湪鍚屼竴琛屼腑骞朵笖涓嶅簲鍖呮嫭娉ㄩ噴銆

         --language=lang_name, -L lang_name

鐢ㄧ粰瀹氳瑷缁欏嚭瀹㈡埛绔敊璇秷鎭lang_name鍙互涓鸿瑷鍚嶆垨璇█鏂囦欢瀹夎鐩綍鐨勫叏璺緞鍚嶃傚弬瑙5.10.2鑺傦紝鈥滆缃敊璇秷鎭瑷鈥

         --large-pages

涓浜涚‖浠/鎿嶄綔绯荤粺鏋舵瀯鏀寔澶т簬 榛樿鍊(閫氬父4 KB)鐨勫唴瀛橀〉銆傚疄闄呮敮鎸佸彇鍐充簬浣跨敤鐨勭‖浠跺拰OS銆傚ぇ閲忚闂唴瀛樼殑搴旂敤绋嬪簭閫氳繃浣跨敤杈冨ぇ鐨勯〉锛岄檷浣庝簡Translation Lookaside Buffer (TLB)鎹熷け锛屽彲浠ユ敼鍠勬ц兘銆

鐩墠锛MySQL鍙湪Linux涓敮鎸佸ぇ椤甸潰(Linux涓绉颁綔HugeTLB)銆傛垜浠凡缁忚鍒掑皢璇ユ敮鎸佹墿灞曞埌FreeBSDSolaris鍜屽叾瀹冨彲鑳界殑骞冲彴銆

Linux涓彲浠ヤ娇鐢ㄥぇ椤甸潰鍓嶏紝闇瑕侀厤缃HugeTLB鍐呭瓨姹犮傚弬鑰Linux鍐呮牳婧愮爜涓殑hugetlbpage.txt鏂囦欢銆

榛樿鎯呭喌涓嬭閫夐」琚鐢ㄣ

         ---log[=file], -l [file]

鏃ュ織杩炴帴鍜屽鏂囦欢鐨勬煡璇€傚弬瑙5.11.2鑺傦紝鈥滈氱敤鏌ヨ鏃ュ織鈥銆傚鏋滀綘涓嶆寚瀹氭枃浠跺悕锛MySQL浣跨敤host_name.log浣滀负鏂囦欢鍚嶃

         --log-bin=[file]

浜岃繘鍒舵棩蹇楁枃浠躲傚皢鏇存敼鏁版嵁鐨勬墍鏈夋煡璇㈣鍏ヨ鏂囦欢銆傜敤浜庡浠藉拰澶嶅埗銆傚弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥銆傚缓璁寚瀹氫竴涓枃浠跺悕(鍘熷洜鍙傝A.8.1鑺傦紝鈥淢ySQL涓殑鎵撳紑浜嬪疁鈥)锛屽惁鍒MySQL浣跨敤host_name-bin浣滀负鏃ュ織鏂囦欢鍩烘湰鍚嶃

         --log-bin-index[=file]

浜岃繘鍒舵棩蹇楁枃浠跺悕鐨勭储寮曟枃浠躲傚弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥銆傚鏋滀綘涓嶆寚瀹氭枃浠跺悕锛屽苟涓斿鏋滀綘娌℃湁鍦--log-bin涓寚瀹氾紝MySQL浣跨敤host_name-bin.index浣滀负鏂囦欢鍚嶃

         --log-bin-trust-routine-creators[={0|1}]

娌℃湁鍙傛暟鎴栧弬鏁颁负1,璇ラ夐」灏嗙郴缁熷彉閲log_bin_trust_routine_creators璁剧疆涓1銆備负鍙傛暟 0鏃讹紝璇ラ夐」灏嗙郴缁熷彉閲忚缃负0log_bin_trust_routine_creators褰卞搷MySQL濡備綍瀵逛繚瀛樼殑绋嬪簭鐨勫垱寤哄己鍔犻檺鍒躲傚弬瑙20.4鑺傦紝鈥滃瓨鍌ㄥ瓙绋嬪簭鍜岃Е鍙戠▼搴忕殑浜岃繘鍒舵棩蹇楀姛鑳解

         --log-error[=file]

璇ユ枃浠剁殑鏃ュ織閿欒鍜屽惎鍔ㄦ秷鎭傚弬瑙5.11.1鑺傦紝鈥滈敊璇棩蹇椻銆傚鏋滀綘涓嶆寚瀹氭枃浠跺悕锛MySQL浣跨敤host_name.err浣滀负鏂囦欢鍚嶃傚鏋滄枃浠跺悕娌℃湁鎵╁睍鍚嶏紝鍒欏姞涓.err鎵╁睍鍚嶃

         --log-isam[=file]

灏嗘墍鏈MyISAM鏇存敼璁板叆璇ユ枃浠(鍙湁璋冭瘯MyISAM鏃舵墠浣跨敤)

         (DEPRECATED) --log-long-format

璁板綍婵娲荤殑鏇存柊鏃ュ織銆佷簩杩涘埗鏇存柊鏃ュ織銆佸拰鎱㈡煡璇㈡棩蹇楃殑澶ч噺淇℃伅銆備緥濡傦紝鎵鏈夋煡璇㈢殑鐢ㄦ埛鍚嶅拰鏃堕棿鎴冲皢璁板綍涓嬫潵銆備笉璧炴垚閫夌敤璇ラ夐」锛屽洜涓哄畠鐜板湪浠h〃 榛樿璁板綍琛屼负銆(鍙傝--log-short-format鎻忚堪锛--log-queries-not-using-indexes閫夐」閫傚悎灏嗘湭浣跨敤绱㈠紩鐨勬煡璇㈣褰曞埌鎱㈡煡璇㈡棩蹇椾腑銆

         --log-queries-not-using-indexes

濡傛灉浣犵粨鍚--log-slow-queries浣跨敤璇ラ夐」锛屾湭浣跨敤绱㈠紩鐨勬煡璇篃琚褰曞埌鎱㈡煡璇㈡棩蹇椾腑銆傚弬瑙5.11.4鑺傦紝鈥滄參閫熸煡璇㈡棩蹇椻

         --log-short-format

璁板綍婵娲荤殑鏇存柊鏃ュ織銆佷簩杩涘埗鏇存柊鏃ュ織銆佸拰鎱㈡煡璇㈡棩蹇楃殑灏戦噺淇℃伅銆備緥濡傦紝鐢ㄦ埛鍚嶅拰鏃堕棿鎴充笉璁板綍涓嬫潵銆

         ---log-slow-admin-statements

灏嗘參绠$悊璇彞渚嬪OPTIMIZE TABLEANALYZE TABLEALTER TABLE璁板叆鎱㈡煡璇㈡棩蹇椼

         --log-slow-queries[=file]

灏嗘墍鏈夋墽琛屾椂闂磋秴杩long_query_time 绉掔殑鏌ヨ璁板叆璇ユ枃浠躲傚弬瑙5.11.4鑺傦紝鈥滄參閫熸煡璇㈡棩蹇椻銆傝缁嗕俊鎭弬瑙--log-long-format--log-short-format閫夐」鎻忚堪銆

 

         --log-warnings, -W

灏嗚鍛婁緥濡Aborted connection...鎵撳嵃鍒伴敊璇棩蹇椼傚缓璁惎鐢ㄨ閫夐」锛屼緥濡傦紝濡傛灉浣犱娇鐢ㄥ鍒 (浣犲彲浠ュ緱鍒板叧浜庢墍鍙戠敓浜嬫儏鐨勮缁嗕俊鎭紝渚嬪鍏充簬缃戠粶鏁呴殰鍜岄噸鏂拌繛鎺ョ殑娑堟伅)銆傞粯璁ゆ儏鍐典笅鍚敤璇ラ夐」锛涜鎯崇鐢ㄥ畠锛屼娇鐢--skip-log-warnings銆備腑鏂殑杩炴帴涓嶄細璁板叆閿欒鏃ュ織锛岄櫎闈炲煎ぇ浜1銆傚弬瑙A.2.10鑺傦紝鈥滈氫俊閿欒鍜屽け鏁堣繛鎺モ

         --low-priority-updates

琛ㄤ慨鏀(INSERT, REPLACE, DELETE, UPDATE)姣旈夋嫨鐨勪紭鍏堢骇瑕佷綆銆備篃鍙互閫氳繃{INSERT | REPLACE | DELETE | UPDATE} LOW_PRIORITY ... 鏉ラ檷浣庢煇涓煡璇㈢殑浼樺厛绾ф潵瀹炵幇锛屾垨閫氳繃SET LOW_PRIORITY_UPDATES=1鏉ユ洿鏀逛竴涓嚎绋嬬殑浼樺厛绾с傚弬瑙7.3.2鑺傦紝鈥滆〃閿佸畾浜嬪疁鈥

          --memlock

mysqld 杩涚▼閿佸畾鍦ㄥ唴瀛樹腑銆傚湪鏀寔mlockall()绯荤粺璋冪敤鐨勭郴缁熶笂鏈夋晥锛屼緥濡Solaris銆傚鏋滄搷浣滅郴缁熶娇mysqld鍦ㄧ‖鐩樹笂浜ゆ崲鏃跺嚭鐜伴棶棰橈紝鍙互涓轰綘鎻愪緵甯姪銆傝娉ㄦ剰浣跨敤璇ラ夐」鏃堕渶瑕佷互root杩愯鏈嶅姟鍣紝浣嗕粠瀹夊叏鑰冭檻骞朵笉鏄竴涓ソ娉ㄦ剰銆

         --myisam-recover [=option[,option...]]]

灏嗗瓨鍌ㄥ紩鎿MyISAM璁剧疆涓烘仮澶嶆ā寮忋傝閫夐」鍊兼槸DEFAULTBACKUPFORCEQUICK鍊肩殑浠讳綍缁勫悎銆傚鏋滀綘鎸囧畾澶氫釜鍊硷紝鐢ㄩ楀彿闂撮殧寮銆備綘杩樺彲浠ヤ娇鐢""鍊兼潵绂佺敤璇ラ夐」銆備娇鐢ㄥ鏋滆閫夐」锛屽綋mysqld鎵撳紑MyISAM琛ㄦ椂锛屾鏌ユ槸鍚﹁〃鏍囪涓哄穿婧冩垨娌℃湁姝g‘鍏抽棴銆(鍙湁鐢--skip-external-lockingare杩愯鏃讹紝鏈鍚庣殑閫夐」鎵嶅伐浣滐級濡傛灉鏄繖绉嶆儏鍐碉紝mysqld鍒欐鏌 琛ㄣ傚鏋滆〃琚牬鍧忥紝mysqld璇曞浘缁存姢瀹冦

涓嬮潰鐨勯夐」褰卞搷缁存姢宸ヤ綔锛

閫夐」

鎻忚堪

DEFAULT

涓庢病鏈変娇鐢--myisam-recover閫夐」鐩稿悓銆

BACKUP

濡傛灉鍦ㄦ仮澶嶈繃绋嬩腑锛屾暟鎹枃浠惰鏇存敼浜嗭紝灏tbl_name.MYD鏂囦欢澶囦唤涓tbl_name-datetime.BAK

FORCE

鍗充娇.MYD鏂囦欢灏嗕涪鎺夊涓涔熻繘琛屾仮澶嶃

QUICK

濡傛灉娌℃湁鍒犻櫎鍧楋紝涓嶈妫鏌ヨ〃涓殑琛屻

鍦ㄨ〃鑷姩淇鍓嶏紝MySQL閿欒鏃ュ織娣诲姞涓鏉℃敞瑙c傚鏋滀綘涓嶆兂鐢ㄦ埛骞叉秹骞叉秹澶у鏁伴棶棰橈紝浣犲簲浣跨敤BACKUP,FORCE閫夐」銆傝閫夐」寮哄埗缁存姢琛紝鍗充娇涓浜涜灏嗕細琚垹闄や篃涓嶄緥澶栵紝浣嗗畠淇濇寔鏃х殑鏁版嵁鏂囦欢鍋氫负澶囦唤锛屼互渚夸綘鍙互鍦ㄥ悗鏉ヨ繘琛屾鏌ャ

         --ndb-connectstring=connect_string

褰撲娇鐢NDB瀛樺偍寮曟搸鏃讹紝鍙互鎸囧嚭閫氳繃璁剧疆杩炴帴瀛楃涓查夐」鏉ュ垎鍙戠兢闆嗛厤缃殑绠$悊鏈嶅姟鍣ㄣ傜浉鍏宠娉曞弬瑙17.4.4.2鑺傦紝鈥淢ySQL绨囪繛鎺ュ瓧绗︿覆鈥

         --ndbcluster

濡傛灉浜岃繘鍒舵敮鎸NDB CLUSTER瀛樺偍寮曟搸锛屼娇鐢ㄨ閫夐」鍙互浠f浛绂佺敤MySQL Cluster鏀寔鐨 榛樿璁剧疆銆傚弬瑙绗17绔狅細MySQL绨

         --old-passwords

寮哄埗鏈嶅姟鍣ㄤ负鏂板瘑鐮佺敓鎴愮煭(4.1)瀵嗙爜鍝堝笇銆傚鏋滄湇鍔″櫒蹇呴』鏀寔鏃у鎴风绋嬪簭锛屼负淇濊瘉鍏煎鎬ц繖寰堟湁鐢ㄣ傚弬瑙5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥

         --one-thread

鍙娇鐢ㄤ竴涓嚎绋(鐢ㄤ簬鍦Linux涓皟璇)銆傚彧鏈夋湇鍔″櫒鍚敤浜嗚皟璇曪紝璇ラ夐」鎵嶅彲鐢ㄣ傚弬瑙E.1鑺傦紝鈥滆皟璇昅ySQL鏈嶅姟鍣ㄢ

         --open-files-limit=count

鐢ㄦ潵鏇存敼mysqld鏂囦欢鎻忚堪绗︾殑鏁伴噺銆傚鏋滄病鏈夎缃垨璁剧疆涓0锛屽垯mysqld閫氳繃setrlimit()浣跨敤璇ュ兼潵淇濆瓨鏂囦欢鎻忚堪绗︺傚鏋滆鍊间负0锛屽垯mysqld 淇濆瓨max_connections*5max_connections + table_cache*2(鍙栬緝澶ц)涓枃浠躲傚鏋mysqld缁欏嚭浣犻敊璇"鎵撳紑鐨勬枃浠跺お澶氥"锛屼綘搴旇瘯璇曞鍔犺鍊笺

         --pid-file=path

mysqld_safe浣跨敤鐨勮繘绋ID鏂囦欢鐨勮矾寰勩

         --port=port_num, -P port_num

甯у惉TCP/IP杩炴帴鏃朵娇鐢ㄧ殑绔彛鍙枫

         --safe-mode

璺宠繃涓浜涗紭鍖栭樁娈点

         (DEPRECATED) --safe-show-database

鍙傝5.7.3鑺傦紝鈥淢ySQL鎻愪緵鐨勬潈闄愨

         --safe-user-create

鍚敤鍚庡鏋滅敤鎴锋病鏈mysql.user琛ㄦ垨琛ㄤ腑鍒楃殑INSERT鏉冮檺锛屽垯鐢ㄦ埛涓嶈兘鐢GRANT璇彞鍒涘缓鏂扮敤鎴枫

         --secure-auth

涓嶅厑璁镐娇鐢ㄦ棫(4.1涔嬪墠)瀵嗙爜鐨勮处鎴疯繘琛岄壌瀹氥

         --shared-memory

鍚敤鏈湴瀹㈡埛绔殑鍏变韩鍐呭瓨杩炴帴銆傝閫夐」鍙敤浜Windows

         --shared-memory-base-name=name

鍏变韩鍐呭瓨杩炴帴鍚嶃傝閫夐」鍙敤浜Windows

         --skip-bdb

绂佺敤BDB瀛樺偍寮曟搸銆傝繖鏍峰彲浠ヨ妭鐪佸唴瀛橈紝骞跺彲鑳藉姞閫熸煇浜涙搷浣溿傚鏋滀綘闇瑕BDB琛ㄥ垯涓嶈浣跨敤璇ラ夐」銆

         --skip-concurrent-insert

鍏抽棴鍦ㄥ悓涓鏃堕棿鍦MyISAM琛ㄤ腑閫夋嫨鍜屾彃鍏ョ殑鑳藉姏銆(鍙湁浣犲彂鐜扮己闄锋椂鎵嶄娇鐢ㄨ閫夐」锛

         --skip-external-locking

涓嶈浣跨敤绯荤粺閿佸畾銆傝鎯充娇鐢myisamchk锛屼綘蹇呴』鍏抽棴鏈嶅姟鍣ㄣ(鍙傝1.4.3鑺傦紝鈥淢ySQL绋冲畾鎬р瑕侀伩鍏嶈闇姹傦紝浣跨敤MySQL Monitor涓殑CHECK TABLEREPAIR TABLE鏉ユ鏌ュ苟缁存姢MyISAM琛ㄣ

         --skip-grant-tables

璇ラ夐」浣挎湇鍔″櫒涓嶄娇鐢ㄦ潈闄愮郴缁熴傝鏉冮檺鍏佽璁块棶鏈嶅姟鍣ㄧ殑鐢ㄦ埛涓嶅彈闄愬埗鍦拌闂鎵鏈鏁版嵁搴銆備綘鍙互浠庣郴缁熷澹冲懡浠よ鎵цmysqladmin flush-privilegesmysqladmin reload鍛戒护锛屾垨鎵цMySQL FLUSH PRIVILEGES璇彞璁╄繍琛岀殑鏈嶅姟鍣ㄩ噸鏂板紑濮嬩娇鐢 鎺堟潈琛ㄣ

         --skip-host-cache

涓轰簡鏇村揩鍦板湪鍚嶇О-IP涔嬮棿杩涜瑙f瀽锛屼笉瑕佷娇鐢ㄥ唴閮ㄤ富鏈哄悕缂撳瓨銆傜浉鍙嶏紝姣忔瀹㈡埛绔繛鎺ユ椂鏌ヨDNS鏈嶅姟鍣ㄣ傚弬瑙7.5.6鑺傦紝鈥淢ySQL濡備綍浣跨敤DNS鈥

         --skip-innodb

绂佺敤InnoDB瀛樺偍寮曟搸銆傝繖鏍峰彲浠ヨ妭鐪佸唴瀛橈紝骞跺彲鑳藉姞閫熸煇浜涙搷浣溿傚鏋滀綘闇瑕BDB琛ㄥ垯涓嶈浣跨敤璇ラ夐」銆

         --skip-name-resolve

涓嶈瑙f瀽姝f鏌ュ鎴风杩炴帴鐨勪富鏈哄悕銆傚彧浣跨敤IP鍙枫傚鏋滀綘浣跨敤璇ラ」锛 鎺堟潈琛ㄤ腑鐨勬墍鏈Host鍒楀煎繀椤讳负IP鍙锋垨localhost銆傚弬瑙7.5.6鑺傦紝鈥淢ySQL濡備綍浣跨敤DNS鈥

         --skip-ndbcluster

绂佺敤NDB CLUSTER瀛樺偍寮曟搸銆傝繖鏄敮鎸NDB CLUSTER瀛樺偍寮曟搸鐨勪簩杩涘埗鐨勯粯璁よ缃紝璇存槑鍙湁鐢--ndbcluster閫夐」鏄惧紡瑕嗙洊--skip-ndbcluster閫夐」鏃讹紝绯荤粺鎵嶄负璇ュ瓨鍌ㄥ紩鎿庡垎閰嶅唴瀛樺拰鍏跺畠璧勬簮銆備娇鐢ㄧず渚嬪弬瑙17.4.3鑺傦紝鈥淢ySQL绨囩殑蹇熸祴璇曡缃

         --skip-networking

涓嶅抚鍚TCP/IP杩炴帴銆傚繀椤婚氳繃鍛藉悕绠¢亾鎴栧叡浜唴瀛(Windows)Unix濂楁帴瀛楁枃浠(Unix)瀹屾垚mysqld鐨勭浉浜掓搷浣溿傚浜庡彧鍏佽鏈湴瀹㈡埛绔殑绯荤粺锛屽ぇ鍔涙帹鑽愯閫夐」銆傚弬瑙7.5.6鑺傦紝鈥淢ySQL濡備綍浣跨敤DNS鈥

         --standalone

鍙傚悎鍩轰簬Windows-NT鐨勭郴缁燂紱鎸囧MySQL鏈嶅姟鍣ㄤ笉鍋氫负鏈嶅姟鏉ヨ繍琛屻

         --symbolic-links, --skip-symbolic-links

鍚敤鎴栫鐢ㄧ鍙烽摼鎺ユ敮鎸併傚湪WindowsUnix涓紝璇ラ夐」鐨勪綔鐢ㄦ槸涓嶅悓鐨勶細

o        Windows涓紝鍚敤绗﹀彿閾炬帴锛屼綘鍙互閫氳繃鍒涘缓鍖呭惈瀹為檯鐩綍璺緞鐨directory.sym鏂囦欢鏉ュ缓绔嬫暟鎹簱鐩綍鐨勭鍙烽摼鎺ャ傚弬瑙7.6.1.3鑺傦紝鈥滃湪Windows骞冲彴涓婁娇鐢ㄥ叧浜庢暟鎹簱鐨勭鍙烽摼鎺モ

Unix涓紝鍚敤绗﹀彿閾炬帴琛ㄧず浣犲彲浠ョ敤CREATE TABLE璇彞鐨INDEX DIRECTORYDATA DIRECTORY閫夐」灏MyISAM绱㈠紩鏂囦欢鎴栨暟鎹枃浠堕摼鎺ュ埌鍙︿竴涓洰褰曘傚鏋滀綘鍒犻櫎鎴栭噸鏂板懡鍚嶈〃锛岀鍙烽摼鎺ユ墍鎸囩殑鏂囦欢涔熻鍒犻櫎鎴栭噸鏂板懡鍚嶃傚弬瑙13.1.5鑺傦紝鈥淐REATE TABLE璇硶鈥

         --skip-safemalloc

濡傛灉MySQL閰嶇疆浜--with-debug=full锛屾墍鏈MySQL绋嬪簭鍦ㄥ唴瀛樺垎閰嶅拰閲婃斁鏃舵鏌ュ唴瀛樻槸鍚︽孩鍑恒傛鏌ュ緢鎱紝鍥犳濡傛灉浣犱笉闇瑕佷綘鍙互鐢--skip-safemalloc閫夐」鏉ラ伩鍏嶃

         --skip-show-database

浣跨敤璇ラ夐」锛屽彧鍏佽鍏锋湁SHOW DATABASES鏉冮檺鐨勭敤鎴锋墽琛SHOW DATABASES璇彞锛岃璇彞鏄剧ず鎵鏈夋暟鎹簱鍚嶃備笉浣跨敤璇ラ夐」锛屽厑璁告墍鏈夌敤鎴锋墽琛SHOW DATABASES锛屼絾鍙悜鍏锋湁SHOW DATABASES鏉冮檺鎴栭儴鍒嗘暟鎹簱鏉冮檺鐨勭敤鎴锋樉绀烘瘡涓暟鎹簱鍚嶃傝娉ㄦ剰鍏ㄥ眬鏉冮檺涓烘暟鎹簱鐨勪竴绉嶆潈闄愩

         --skip-stack-trace

涓嶈窡韪啓鍫嗘爤銆傚綋璋冭瘯杩愯mysqld鏃惰閫夐」鏈夌敤銆傚湪涓浜涚郴缁熶腑锛屼綘杩樺繀椤讳娇鐢ㄨ閫夐」鏉ヨ幏寰楀唴鏍告枃浠躲傚弬瑙E.1鑺傦紝鈥滆皟璇昅ySQL鏈嶅姟鍣ㄢ

         --skip-thread-priority

鍦ㄥ揩閫熷搷搴斾腑绂佺敤绾跨▼浼樺厛绾с

         --socket=path

Unix涓紝璇ラ夐」鎸囧畾鐢ㄤ簬鏈湴杩炴帴鐨Unix濂楁帴瀛楁枃浠躲 榛樿鍊兼槸/tmp/mysql.sock銆傚湪Windows涓紝璇ラ夐」鎸囧畾鏈湴杩炴帴鎵浣跨敤鐨勭閬撳悕銆 榛樿鍊兼槸MySQL

         --sql-mode=value[,value[,value...]]

MySQL璁剧疆涓SQL妯″紡銆傚弬瑙5.3.2鑺傦紝鈥淪QL鏈嶅姟鍣ㄦā寮忊

         --temp-pool

璇ラ夐」浣挎湇鍔″櫒鍒涘缓鐨勫ぇ澶氭暟涓存椂鏂囦欢浣跨敤涓绯诲垪鏂囦欢鍚嶏紝鑰屼笉鏄瘡涓柊鏂囦欢浣跨敤鍞竴鐨勬枃浠跺悕銆傝繖鏍疯В鍐充簡鍦Linux鍐呮牳涓敤 涓嶅悓鐨勫悕鍒涘缓璁稿鏂版枃浠剁殑闂銆傚湪浠ュ墠锛Linux浼间箮鈥滄硠婕忊濆唴瀛橈紝鍥犱负瀹冭鐩存帴鍒嗛厤鍒directory entry缂撳瓨鑰屼笉鏄‖鐩樼紦瀛樸

         --transaction-isolation=level

璁剧疆榛樿浜嬪姟闅旂绾у埆锛屽彲浠READ-UNCOMMITTEDREAD-COMMITTEEREPEATABLE-READSERIALIZABLE銆傚弬瑙13.4.6鑺傦紝鈥淪ET TRANSACTION璇硶鈥

         --tmpdir=path, -t path

鍒涘缓涓存椂鏂囦欢鐨勭洰褰曡矾寰勩傞粯璁/tmp鐩綍鍦ㄥお灏忎笉鑳藉绾充复鏃惰〃鐨勫垎鍖烘椂璇ラ夐」寰堟湁鐢ㄣ傝閫夐」鎺ュ彈round-robin妯″紡鐨勫嚑涓矾寰勩傚湪Unix涓矾寰勫簲鐢ㄥ啋鍙(:) 闂撮殧寮锛屽湪WindowsNetWareOS/2涓敤鍒嗗彿() 闂撮殧寮銆傚鏋MySQL鏈嶅姟鍣ㄤ负澶嶅埗浠庢満锛屼綘涓嶅簲璁--tmpdir鎸囧悜鍩轰簬鍐呭瓨鐨勬枃浠剁郴缁熶腑鐨勭洰褰曟垨鏈嶅姟鍣ㄤ富鏈洪噸鍚椂浼氭竻闄ょ殑鐩綍銆傚鍒朵粠鏈洪渶瑕佷复鏃舵枃浠讹紝鏈哄櫒閲嶅惎鏃跺彲浠ュ鍒朵复鏃惰〃鎴栨墽琛LOAD DATA INFILE鎿嶄綔銆傚鏋滄湇鍔″櫒閲嶅惎鏃朵复鏃舵枃浠剁洰褰曚腑鐨勬枃浠朵涪澶憋紝澶嶅埗澶辫触銆

         --user={user_name | user_id}, -u {user_name | user_id}

user_name鎴栨暟瀛楃敤鎴ID user_id杩愯mysqld鏈嶅姟鍣(鐢ㄦ埛鈥濇寚绯荤粺鐧诲綍璐︽埛锛岃屼笉鏄 鎺堟潈琛ㄤ腑鎵鍒楃殑MySQL鐢ㄦ埛锛

root鍚姩mysqld寮哄埗浣跨敤璇ラ夐」銆傛湇鍔″櫒鍦ㄥ惎鍔ㄥ簭鍒椾腑鏇存敼鐢ㄦ埛ID锛岃瀹冨仛涓哄叿浣撶敤鎴疯屼笉鏄root杩愯銆傚弬瑙5.6.1鑺傦紝鈥滈氱敤瀹夊叏鎸囧崡鈥

瑕侀伩鍏嶇敤鎴峰湪my.cnf鏂囦欢涓坊鍔--user=root閫夐」(浣挎湇鍔″櫒鐢root杩愯)鏃跺彲鑳藉嚭鐜扮殑瀹夊叏婕忔礊锛mysqld鍙娇鐢ㄦ寚瀹氱殑绗1--user閫夐」锛屽鏋滄湁澶氫釜--user閫夐」鍒欎細鍑虹幇璀﹀憡銆傚湪鍛戒护琛岄夐」鍓嶅鐞/etc/my.cnf$MYSQL_HOME/my.cnf涓殑閫夐」锛屽洜姝ゅ缓璁綘鍦/etc/my.cnf涓斁涓涓--user閫夐」锛屽苟鎸囧畾root涔嬪鐨勫叾瀹冨笺傚湪鍏跺畠--user閫夐」鍓嶅厛鎵惧埌/etc/my.cnf涓殑閫夐」锛岀‘淇濇湇鍔″櫒鐢ㄥ叾瀹冪敤鎴疯繍琛岋紝濡傛灉鎵惧埌鍏跺畠--user閫夐」鍒欎細鍑虹幇璀﹀憡銆

         --version, -V

鏄剧ず鐗堟湰淇℃伅骞堕鍑恒

浣犲彲浠ヤ娇鐢--var_name=value褰㈠紡鐨勯夐」涓烘湇鍔″櫒绯荤粺鍙橀噺銆備緥濡傦紝--key_buffer_size=32M灏嗗彉閲key_buffer_size璁句负32MB

璇锋敞鎰忚缃彉閲忔椂锛MySQL鍙互鑷姩灏嗗畠绾犳鍒版煇涓粰瀹氳寖鍥村唴锛屾垨濡傛灉鍙厑璁告煇涓硷紝鍒欏皢璁剧疆鍊艰皟鑺傚埌鏈鎺ヨ繎鍏佽鐨勫笺

杩樺彲浠ラ氳繃--set-variable=var_name=value-O var_name=value璇硶鏉ヨ缃彉閲忋備絾鏄紝鐜板湪涓嶈禐鎴愪娇鐢ㄨ璇硶銆

5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥瀹屽叏鎻忚堪浜嗗叏閮ㄧ郴缁熷彉閲忋傝皟鑺傛湇鍔″櫒鍙傛暟閮ㄥ垎鍖呮嫭濡備綍瀵逛粬浠繘琛屼紭鍖栥傚弬瑙7.5.2鑺傦紝鈥滆皟鑺傛湇鍔″櫒鍙傛暟鈥

浣犲彲浠ョ敤SET璇彞鏇存敼澶у鏁版湇鍔″櫒绯荤粺鍙橀噺鐨勫笺傚弬瑙13.5.3鑺傦紝鈥淪ET璇硶鈥

濡傛灉浣犳兂鐢SET 闄愬埗鍚姩椤瑰彲璁剧殑鏈澶у硷紝浣犲彲浠ヤ娇鐢--maximum-var_name鍛戒护琛岄夐」鏉ュ畾涔夈

5.3.2. SQL鏈嶅姟鍣ㄦā寮

MySQL鏈嶅姟鍣ㄥ彲浠ヤ互涓嶅悓鐨SQL妯″紡鏉ユ搷浣滐紝骞朵笖鍙互涓轰笉鍚屽鎴风搴旂敤涓嶅悓妯″紡銆傝繖鏍锋瘡涓簲鐢ㄧ▼搴忓彲浠ユ牴鎹嚜宸辩殑闇姹傛潵瀹氬埗鏈嶅姟鍣ㄧ殑鎿嶄綔妯″紡銆

妯″紡瀹氫箟MySQL搴旀敮鎸佸摢浜SQL璇硶锛屼互鍙婂簲鎵ц鍝鏁版嵁楠岃瘉妫鏌ャ傝繖鏍峰彲浠ユ洿瀹规槗鍦板湪涓嶅悓鐨勭幆澧冧腑浣跨敤MySQL锛屽苟缁撳悎鍏跺畠鏁版嵁搴撴湇鍔″櫒浣跨敤MySQL

浣犲彲浠ョ敤--sql-mode="modes"閫夐」鍚姩mysqld璁剧疆榛樿SQL妯″紡銆傚鏋滀綘鎯宠閲嶈锛岃鍊艰繕鍙互涓虹┖(--sql-mode ="")

浣犺繕鍙互鍦ㄥ惎鍔ㄥ悗鐢SET [SESSION|GLOBAL] sql_mode='modes'璇彞璁剧疆sql_mode鍙橀噺鏉ユ洿鏀SQL妯″紡銆傝缃 GLOBAL鍙橀噺鏃堕渶瑕佹嫢鏈SUPER鏉冮檺锛屽苟涓斾細褰卞搷浠庨偅鏃惰捣杩炴帴鐨勬墍鏈夊鎴风鐨勬搷浣溿傝缃SESSION鍙橀噺鍙奖鍝嶅綋鍓嶇殑瀹㈡埛绔備换浣曞鎴风鍙互闅忔椂鏇存敼鑷繁鐨勪細璇 sql_mode鍊笺

Modesis鏄敤閫楀彿()闂撮殧寮鐨勪竴绯诲垪涓嶅悓鐨勬ā寮忋備綘鍙互鐢SELECT @@sql_mode璇彞鏌ヨ褰撳墠鐨勬ā寮忋傞粯璁ゅ兼槸绌(娌℃湁璁剧疆浠讳綍妯″紡)

涓昏閲嶈sql_mode鍊间负锛

         ANSI

鏇存敼璇硶鍜岃涓猴紝浣垮叾鏇寸鍚堟爣鍑SQL

         STRICT_TRANS_TABLES

濡傛灉涓嶈兘灏嗙粰瀹氱殑鍊兼彃鍏ュ埌浜嬪姟琛ㄤ腑锛屽垯鏀惧純璇ヨ鍙ャ傚浜庨潪浜嬪姟琛紝濡傛灉鍊煎嚭鐜板湪鍗曡璇彞鎴栧琛岃鍙ョ殑绗1琛岋紝鍒欐斁寮冭璇彞銆傛湰鑺傚悗闈㈢粰鍑轰簡鏇磋缁嗙殑鎻忚堪銆

         TRADITIONAL

Make MySQL鐨勮涓鸿薄鈥浼犵粺SQL鏁版嵁搴撶郴缁熴傝妯″紡鐨勭畝鍗曟弿杩版槸褰撳湪鍒椾腑鎻掑叆涓嶆纭殑鍊兼椂鈥滅粰鍑閿欒鑰屼笉鏄鍛鈥濄閲婏細涓鏃﹀彂鐜伴敊璇珛鍗虫斁寮INSERT/UPDATE銆傚鏋滀綘浣跨敤闈炰簨鍔″瓨鍌ㄥ紩鎿庯紝杩欑鏂瑰紡涓嶆槸浣犳兂瑕佺殑锛屽洜涓哄嚭鐜伴敊璇墠杩涜鐨勬暟鎹洿鏀逛笉浼氣滄粴鍔ㄢ濓紝缁撴灉鏄洿鏂扳滃彧杩涜浜嗕竴閮ㄥ垎鈥濄

鏈墜鍐屾寚鈥涓ユ牸妯″紡鈥濓紝琛ㄧず鑷冲皯STRICT _TRANS_TABLESSTRICT _ALL_TABLES琚惎鐢ㄧ殑妯″紡銆

涓嬮潰鎻忚堪浜嗘敮鎸佺殑鎵鏈夋ā寮忥細

         ALLOW_INVALID_DATES

鍦ㄤ弗鏍兼ā寮忎笅涓嶈妫鏌ュ叏閮ㄦ棩鏈熴傚彧妫鏌112涔嬮棿鐨勬湀浠藉拰131涔嬮棿鐨勬棩銆傝繖鍦Web搴旂敤绋嬪簭涓紝褰撲綘浠庝笁涓笉鍚岀殑瀛楁鑾峰彇骞淬佹湀銆佹棩锛屽苟涓旀兂瑕佺‘鍒囦繚瀛樼敤鎴锋彃鍏ョ殑鍐呭(涓嶈繘琛屾棩鏈熼獙璇)鏃跺緢閲嶈銆傝妯″紡閫傜敤浜DATEDATETIME鍒椼備笉閫傚悎TIMESTAMP鍒楋紝TIMESTAMP鍒楅渶瑕侀獙璇佹棩鏈熴

鍚敤涓ユ牸妯″紡鍚庯紝鏈嶅姟鍣ㄩ渶瑕佸悎娉曠殑鏈堝拰鏃ワ紝涓嶄粎浠呮槸鍒嗗埆鍦112131鑼冨洿鍐呫備緥濡傦紝绂佺敤涓ユ牸妯″紡鏃'2004-04-31'鏄悎娉曠殑锛屼絾鍚敤涓ユ牸妯″紡鍚庢槸闈炴硶鐨勩傝鎯冲湪涓ユ牸妯″紡鍏佽閬帺鍥哄畾鏃ユ湡锛岃繕搴斿惎鐢ALLOW_INVALID_DATES

         ANSI_QUOTES

灏嗏"鈥欒涓鸿瘑鍒寮曞彿(`鈥欏紩鍙峰瓧绗)锛屼笉瑕佽涓哄瓧绗︿覆鐨勫紩鍙峰瓧绗︺傚湪ANSI妯″紡锛屼綘鍙互浠嶇劧浣跨敤鈥`鈥欐潵寮曠敤璇嗗埆绗︺傚惎鐢ANSI_QUOTES鍚庯紝浣犱笉鑳界敤鍙屽紩鍙锋潵寮曠敤瀛楃涓诧紝鍥犱负瀹冭瑙i噴涓鸿瘑鍒銆

         ERROR_FOR_DIVISION_BY_ZERO

鍦ㄤ弗鏍兼ā寮忥紝鍦INSERTUPDATE杩囩▼涓紝濡傛灉琚浂闄(MOD(X0))锛屽垯浜х敓閿欒(鍚﹀垯涓鸿鍛)銆傚鏋滄湭缁欏嚭璇ユā寮忥紝琚浂闄ゆ椂MySQL杩斿洖NULL銆傚鏋滅敤鍒INSERT IGNOREUPDATE IGNORE涓紝MySQL鐢熸垚琚浂闄よ鍛婏紝浣嗘搷浣滅粨鏋滀负NULL

         HIGH_NOT_PRECEDENCE

NOT鎿嶄綔绗︾殑浼樺厛椤哄簭鏄〃杈惧紡渚嬪NOT a BETWEEN b AND c琚В閲婁负NOT (a BETWEEN b AND c)銆傚湪涓浜涙棫鐗堟湰MySQL涓紝 琛ㄨ揪寮忚瑙i噴涓(NOT a) BETWEEN b AND c銆傚惎鐢HIGH_NOT_PRECEDENCESQL妯″紡锛屽彲浠ヨ幏寰椾互鍓嶇殑鏇撮珮浼樺厛绾х殑缁撴灉銆

mysql> SET sql_mode = '';
mysql> SELECT NOT 1 BETWEEN -5 AND 5;
        -> 0
mysql> SET sql_mode = 'broken_not';
mysql> SELECT NOT 1 BETWEEN -5 AND 5;
        -> 1

         IGNORE_SPACE

鍏佽鍑芥暟鍚嶅拰鈥(鈥欎箣闂存湁绌烘牸銆傚己鍒跺皢鎵鏈夊嚱鏁板悕瑙嗕负淇濆瓨鐨勫瓧銆傜粨鏋滄槸锛屽鏋滀綘鎯宠璁块棶淇濆瓨涓哄瓧鐨勬暟鎹簱銆佽〃鎴栧垪鍚嶏紝浣犲繀椤诲紩鐢ㄥ畠銆備緥濡傦紝鍥犱负鏈USER()鍑芥暟锛mysql鏁版嵁搴撲腑鐨user琛ㄥ悕鍜岃琛ㄥ唴鐨User鍒楄淇濆瓨涓嬫潵锛屽洜姝や綘蹇呴』寮曠敤瀹冧滑锛

SELECT "User" FROM mysql."user";

         NO_AUTO_CREATE_USER

闃叉GRANT鑷姩鍒涘缓鏂扮敤鎴凤紝闄ら潪杩樻寚瀹氫簡瀵嗙爜銆

         NO_AUTO_VALUE_ON_ZERO

NO_AUTO_VALUE_ON_ZERO褰卞搷AUTO_INCREMENT鍒楃殑澶勭悊銆備竴鑸儏鍐碉紝浣犲彲浠ュ悜璇ュ垪鎻掑叆NULL0鐢熸垚涓嬩竴涓簭鍒楀彿銆NO_AUTO_VALUE_ON_ZERO绂佺敤0锛屽洜姝ゅ彧鏈NULL鍙互鐢熸垚涓嬩竴涓簭鍒楀彿銆

濡傛灉灏0淇濆瓨鍒拌〃鐨AUTO_INCREMENT鍒楋紝璇ユā寮忎細寰堟湁鐢ㄣ(涓嶆帹鑽愰噰鐢ㄨ鎯緥)銆備緥濡傦紝濡傛灉浣犵敤mysqldump杞偍琛ㄥ苟閲嶈浇锛MySQL閬囧埌0鍊间竴鑸細鐢熸垚鏂扮殑搴忓垪鍙凤紝鐢熸垚鐨勮〃鐨勫唴瀹逛笌杞偍鐨勮〃涓嶅悓銆傞噸杞借浆鍌ㄦ枃浠跺墠鍚敤NO_AUTO_VALUE_ON_ZERO鍙互瑙e喅璇ラ棶棰樸mysqldump鍦ㄨ緭鍑轰腑鑷姩鍖呮嫭鍚敤NO_AUTO_VALUE_ON_ZERO鐨勮鍙ャ

         NO_BACKSLASH_ESCAPES

绂佺敤鍙嶆枩绾垮瓧绗(\)鍋氫负瀛楃涓插唴鐨勯鍑哄瓧绗︺傚惎鐢ㄨ妯″紡锛屽弽鏂滅嚎鍒欐垚涓烘櫘閫氬瓧绗︺

         NO_DIR_IN_CREATE

鍒涘缓琛ㄦ椂锛屽拷瑙嗘墍鏈INDEX DIRECTORYDATA DIRECTORY鎸囦护銆傝閫夐」瀵逛粠澶嶅埗鏈嶅姟鍣ㄦ湁鐢ㄣ

         NO_ENGINE_SUBSTITUTION

濡傛灉闇瑕佺殑瀛樺偍寮曟搸琚鐢ㄦ垨鏈紪璇戯紝鍙互闃叉鑷姩鏇挎崲瀛樺偍寮曟搸銆

         NO_FIELD_OPTIONS

涓嶈鍦SHOW CREATE TABLE鐨勮緭鍑轰腑鎵撳嵃MySQL涓撶敤鍒楅夐」銆傝妯″紡鍦ㄥ彲绉绘妯″紡锛portability mode锛変笅鐢ㄤ簬mysqldump

         NO_KEY_OPTIONS

涓嶈鍦SHOW CREATE TABLE鐨勮緭鍑轰腑鎵撳嵃MySQL涓撶敤绱㈠紩閫夐」銆傝妯″紡鍦ㄥ彲绉绘妯″紡锛portability mode锛変笅鐢ㄤ簬mysqldump

         NO_TABLE_OPTIONS

涓嶈鍦SHOW CREATE TABLE鐨勮緭鍑轰腑鎵撳嵃MySQL涓撶敤琛ㄩ夐」锛堜緥濡ENGINE锛夈傝妯″紡鍦ㄥ彲绉绘妯″紡锛portability mode锛変笅鐢ㄤ簬mysqldump

         NO_UNSIGNED_SUBTRACTION

鍦ㄥ噺杩愮畻涓紝濡傛灉鏌愪釜鎿嶄綔鏁版病鏈夌鍙凤紝涓嶈灏嗙粨鏋滄爣璁颁负UNSIGNED銆傝娉ㄦ剰杩欐牱浣UNSIGNED BIGINT涓嶈兘100%鐢ㄤ簬涓婁笅鏂囦腑銆傚弬瑙12.8鑺傦紝鈥淐ast鍑芥暟鍜屾搷浣滅鈥

 

         NO_ZERO_DATE

鍦ㄤ弗鏍兼ā寮忥紝涓嶈灏 '0000-00-00'鍋氫负鍚堟硶鏃ユ湡銆備綘浠嶇劧鍙互鐢IGNORE閫夐」鎻掑叆闆舵棩鏈熴傚湪闈炰弗鏍兼ā寮忥紝鍙互鎺ュ彈璇ユ棩鏈燂紝浣嗕細鐢熸垚璀﹀憡銆

         NO_ZERO_IN_DATE

鍦ㄤ弗鏍兼ā寮忥紝涓嶆帴鍙楁湀鎴栨棩閮ㄥ垎涓0鐨勬棩鏈熴傚鏋滀娇鐢IGNORE閫夐」锛屾垜浠负绫讳技鐨勬棩鏈熸彃鍏'0000-00-00'銆傚湪闈炰弗鏍兼ā寮忥紝鍙互鎺ュ彈璇ユ棩鏈燂紝浣嗕細鐢熸垚璀﹀憡銆

         ONLY_FULL_GROUP_BY

涓嶈璁GROUP BY閮ㄥ垎涓殑鏌ヨ鎸囧悜鏈夋嫨鐨勫垪銆

         PIPES_AS_CONCAT

||瑙嗕负瀛楃涓茶繛鎺ユ搷浣滅锛堬紜锛(CONCAT())锛岃屼笉瑙嗕负OR

         REAL_AS_FLOAT

REAL瑙嗕负FLOAT鐨勫悓涔夎瘝锛岃屼笉鏄DOUBLE鐨勫悓涔夎瘝銆

         STRICT_TRANS_TABLES

涓烘墍鏈夊瓨鍌ㄥ紩鎿庡惎鐢ㄤ弗鏍兼ā寮忋傞潪娉曟暟鎹艰鎷掔粷銆傚悗闈㈡湁璇︾粏璇存槑銆

         STRICT_TRANS_TABLES

涓轰簨鍔″瓨鍌ㄥ紩鎿庡惎鐢ㄤ弗鏍兼ā寮忥紝涔熷彲鑳戒负闈炰簨鍔″瓨鍌ㄥ紩鎿庡惎鐢ㄤ弗鏍兼ā寮忋傚悗闈㈡湁璇︾粏璇存槑銆

涓ユ牸妯″紡鎺у埗MySQL濡備綍澶勭悊闈炴硶鎴栦涪澶辩殑杈撳叆鍊笺傛湁鍑犵鍘熷洜鍙互浣夸竴涓间负闈炴硶銆備緥濡傦紝鏁版嵁绫诲瀷閿欒锛屼笉閫傚悎鍒楋紝鎴栬秴鍑鸿寖鍥淬傚綋鏂版彃鍏ョ殑琛屼笉鍖呭惈鏌愬垪鐨勬病鏈夋樉绀哄畾涔DEFAULT瀛愬彞鐨勫硷紝鍒欒鍊艰涓㈠け銆

瀵逛簬浜嬪姟琛紝褰撳惎鐢STRICT_ALL_TABLESSTRICT_TRANS_TABLES妯″紡鏃讹紝濡傛灉璇彞涓湁闈炴硶鎴栦涪澶卞硷紝鍒欎細鍑虹幇閿欒銆傝鍙ヨ鏀惧純骞舵粴鍔ㄣ

瀵逛簬闈炰簨鍔¤〃锛屽鏋滄彃鍏ユ垨鏇存柊鐨勭1琛屽嚭鐜板潖鍊硷紝涓ょ妯″紡鐨勮涓虹浉鍚屻傝鍙ヨ鏀惧純锛岃〃淇濇寔涓嶅彉銆傚鏋滆鍙ユ彃鍏ユ垨淇敼澶氳锛屽苟涓斿潖鍊煎嚭鐜板湪绗2鎴栧悗闈㈢殑琛岋紝缁撴灉鍙栧喅浜庡惎鐢ㄤ簡鍝釜涓ユ牸閫夐」锛

         瀵逛簬STRICT_ALL_TABLESMySQL杩斿洖閿欒骞跺拷瑙嗗墿浣欑殑琛屻備絾鏄紝鍦ㄨ繖绉嶆儏鍐典笅锛屽墠闈㈢殑琛屽凡缁忚鎻掑叆鎴栨洿鏂般傝繖璇存槑浣犲彲浠ラ儴鍒嗘洿鏂帮紝杩欏彲鑳戒笉鏄綘鎯宠鐨勩傝閬垮厤杩欑偣锛屾渶濂戒娇鐢ㄥ崟琛岃鍙ワ紝鍥犱负杩欐牱鍙互涓嶆洿鏀硅〃鍗冲彲浠ユ斁寮冦

         瀵逛簬STRICT_TRANS_TABLESMySQL灏嗛潪娉曞艰浆鎹负鏈鎺ヨ繎璇ュ垪鐨勫悎娉曞煎苟鎻掑叆璋冩暣鍚庣殑鍊笺傚鏋滃间涪澶憋紝MySQL鍦ㄥ垪涓彃鍏ラ殣寮 榛樿鍊笺傚湪浠讳綍鎯呭喌涓嬶紝MySQL閮戒細鐢熸垚璀﹀憡鑰屼笉鏄粰鍑洪敊璇苟缁х画鎵ц璇彞銆13.1.5鑺傦紝鈥淐REATE TABLE璇硶鈥鎻忚堪浜嗛殣寮忛粯璁ゅ笺

涓ユ牸妯″紡涓嶅厑璁搁潪娉曟棩鏈燂紝渚嬪'2004-04-31'銆傚畠涓嶅厑璁哥姝㈡棩鏈熶娇鐢ㄢ滈浂鈥濋儴鍒嗭紝渚嬪'2004-04-00'鎴栤鈥濇棩鏈熴傝鎯崇姝紝搴斿湪涓ユ牸妯″紡鍩虹涓婏紝鍚敤NO_ZERO_IN_DATENO_ZERO_DATE SQL妯″紡銆

濡傛灉浣犱笉浣跨敤涓ユ牸妯″紡(鍗充笉鍚敤STRICT_TRANS_TABLESSTRICT_ALL_TABLES妯″紡)锛屽浜庨潪娉曟垨涓㈠け鐨勫硷紝MySQL灏嗘彃鍏ヨ皟鏁村悗鐨勫煎苟缁欏嚭璀﹀憡銆傚湪涓ユ牸妯″紡锛屼綘鍙互閫氳繃INSERT IGNOREUPDATE IGNORE鏉ュ疄鐜般傚弬瑙13.5.4.22鑺傦紝鈥淪HOW WARNINGS璇硶鈥

涓嬮潰鐨勭壒娈婃ā寮忓揩閫熺粍鍚堜簡鍓嶉潰鎵鍒楃殑妯″紡銆

鍏朵腑鍖呮嫭澶у鏁版渶鏂扮増鏈MySQL涓殑鎵鏈夋ā寮忓笺傛棫鐗堟湰涓紝缁勫悎妯″紡涓嶅寘鎷柊鐗堟湰涓病鏈夌殑涓嶉傜敤鐨勫叿浣撴ā寮忓笺

         ANSI

绛夊悓REAL_AS_FLOATPIPES_AS_CONCATANSI_QUOTESIGNORE_SPACE銆傚弬瑙1.8.3鑺傦紝鈥滃湪ANSI妯″紡涓嬭繍琛孧ySQL鈥

         DB2

绛夊悓PIPES_AS_CONCATANSI_QUOTESIGNORE_SPACENO_KEY_OPTIONSNO_TABLE_OPTIONSNO_FIELD_OPTIONS

         MAXDB

绛夊悓PIPES_AS_CONCATANSI_QUOTESIGNORE_SPACENO_KEY_OPTIONSNO_TABLE_OPTIONSNO_FIELD_OPTIONSNO_AUTO_CREATE_USER

         MSSQL

绛夊悓PIPES_AS_CONCATANSI_QUOTESIGNORE_SPACENO_KEY_OPTIONSNO_TABLE_OPTIONSNO_FIELD_OPTIONS

         MYSQL323

绛夊悓NO_FIELD_OPTIONSHIGH_NOT_PRECEDENCE

         MYSQL40

绛夊悓NO_FIELD_OPTIONSHIGH_NOT_PRECEDENCE

         ORACLE

绛夊悓PIPES_AS_CONCATANSI_QUOTESIGNORE_SPACENO_KEY_OPTIONSNO_TABLE_OPTIONSNO_FIELD_OPTIONSNO_AUTO_CREATE_USER

         POSTGRESQL

绛夊悓PIPES_AS_CONCATANSI_QUOTESIGNORE_SPACENO_KEY_OPTIONSNO_TABLE_OPTIONSNO_FIELD_OPTIONS

         TRADITIONAL

绛夊悓STRICT_TRANS_TABLES銆丼TRICT_ALL_TABLES銆丯O_ZERO_IN_DATE銆丯O_ZERO_DATE銆丒RROR_FOR_DIVISION_BY_ZERO銆丯O_AUTO_CREATE_USER銆

5.3.3. 鏈嶅姟鍣ㄧ郴缁熷彉閲

鏈嶅姟鍣ㄥ皢缁存姢璁稿琛ㄧず鍏堕厤缃殑绯荤粺鍙橀噺銆傛墍鏈夊彉閲忓潎鏈夐粯璁ゅ笺傚彲浠ュ湪鍛戒护琛屼腑鎴栭夐」鏂囦欢璁剧疆閫夐」鍦ㄦ湇鍔″櫒鍚姩鏃跺瀹冧滑杩涜璁剧疆銆傚ぇ澶氭暟鍙互鍦ㄨ繍琛屾椂浣跨敤SET璇彞鏉ヨ缃

mysqld鏈嶅姟鍣缁存姢涓ょ鍙橀噺銆傚叏灞鍙橀噺褰卞搷鏈嶅姟鍣ㄧ殑鍏ㄥ眬鎿嶄綔銆備細璇濆彉閲忓奖鍝嶅叿浣撳鎴风杩炴帴鐩稿叧鎿嶄綔銆

鏈嶅姟鍣ㄥ惎鍔ㄦ椂锛屽皢鎵鏈夊叏灞鍙橀噺鍒濆鍖栦负榛樿鍊笺傚彲浠ュ湪閫夐」鏂囦欢鎴栧懡浠よ涓寚瀹氱殑閫夐」鏉ユ洿鏀硅繖浜涢粯璁ゅ笺傛湇鍔″櫒鍚姩鍚庯紝閫氳繃杩炴帴鏈嶅姟鍣ㄥ苟鎵цSET GLOBAL var_name璇彞鍙互鏇存敼鍔ㄦ佸叏灞鍙橀噺銆傝鎯虫洿鏀瑰叏灞鍙橀噺锛屽繀椤诲叿鏈SUPER鏉冮檺銆

鏈嶅姟鍣ㄨ繕涓烘瘡涓鎴风杩炴帴缁存姢浼氳瘽鍙橀噺銆傝繛鎺ユ椂浣跨敤鐩稿簲鍏ㄥ眬鍙橀噺鐨勫綋鍓嶅煎瀹㈡埛绔細璇濆彉閲忚繘琛屽垵濮嬪寲銆傚鎴峰彲浠ラ氳繃SET SESSION var_name璇彞鏉ユ洿鏀瑰姩鎬佷細璇濆彉閲忋傝缃細璇濆彉閲忎笉闇瑕佺壒娈婃潈闄愶紝浣嗗鎴峰彲浠ュ彧鏇存敼鑷繁鐨勪細璇濆彉閲忥紝鑰屼笉鏇存敼鍏跺畠瀹㈡埛鐨勪細璇濆彉閲忋

浠讳綍璁块棶鍏ㄥ眬鍙橀噺鐨勫鎴风閮藉彲浠ョ湅瑙佸鍏ㄥ眬鍙橀噺鐨勬洿鏀广備絾鏄紝瀹冨彧褰卞搷鍦ㄦ洿鏀瑰悗杩炴帴鐨勪粠璇ュ叏灞鍙橀噺鍒濆鍖栫浉搴斾細璇濆彉閲忕殑瀹㈡埛绔傚畠涓嶄細褰卞搷宸茬粡杩炴帴涓婄殑瀹㈡埛绔殑浼氳瘽鍙橀噺(鐢氳嚦鏄墽琛SET GLOBAL璇彞鐨勫鎴风)

褰撲娇鐢ㄥ惎鍔ㄩ夐」璁剧疆鍙橀噺鏃讹紝鍙橀噺鍊煎彲浠ヤ娇鐢ㄥ悗缂KMG鍒嗗埆琛ㄧず鍗冨瓧鑺傘佸厗瀛楄妭鎴gigabytes銆備緥濡傦紝涓嬮潰鐨勫懡浠ゅ惎鍔ㄦ湇鍔″櫒鏃剁殑閿肩紦鍐插尯澶у皬涓16 megabytes

mysqld --key_buffer_size=16M

鍚庣紑鐨勫ぇ灏忓啓缇庡叧绯伙紱16M16m鏄悓鏍风殑銆

杩愯鏃讹紝浣跨敤SET璇彞鏉ヨ缃郴缁熷彉閲忋傛鏃讹紝涓嶈兘浣跨敤鍚庣紑锛屼絾鍊煎彲浠ラ噰鍙栦笅鍒楄〃杈惧紡锛

mysql> SET sort_buffer_size = 10 * 1024 * 1024;

瑕佹兂鏄惧紡鎸囧畾鏄惁璁剧疆鍏ㄥ眬鎴栦細璇濆彉閲忥紝浣跨敤GLOBALSESSION閫夐」锛

mysql> SET GLOBAL sort_buffer_size = 10 * 1024 * 1024;
mysql> SET SESSION sort_buffer_size = 10 * 1024 * 1024;

涓や釜閫夐」鍧囨病鏈夛紝鍒欒鍙ヨ缃細璇濆彉閲忋

5.3.3.1鑺傦紝鈥滃姩鎬佺郴缁熷彉閲忊涓垪鍑轰簡鍙互鍦ㄨ繍琛屾椂璁剧疆鐨勫彉閲忋

濡傛灉浣犳兂鐢SET璇彞闄愬埗绯荤粺鍙橀噺鍙鐨勬渶澶у硷紝鍙互鍦ㄦ湇鍔″櫒鍚姩鏃堕氳繃--maximum-var_name褰㈠紡鐨勯夐」鏉ユ寚瀹氥備緥濡傦紝瑕佹兂闃叉query_cache_size鐨勫艰繍琛屾椂瓒呰繃32MB锛屼娇鐢ㄩ夐」--maximum-query_cache_size=32M

浣犲彲浠ラ氳繃SHOW VARIABLES璇彞鏌ョ湅绯荤粺鍙橀噺鍙婂叾鍊笺傝缁嗕俊鎭弬瑙9.4鑺傦紝鈥滅郴缁熷彉閲忊

mysql> SHOW VARIABLES;
+---------------------------------+-------------------------------------------+
| Variable_name                   | Value                                     |
+---------------------------------+-------------------------------------------+
| auto_increment_increment        | 1                                         |
| auto_increment_offset           | 1                                         |
| automatic_sp_privileges         | ON                                        |
| back_log                        | 50                                        |
| basedir                         | /home/jon/bin/mysql/                      |
| binlog_cache_size               | 32768                                     |
| bulk_insert_buffer_size         | 8388608                                   |
| character_set_client            | latin1                                    |
| character_set_connection        | latin1                                    |
| character_set_database          | latin1                                    |
| character_set_results           | latin1                                    |
| character_set_server            | latin1                                    |
| character_set_system            | utf8                                      |
| character_sets_dir              | /home/jon/bin/mysql/share/mysql/charsets/ |
| collation_connection            | latin1_swedish_ci                         |
| collation_database              | latin1_swedish_ci                         |
| collation_server                | latin1_swedish_ci                         |
| completion_type                 | 0                                         |
| concurrent_insert               | 1                                         |
| connect_timeout                 | 5                                         |
| datadir                         | /home/jon/bin/mysql/var/                  |
| date_format                     | %Y-%m-%d                                  |
| datetime_format                 | %Y-%m-%d %H:%i:%s                         |
| default_week_format             | 0                                         |
| delay_key_write                 | ON                                        |
| delayed_insert_limit            | 100                                       |
| delayed_insert_timeout          | 300                                       |
| delayed_queue_size              | 1000                                      |
| div_precision_increment         | 4                                         |
| engine_condition_pushdown       | OFF                                       |
| expire_logs_days                | 0                                         |
| flush                           | OFF                                       |
| flush_time                      | 0                                         |
| ft_boolean_syntax               | + -><()~*:""&|                            |
| ft_max_word_len                 | 84                                        |
| ft_min_word_len                 | 4                                         |
| ft_query_expansion_limit        | 20                                        |
| ft_stopword_file                | (built-in)                                |
| group_concat_max_len            | 1024                                      |
| have_archive                    | YES                                       |
| have_bdb                        | NO                                        |
| have_blackhole_engine           | YES                                       |
| have_compress                   | YES                                       |
| have_crypt                      | YES                                       |
| have_csv                        | YES                                       |
| have_example_engine             | NO                                        |
| have_federated_engine           | NO                                        |
| have_geometry                   | YES                                       |
| have_innodb                     | YES                                       |
| have_isam                       | NO                                        |
| have_ndbcluster                 | DISABLED                                  |
| have_openssl                    | NO                                        |
| have_partition_engine           | YES                                       |
| have_query_cache                | YES                                       |
| have_raid                       | NO                                        |
| have_rtree_keys                 | YES                                       |
| have_symlink                    | YES                                       |
| init_connect                    |                                           |
| init_file                       |                                           |
| init_slave                      |                                           |
| innodb_additional_mem_pool_size | 1048576                                   |
| innodb_autoextend_increment     | 8                                         |
| innodb_buffer_pool_awe_mem_mb   | 0                                         |
| innodb_buffer_pool_size         | 8388608                                   |
| innodb_checksums                | ON                                        |
| innodb_commit_concurrency       | 0                                         |
| innodb_concurrency_tickets      | 500                                       |
| innodb_data_file_path           | ibdata1:10M:autoextend                    |
| innodb_data_home_dir            |                                           |
| innodb_doublewrite              | ON                                        |
| innodb_fast_shutdown            | 1                                         |
| innodb_file_io_threads          | 4                                         |
| innodb_file_per_table           | OFF                                       |
| innodb_flush_log_at_trx_commit  | 1                                         |
| innodb_flush_method             |                                           |
| innodb_force_recovery           | 0                                         |
| innodb_lock_wait_timeout        | 50                                        |
| innodb_locks_unsafe_for_binlog  | OFF                                       |
| innodb_log_arch_dir             |                                           |
| innodb_log_archive              | OFF                                       |
| innodb_log_buffer_size          | 1048576                                   |
| innodb_log_file_size            | 5242880                                   |
| innodb_log_files_in_group       | 2                                         |
| innodb_log_group_home_dir       | ./                                        |
| innodb_max_dirty_pages_pct      | 90                                        |
| innodb_max_purge_lag            | 0                                         |
| innodb_mirrored_log_groups      | 1                                         |
| innodb_open_files               | 300                                       |
| innodb_support_xa               | ON                                        |
| innodb_sync_spin_loops          | 20                                        |
| innodb_table_locks              | ON                                        |
| innodb_thread_concurrency       | 20                                        |
| innodb_thread_sleep_delay       | 10000                                     |
| interactive_timeout             | 28800                                     |
| join_buffer_size                | 131072                                    |
| key_buffer_size                 | 8388600                                   |
| key_cache_age_threshold         | 300                                       |
| key_cache_block_size            | 1024                                      |
| key_cache_division_limit        | 100                                       |
| language                        | /home/jon/bin/mysql/share/mysql/english/  |
| large_files_support             | ON                                        |
| large_page_size                 | 0                                         |
| large_pages                     | OFF                                       |
| license                         | GPL                                       |
| local_infile                    | ON                                        |
| locked_in_memory                | OFF                                       |
| log                             | ON                                        |
| log_bin                         | ON                                        |
| log_bin_trust_routine_creators  | OFF                                       |
| log_error                       | /home/jon/bin/mysql/var/master1.err       |
| log_slave_updates               | OFF                                       |
| log_slow_queries                | OFF                                       |
| log_warnings                    | 1                                         |
| long_query_time                 | 10                                        |
| low_priority_updates            | OFF                                       |
| lower_case_file_system          | OFF                                       |
| lower_case_table_names          | 0                                         |
| max_allowed_packet              | 1048576                                   |
| max_binlog_cache_size           | 4294967295                                |
| max_binlog_size                 | 1073741824                                |
| max_connect_errors              | 10                                        |
| max_connections                 | 100                                       |
| max_delayed_threads             | 20                                        |
| max_error_count                 | 64                                        |
| max_heap_table_size             | 16777216                                  |
| max_insert_delayed_threads      | 20                                        |
| max_join_size                   | 4294967295                                |
| max_length_for_sort_data        | 1024                                      |
| max_relay_log_size              | 0                                         |
| max_seeks_for_key               | 4294967295                                |
| max_sort_length                 | 1024                                      |
| max_tmp_tables                  | 32                                        |
| max_user_connections            | 0                                         |
| max_write_lock_count            | 4294967295                                |
| multi_range_count               | 256                                       |
| myisam_data_pointer_size        | 6                                         |
| myisam_max_sort_file_size       | 2147483647                                |
| myisam_recover_options          | OFF                                       |
| myisam_repair_threads           | 1                                         |
| myisam_sort_buffer_size         | 8388608                                   |
| ndb_autoincrement_prefetch_sz   | 32                                        |
| ndb_cache_check_time            | 0                                         |
| ndb_force_send                  | ON                                        |
| ndb_index_stat_cache_entries    | 32                                        |
| ndb_index_stat_enable           | ON                                        |
| ndb_index_stat_update_freq      | 20                                        |
| ndb_use_exact_count             | ON                                        |
| ndb_use_transactions            | ON                                        |
| net_buffer_length               | 16384                                     |
| net_read_timeout                | 30                                        |
| net_retry_count                 | 10                                        |
| net_write_timeout               | 60                                        |
| new                             | OFF                                       |
| old_alter_table                 | OFF                                       |
| old_passwords                   | OFF                                       |
| open_files_limit                | 1024                                      |
| optimizer_prune_level           | 1                                         |
| optimizer_search_depth          | 62                                        |
| pid_file                        | /home/jon/bin/mysql/var/hostname.pid1     |
| port                            | 3306                                      |
| preload_buffer_size             | 32768                                     |
| protocol_version                | 10                                        |
| query_alloc_block_size          | 8192                                      |
| query_cache_limit               | 1048576                                   |
| query_cache_min_res_unit        | 4096                                      |
| query_cache_size                | 0                                         |
| query_cache_type                | ON                                        |
| query_cache_wlock_invalidate    | OFF                                       |
| query_prealloc_size             | 8192                                      |
| range_alloc_block_size          | 2048                                      |
| read_buffer_size                | 131072                                    |
| read_only                       | OFF                                       |
| read_rnd_buffer_size            | 262144                                    |
| relay_log_purge                 | ON                                        |
| relay_log_space_limit           | 0                                         |
| rpl_recovery_rank               | 0                                         |
| secure_auth                     | OFF                                       |
| server_id                       | 1                                         |
| skip_external_locking           | ON                                        |
| skip_networking                 | OFF                                       |
| skip_show_database              | OFF                                       |
| slave_compressed_protocol       | OFF                                       |
| slave_load_tmpdir               | /tmp/                                     |
| slave_net_timeout               | 3600                                      |
| slave_skip_errors               | OFF                                       |
| slave_transaction_retries       | 10                                        |
| slow_launch_time                | 2                                         |
| socket                          | /tmp/mysql.sock                           |
| sort_buffer_size                | 2097144                                   |
| sql_mode                        |                                           |
| sql_notes                       | ON                                        |
| sql_warnings                    | ON                                        |
| storage_engine                  | MyISAM                                    |
| sync_binlog                     | 0                                         |
| sync_frm                        | ON                                        |
| sync_replication                | 0                                         |
| sync_replication_slave_id       | 0                                         |
| sync_replication_timeout        | 10                                        |
| system_time_zone                | EST                                       |
| table_cache                     | 64                                        |
| table_lock_wait_timeout         | 50                                        |
| table_type                      | MyISAM                                    |
| thread_cache_size               | 0                                         |
| thread_stack                    | 196608                                    |
| time_format                     | %H:%i:%s                                  |
| time_zone                       | SYSTEM                                    |
| timed_mutexes                   | OFF                                       |
| tmp_table_size                  | 33554432                                  |
| tmpdir                          |                                           |
| transaction_alloc_block_size    | 8192                                      |
| transaction_prealloc_size       | 4096                                      |
| tx_isolation                    | REPEATABLE-READ                           |
| updatable_views_with_limit      | YES                                       |
| version                         | 5.1.2-alpha-log                           |
| version_comment                 | Source distribution                       |
| version_compile_machine         | i686                                      |
| version_compile_os              | suse-linux                                |
| wait_timeout                    | 28800                                     |
+---------------------------------+-------------------------------------------+
218 rows in set (0.03 sec)

姝ゅ鎻忚堪浜嗗ぇ澶氭暟绯荤粺鍙橀噺銆傛病鏈夌増鏈殑鍙橀噺鍦ㄦ墍鏈MySQL 5.1 鍙戝竷涓傜敤銆傚叧浜庡叾浣跨敤鍘嗗彶淇℃伅锛岃鍙傝MySQL 5.0鍙傝冩寚鍗MySQL 4.1鍙傝冩寚鍗InnoDB绯荤粺鍙橀噺鍒椾簬 15.2.4鑺傦紝鈥淚nnoDB鍚姩閫夐」鈥

鑻ユ病鏈夊彟琛岃瀹氾紝缂撳啿鍖哄ぇ灏忋侀暱搴﹀拰鍫嗘爤澶у皬鐨勫崟浣嶅潎涓哄瓧鑺傘

鍏充簬杩欎簺鍙橀噺鐨勮皟鑺備俊鎭弬瑙7.5.2鑺傦紝鈥滆皟鑺傛湇鍔″櫒鍙傛暟鈥

         auto_increment_increment

auto_increment_incrementauto_increment_offset鐢ㄤ簬涓绘湇鍔″櫒锛嶄富鏈嶅姟鍣紙master-to-master锛夊鍒讹紝骞跺彲浠ョ敤鏉ユ帶鍒AUTO_INCREMENT鍒楃殑鎿嶄綔銆備袱涓彉閲忓潎鍙互璁剧疆涓哄叏灞鎴栧眬閮ㄥ彉閲忥紝骞朵笖鍋囧畾姣忎釜鍊奸兘鍙互涓165,535涔嬮棿鐨勬暣鏁板笺傚皢鍏朵腑涓涓彉閲忚缃负0浼氫娇璇ュ彉閲忎负1銆傚鏋滆瘯鍥惧皢杩欎簺鍙橀噺璁剧疆涓哄ぇ浜65,535鎴栧皬浜0鐨勫硷紝鍒欎細灏嗚鍊艰缃负65,535銆傚鏋滃悜灏auto_increment_incrementauto_increment_offset璁剧疆涓洪潪鏁存暟鍊硷紝鍒欎細缁欏嚭閿欒锛屽苟涓斿彉閲忕殑瀹為檯鍊煎湪杩欑鎯呭喌涓嬩繚鎸佷笉鍙樸

杩欎袱涓彉閲忓奖鍝AUTO_INCREMENT鍒楃殑鏂瑰紡锛

o        auto_increment_increment鎺у埗鍒椾腑鐨勫肩殑澧為噺鍊笺備緥濡:

o                       mysql> SHOW VARIABLES LIKE 'auto_inc%';
o                       +--------------------------+-------+
o                       | Variable_name            | Value |
o                       +--------------------------+-------+
o                       | auto_increment_increment | 1     |
o                       | auto_increment_offset    | 1     |
o                       +--------------------------+-------+
o                       2 rows in set (0.00 sec)
o                      
o                       mysql> CREATE TABLE autoinc1 (col INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
o                       Query OK, 0 rows affected (0.04 sec)
o                      
o                       mysql> SET @auto_increment_increment=10;
o                       Query OK, 0 rows affected (0.00 sec)
o                      
o                       mysql> SHOW VARIABLES LIKE 'auto_inc%';
o                       +--------------------------+-------+
o                       | Variable_name            | Value |
o                       +--------------------------+-------+
o                       | auto_increment_increment | 10    |
o                       | auto_increment_offset    | 1     |
o                       +--------------------------+-------+
o                       2 rows in set (0.01 sec)
o                      
o                       mysql> INSERT INTO autoinc1 VALUES (NULL), (NULL), (NULL), (NULL);
o                       Query OK, 4 rows affected (0.00 sec)
o                       Records: 4  Duplicates: 0  Warnings: 0
o                      
o                       mysql> SELECT col FROM autoinc1;
o                       +-----+
o                       | col |
o                       +-----+
o                       |   1 |
o                       |  11 |
o                       |  21 |
o                       |  31 |
o                       +-----+
o                       4 rows in set (0.00 sec)

(娉ㄦ槑濡備綍浣跨敤SHOW VARIABLES鏉ヨ幏鍙栬繖浜涘彉閲忕殑褰撳墠鍊硷級

o        auto_increment_offset纭畾AUTO_INCREMENT鍒楀肩殑璧风偣銆傚亣瀹氬湪涓庡墠闈㈢殑渚嬪瓙鐨勭浉鍚岀殑浼氳瘽涓墽琛屼笅闈㈢殑鍛戒护锛

o                       mysql> SET @auto_increment_offset=5;
o                       Query OK, 0 rows affected (0.00 sec)
o                      
o                       mysql> SHOW VARIABLES LIKE 'auto_inc%';
o                       +--------------------------+-------+
o                       | Variable_name            | Value |
o                       +--------------------------+-------+
o                       | auto_increment_increment | 10    |
o                       | auto_increment_offset    | 5     |
o                       +--------------------------+-------+
o                       2 rows in set (0.00 sec)
o                      
o                       mysql> CREATE TABLE autoinc2 (col INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
o                       Query OK, 0 rows affected (0.06 sec)
o                      
o                       mysql> INSERT INTO autoinc2 VALUES (NULL), (NULL), (NULL), (NULL);
o                       Query OK, 4 rows affected (0.00 sec)
o                       Records: 4  Duplicates: 0  Warnings: 0
o                      
o                       mysql> SELECT col FROM autoinc2;
o                       +-----+
o                       | col |
o                       +-----+
o                       |   5 |
o                       |  15 |
o                       |  25 |
o                       |  35 |
o                       +-----+
o                       4 rows in set (0.02 sec)
o                      

濡傛灉auto_increment_offset鐨勫煎ぇ浜auto_increment_increment鐨勫硷紝鍒auto_increment_offset鐨勫艰蹇界暐銆

濡傛灉鍏朵腑涓涓垨涓や釜鍙橀噺琚洿鏀逛簡锛岀劧鍚庢洿鏀规彃鍏ュ埌鍖呭惈AUTO_INCREMENT鍒楃殑琛ㄤ腑鐨勬柊琛岋紝缁撴灉鍙兘鐪嬩笂鍘绘湁闂锛岀敱浜庤绠AUTO_INCREMENT绯诲垪鍊兼椂娌℃湁鑰冭檻鍒楀唴宸茬粡瀛樺湪鐨勫硷紝骞朵笖鎻掑叆鐨勪笅涓涓兼槸鍒楀唴鏈灏忕殑鍊硷紝澶т簬AUTO_INCREMENT鍒楀唴宸叉湁鐨勬渶澶у笺傛崲鍙ヨ瘽璇达紝鏁板肩殑璁$畻鏂规硶涓猴細

auto_increment_offset+ N * auto_increment_increment

鍏朵腑N涓虹郴鍒楀唴鐨勬鏁存暟鍊[1,2,3,...]銆備緥濡傦細

mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 10    |
| auto_increment_offset    | 5     |
+--------------------------+-------+
2 rows in set (0.00 sec)
 
mysql> SELECT col FROM autoinc1;
+-----+
| col |
+-----+
|   1 |
|  11 |
|  21 |
|  31 |
+-----+
4 rows in set (0.00 sec)
 
mysql> INSERT INTO autoinc1 VALUES (NULL), (NULL), (NULL), (NULL);
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0
 
mysql> SELECT col FROM autoinc1;
+-----+
| col |
+-----+
|   1 |
|  11 |
|  21 |
|  31 |
|  35 |
|  45 |
|  55 |
|  65 |
+-----+
8 rows in set (0.00 sec)

auto_increment_incrementauto_increment_offset鎵绀虹殑鍊煎彲浠ョ敓鎴愮郴鍒5 + N * 10,鍗筹紝[5,15,25,35,45,...]銆傚湪INSERTcol 鍒楀唴鏈澶х殑鍊间负31,AUTO_INCREMENT鏁板垪鐨勪笅涓涓间负35,鍥犳col涓彃鍏ョ殑鍊间粠璇ョ偣寮濮嬶紝缁撴灉濡SELECT鏌ヨ鎵绀恒

涓瀹氳璁颁綇涓嶅彲鑳藉皢杩欎袱涓彉閲忕殑缁撴灉闄愬埗鍒颁竴涓〃涓紝鍥犳涓嶄細鏇夸唬鍏跺畠鏁版嵁搴撶鐞嗙郴缁熸彁渚涚殑搴忓垪锛涜繖浜涘彉閲忔帶鍒MySQL鏈嶅姟鍣ㄤ笂allAUTO_INCREMENT鍒楃殑鎵鏈夎涓恒傚鏋滄煇涓彉閲忚涓哄叏灞鍙橀噺锛屽垯鍙湁閫氳繃灞閮ㄨ缃皢鍏ㄥ眬鍊兼洿鏀瑰拰瑕嗙洊鍚庢垨mysqld閲嶅惎鍚庡叾浣滅敤鏂瑰彲鏀瑰彉锛涘鏋滃眬閮ㄨ缃紝鍒欐柊鍊煎奖鍝嶆墍鏈夎〃鐨AUTO_INCREMENT鍒楋紝鍦ㄨ繖涓細璇濇湡闂村綋鍓嶇敤鎴峰湪杩欎簺琛ㄤ腑鎻掑叆浜嗘柊琛岋紝闄ら潪鍦ㄤ細璇濇湡闂存洿鏀逛簡杩欎簺鍊笺

auto_increment_increment鐨 榛樿鍊间负1銆傚弬瑙6.12鑺傦紝鈥滃鏈嶅姟鍣ㄥ鍒朵腑鐨凙uto-Increment鈥

         auto_increment_offset

璇ュ彉閲忕殑榛樿鍊间负1銆傝瑙auto_increment_increment鐨勬弿杩般

         back_log

MySQL鏈夌殑涓昏杩炴帴璇锋眰鐨勬暟閲忋傚綋涓MySQL绾跨▼鍦ㄧ煭鏃堕棿鍐呭緱鍒拌澶氳繛鎺ヨ姹傛椂鍙戞尌浣滅敤銆備富绾跨▼闇瑕佽姳涓浜涙椂闂(灏界寰堝皯)鏉ユ鏌ヨ繛鎺ュ苟鍚姩涓涓柊绾跨▼銆back_log鍊艰鏄MySQL涓存椂鍋滄鍝嶅簲鏂拌姹傚墠鍦ㄧ煭鏃堕棿鍐呭彲浠ュ爢璧峰灏戣姹傘傚鏋滀綘闇瑕佸湪鐭椂闂村唴鍏佽澶ч噺杩炴帴锛屽彲浠ュ鍔犺鏁板笺

鎹㈠彞璇濊锛岃鍊间负鈥滆繘鈥TCP/IP杩炴帴甯у惉闃熷垪鐨勫ぇ灏忋傛搷浣滅郴缁熸湁璇ラ槦鍒楄嚜宸辩殑闄愬埗鍊笺傛湰鎵嬪唽涓Unix listen()绯荤粺璋冪敤椤靛簲鏈夋洿璇︾粏鐨勪俊鎭傝鍙橀噺鏈澶у艰鏌ラ槄OS鏂囨。銆備紒鍥惧皢back_log璁剧疆涓洪珮浜庝綘鐨勬搷浣滅郴缁熼檺鍊兼槸寰掑姵鏃犵泭鐨勩

         basedir

MySQL瀹夎鍩哄噯鐩綍銆傚彲浠ョ敤--basedir閫夐」璁剧疆璇ュ彉閲忋

         bdb_cache_size

BDB琛ㄧ紦瀛樼储寮曞拰琛屽垎閰嶇殑缂撳啿鍖虹殑澶у皬銆傚鏋滀綘涓嶄娇鐢BDB琛紝浣犲簲鐢--skip-bdb鍚姩mysqld浠ヤ究涓嶆氮璐硅缂撳瓨銆

         bdb_home

BDB琛ㄥ熀鍑嗙洰褰曘傚簲涓datadir鍙橀噺鐨勫肩浉鍚屻

         bdb_log_buffer_size

BDB琛ㄧ紦瀛樼储寮曞拰琛屽垎閰嶇殑缂撳啿鍖虹殑澶у皬銆傚鏋滀綘涓嶄娇鐢BDB琛紝浣犲簲灏嗚鍊艰缃负0鎴栫敤--skip-bdb鍚姩mysqld浠ヤ究涓嶆氮璐硅缂撳瓨銆

         bdb_logdir

BDB瀛樺偍寮曟搸鍐欏畠鏃ュ織鏂囦欢鐨勭洰褰曘傚彲浠ョ敤--bdb-logdir閫夐」璁剧疆璇ュ彉閲忋

         bdb_max_lock

BDB琛ㄤ笅鍙互婵娲荤殑鏈澶ч攣鏁(榛樿涓10,000)銆傚鏋滃綋浣犳墽琛岄暱浜嬪姟鎴栧綋mysqld蹇呴』妫鏌ヨ澶氳鏉ヨ绠楁煡璇㈡椂鍑虹幇涓嬮潰鐨勯敊璇紝浣犲簲澧炲姞璇ュ硷細

bdb: Lock table is out of available locks
Got error 12 from ...

         bdb_shared_data

濡傛灉浣犳浣跨敤--bdb-shared-data搴斾负ON

         bdb_tmpdir

--bdb-tmpdir閫夐」鐨勫笺

 

         binlog_cache_size

鍦ㄤ簨鍔¤繃绋嬩腑瀹圭撼浜岃繘鍒舵棩蹇SQL璇彞鐨勭紦瀛樺ぇ灏忋備簩杩涘埗鏃ュ織缂撳瓨鏄湇鍔″櫒鏀寔浜嬪姟瀛樺偍寮曟搸骞朵笖鏈嶅姟鍣ㄥ惎鐢ㄤ簡浜岃繘鍒舵棩蹇(--log-bin閫夐」)鐨勫墠鎻愪笅涓烘瘡涓鎴风鍒嗛厤鐨勫唴瀛樸傚鏋滀綘缁忓父浣跨敤澶х殑锛屽璇彞浜嬪姟锛屼綘鍙互澧炲姞璇ュ间互鑾峰緱鏇存湁鐨勬ц兘銆Binlog_cache_useBinlog_cache_disk_use鐘舵佸彉閲忓彲浠ョ敤鏉ヨ皟鏁磋鍙橀噺鐨勫ぇ灏忋傚弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥

         bulk_insert_buffer_size

MyISAM 浣跨敤涓撶敤鏍戠姸缂撳瓨鏉ヤ娇INSERT ... SELECTINSERT ... VALUES (...)(...) ...LOAD DATA INFILE鐨勫ぇ鍧楁彃鍏ユ洿蹇傝鍙橀噺鐢ㄦ瘡绾跨▼鐨勫瓧鑺傛暟闄愬埗缂撳瓨鏍戠殑澶у皬銆傚皢瀹冭缃负0绂佺敤浼樺寲銆閲婏細鍙湁鍚戦潪绌鸿〃娣诲姞鏁版嵁鏃舵墠浣跨敤璇ョ紦瀛樸 榛樿鍊兼槸8MB

         character_set_client

鏉ヨ嚜瀹㈡埛绔殑璇彞鐨勫瓧绗﹂泦銆

         character_set_connection

鐢ㄤ簬娌℃湁瀛楃闆嗗鍏ョ鐨勬枃瀛楀拰鏁板瓧锛嶅瓧绗︿覆杞崲銆

         character_set_database

榛樿鏁版嵁搴撲娇鐢ㄧ殑瀛楃闆嗐傚綋榛樿鏁版嵁搴撴洿鏀规椂锛屾湇鍔″櫒鍒欒缃鍙橀噺銆傚鏋滄病鏈夐粯璁ゆ暟鎹簱锛屽彉閲忕殑鍊煎悓character_set_server

         character_set_results

鐢ㄤ簬鍚戝鎴风杩斿洖鏌ヨ缁撴灉鐨勫瓧绗﹂泦銆

         character_set_ server

鏈嶅姟鍣ㄧ殑榛樿瀛楃闆嗐

         character_set_system

鏈嶅姟鍣ㄧ敤鏉ヤ繚瀛樿瘑鍒鐨勫瓧绗﹂泦銆傝鍊间竴瀹氭槸utf8

         character_sets_dir

瀛楃闆嗗畨瑁呯洰褰曘

         collation_connection

杩炴帴瀛楃闆嗙殑鏍″瑙勫垯銆

         collation_database

榛樿鏁版嵁搴撲娇鐢ㄧ殑鏍″瑙勫垯銆傚綋榛樿鏁版嵁搴撴敼鍙樻椂鏈嶅姟鍣ㄥ垯璁剧疆璇ュ彉閲忋傚鏋滄病鏈夐粯璁ゆ暟鎹簱锛屽彉閲忕殑鍊煎悓collation_server

         collation_server

鏈嶅姟鍣ㄧ殑榛樿鏍″瑙勫垯銆

         completion_type

浜嬪姟缁撴潫绫诲瀷锛

o        濡傛灉璇ュ间负0(榛樿)COMMITROLLBACK涓嶅彈褰卞搷銆

o        濡傛灉璇ュ间负1COMMITROLLBACK鍒嗗埆绛夊悓浜COMMIT AND CHAINROLLBACK AND CHAIN(鏂颁簨鍔$敤鍒氬垰缁撴潫鐨勪簨鍔$浉鍚岀殑闂撮殧绛夌骇绔嬪嵆鍚姩锛

o        濡傛灉璇ュ间负2COMMITROLLBACK鍒嗗埆绛夊悓浜COMMRELEASEROLLBACK RELEASE(浜嬪姟缁堟鍚庯紝鏈嶅姟鍣ㄦ柇寮锛

         concurrent_insert

濡傛灉涓ON(榛樿鍊)MySQL鍏佽INSERTSELECT璇彞鍦ㄤ腑闂存病鏈夌┖鏁版嵁鍧楃殑MyISAM琛ㄤ腑骞惰杩愯銆備綘鍙互鐢--safe--skip-new鍚姩mysqld鍏抽棴璇ラ夐」銆

璇ュ彉閲忎负鏁存暟锛屾湁3涓硷細

鎻忚堪

0

1

(榛樿)鍦ㄦ病鏈夌┖鏁版嵁鍧楃殑MyISAM琛ㄤ腑鍚敤骞惰鎻掑叆

2

涓烘墍鏈MyISAM琛ㄥ惎鐢ㄥ苟琛屾彃鍏ャ傚鏋滆〃鏈夌┖璁板綍鎴栨琚彟涓绾跨▼浣跨敤锛屾柊琛屽皢鎻掑叆鍒拌〃鐨勬渶鍚庛傚鏋滆〃鏈娇鐢紝MySQL灏嗚繘琛屾櫘閫氳閿佸畾骞跺皢鏂拌鎻掑叆绌鸿褰曘

         connect_timeout

mysqld鏈嶅姟鍣Bad handshake鍝嶅簲鍓嶇瓑寰呰繛鎺ュ寘鐨勭鏁般

         datadir

MySQL鏁版嵁鐩綍銆傚彲浠ョ敤--datadir閫夐」璁剧疆璇ュ彉閲忋

         date_format

璇ュ彉閲忔湭浣跨敤銆

         datetime_format

璇ュ彉閲忔湭浣跨敤銆

         default_week_format

WEEK() 鍑芥暟浣跨敤鐨勯粯璁ゆā寮忋

         delay_key_write

璇ラ夐」鍙傜敤MyISAM琛ㄣ傚畠鍏锋湁涓嬭堪鍊煎彲浠ュ奖鍝CREATE TABLE璇彞浣跨敤鐨DELAY_KEY_WRITE琛ㄩ夐」鐨勫鐞嗐

閫夐」

鎻忚堪

OFF

DELAY_KEY_WRITE琚拷鐣ャ

ON

MySQLCREATE TABLE涓敤DELAY_KEY_WRITE閫夐」銆傝繖鏄 榛樿鍊笺

ALL

鐢ㄥ惎鐢DELAY_KEY_WRITE閫夐」鍒涘缓琛ㄧ殑鐩稿悓鏂规硶瀵规墍鏈夋柊鎵撳紑琛ㄧ殑杩涜澶勭悊銆

濡傛灉鍚敤浜DELAY_KEY_WRITE锛岃鏄庝娇鐢ㄨ椤圭殑琛ㄧ殑閿紦鍐插尯鍦ㄦ瘡娆℃洿鏂扮储寮曟椂涓嶈娓呯┖锛屽彧鏈夊叧闂〃鏃舵墠娓呯┖銆傞伄鎺╃洊鍙互澶уぇ鍔犲揩閿殑鍐欐搷浣滐紝浣嗗鏋滀綘浣跨敤璇ョ壒鎬э紝浣犲簲鐢--myisam-recover閫夐」鍚姩鏈嶅姟鍣紝涓烘墍鏈MyISAM琛ㄦ坊鍔犺嚜鍔ㄦ鏌(渚嬪锛--myisam-recover=BACKUP,FORCE)銆傚弬瑙5.3.1鑺傦紝鈥mysqld鍛戒护琛岄夐」鈥15.1.1鑺傦紝鈥淢yISAM鍚姩閫夐」鈥

璇锋敞鎰--external-locking涓嶄负浣跨敤寤惰繜閿啓鍏ョ殑琛ㄦ彁渚涚储寮曠牬鍧忎繚鎶ゃ

         delayed_insert_limit

鎻掑叆delayed_insert_limit 寤惰繜琛屽悗锛INSERT DELAYED 澶勭悊鍣ㄧ嚎绋嬫鏌ユ槸鍚︽湁鎸傝捣鐨SELECT璇彞銆傚鏋滄湁锛屽湪缁х画鎻掑叆寤惰繜鐨勮涔嬪墠锛屽厑璁稿畠浠厛鎵ц銆

         delayed_insert_timeout

INSERT DELAYED澶勭悊鍣ㄧ嚎绋嬬粓姝㈠墠搴旂瓑寰INSERT璇彞鐨勬椂闂淬

         delayed_queue_size

杩欐槸鍚勪釜琛ㄤ腑澶勭悊INSERT DELAYED璇彞鏃堕槦鍒椾腑琛岀殑鏁伴噺闄愬埗銆傚鏋滈槦鍒楁弧浜嗭紝鎵цINSERT DELAYED璇彞鐨勫鎴风搴旂瓑寰呯洿鍒伴槦鍒楀唴鍐嶆湁绌洪棿銆

         div_precision_increment

璇ュ彉閲忚鏄庣敤/鎿嶄綔绗︽墽琛岄櫎鎿嶄綔鐨勭粨鏋滃彲澧炲姞鐨勭簿纭害鐨勪綅鏁般 榛樿鍊兼槸4銆傛渶灏忓拰鏈澶у煎垎鍒负030銆備笅闈㈢殑绀轰緥璇存槑浜嗗鍔 榛樿鍊肩殑缁撴灉銆

mysql> SELECT 1/7;
+--------+
| 1/7    |
+--------+
| 0.1429 |
+--------+
mysql> SET div_precision_increment = 12;
mysql> SELECT 1/7;
+----------------+
| 1/7            |
+----------------+
| 0.142857142857 |
+----------------+

         engine_condition_pushdown

璇ュ彉閲忛傜敤浜NDB銆傞粯璁ゅ间负0(OFF)锛氬鏋滀綘鎵ц绫讳技鏌ヨSELECT * FROM t WHERE mycol = 42锛屽叾涓mycol涓烘病鏈夌储寮曠殑鍒楋紝褰撴弧浜嗙殑琛ㄦ壂鎻忔瘡涓NDB鑺傜偣鏃讹紝鎵ц璇ユ煡璇€傛瘡涓妭鐐逛娇鐢WHERE鏉′欢灏嗘瘡涓琛屽彂閫佺粰MySQL鏈嶅姟鍣ㄣ傚鏋engine_condition_pushdown琚缃负1(ON)锛岃鏉′欢鈥pushed down鈥濈粰瀛樺偍寮曟搸骞跺彂閫佺粰NDB鑺傜偣銆傛瘡涓妭鐐归兘鎵ц鎵弿锛屽苟鍙悜MySQL鏈嶅姟鍣ㄥ彂閫佸洖鍖归厤鏉′欢鐨勮銆

         expire_logs_days

浜岃繘鍒舵棩蹇楄嚜鍔ㄥ垹闄ょ殑澶╂暟銆傞粯璁ゅ间负0,琛ㄧず鈥滄病鏈鑷姩鍒犻櫎鈥濄傚惎鍔ㄦ椂鍜屼簩杩涘埗鏃ュ織寰幆鏃跺彲鑳藉垹闄ゃ

         flush

濡傛灉鐢--flush閫夐」鍚姩mysqld璇ュ间负ON

         flush_time

濡傛灉璁句负闈為浂鍊硷紝姣忛殧flush_time绉掑垯鍏抽棴鎵鏈夎〃浠ラ噴鏀剧‖鐩樿祫婧愬苟鍚屾鏈竻绌虹殑鏁版嵁銆傛垜浠缓璁彧鍦Windows 9xMe锛屾垨鏈夋渶灏忚祫婧愮殑绯荤粺涓娇鐢ㄨ閫夐」銆

         ft_boolean_syntax

浣跨敤IN BOOLEAN MODE鎵ц鐨勫竷灏斿叏鏂囨悳绱㈡敮鎸佺殑鎿嶄綔绗︾郴鍒椼傚弬瑙12.7.1鑺傦紝鈥滃竷灏斿叏鏂囨悳绱⑩

榛樿鍙橀噺鍊间负 '+ -><()~*:""&|'銆傛洿鏀硅繖浜涘肩殑瑙勫垯鏄細

o        鎿嶄綔绗﹀嚱鏁扮敱鍏跺湪瀛楃涓插唴鐨勪綅缃喅瀹氥

o        鏇挎崲鍊煎繀椤绘槸14涓瓧绗︺

o        姣忎釜瀛楃蹇呴』涓ASCII鐮侀潪鏂囧瓧鏁板瓧瀛楃銆

o        1涓垨绗2涓瓧绗﹀繀椤讳负绌烘牸銆

o        闄ら潪璇彞鍦ㄧ11涓瓧绗﹀拰绗12涓瓧绗﹀寮曠敤浜嗘搷浣滅锛屽惁鍒欎笉鍏佽澶嶅埗銆傝繖涓や釜瀛楃鍙互涓嶇浉鍚岋紝浣嗚繖鏄敮涓鍙兘鐨勪袱涓

o        浣嶇疆101314(榛樿璁剧疆涓衡:鈥欍佲&鈥欏拰鈥|)淇濈暀鐢ㄤ簬灏嗘潵鎵╁睍銆

         ft_max_word_len

FULLTEXT绱㈠紩涓墍鍖呭惈鐨勫瓧鐨勬渶澶ч暱搴︺

閲婏細鏇存敼璇ュ彉閲忓悗蹇呴』閲嶅缓FULLTEXT绱㈠紩銆傚簲浣跨敤REPAIR TABLE tbl_name QUICK

         ft_min_word_len

FULLTEXT绱㈠紩涓墍鍖呭惈鐨勫瓧鐨勬渶灏忛暱搴︺

閲婏細鏇存敼璇ュ彉閲忓悗蹇呴』閲嶅缓FULLTEXT绱㈠紩銆傚簲浣跨敤REPAIR TABLE tbl_name QUICK

         ft_query_expansion_limit

浣跨敤WITH QUERY EXPANSION杩涜鍏ㄦ枃鎼滅储鐨勬渶澶у尮閰嶆暟銆

         ft_stopword_file

鐢ㄤ簬璇诲彇鍏ㄦ枃鎼滅储鐨勫仠姝㈠瓧娓呭崟鐨勬枃浠躲傝鏂囦欢涓殑鎵鏈夊瓧閮戒細鐢ㄥ埌锛涙敞閲婁笉閲嶈銆傞粯璁ゆ儏鍐典笅锛屼娇鐢ㄥ唴宓屽紡鍋滄瀛楁竻鍗(myisam/ft_static.c鏂囦欢涓墍瀹氫箟)銆傚皢璇ュ彉閲忚缃负绌哄瓧绗︿覆('')鍒欑鐢ㄥ仠姝㈠瓧杩囨护銆

閲婏細鏇存敼璇ュ彉閲忔垨鍋滄瀛楁枃浠剁殑鍐呭鍚庡繀椤婚噸寤FULLTEXT绱㈠紩銆傚簲浣跨敤REPAIR TABLE tbl_name QUICK

         group_concat_max_len

鍏佽鐨GROUP_CONCAT()鍑芥暟缁撴灉鐨勬渶澶ч暱搴︺

         have_archive

濡傛灉mysqld鏀寔ARCHIVE琛ㄥ垯涓YES锛屽惁鍒欎负NO

         have_bdb

濡傛灉mysqld鏀寔BDB琛ㄥ垯涓YES銆傚鏋滀娇鐢--skip-bdb鍒欎负DISABLED

         have_blackhole_engine

濡傛灉mysqld鏀寔BLACKHOLE琛ㄥ垯涓YES锛屽惁鍒欎负NO

         have_compress

鏄惁zlib鍘嬬缉搴撻傚悎璇ユ湇鍔″櫒銆傚鏋滀笉閫傚悎锛屼笉鑳戒娇鐢COMPRESS()UNCOMPRESS()鍑芥暟銆

         have_crypt

鏄惁crypt()绯荤粺璋冪敤閫傚悎璇ユ湇鍔″櫒銆傚鏋滀笉閫傚悎锛屼笉鑳戒娇鐢CRYPT()鍑芥暟銆

         have_csv

濡傛灉mysqld鏀寔ARCHIVE琛ㄥ垯涓YES锛屽惁鍒欎负NO

         have_example_engine

濡傛灉mysqld鏀寔EXAMPLE琛ㄥ垯涓YES锛屽惁鍒欎负NO

have_federated_engine

濡傛灉mysqld鏀寔FEDERATED琛ㄥ垯涓YES锛屽惁鍒欎负NO

         have_geometry

鏄惁鏈嶅姟鍣ㄦ敮鎸佺┖闂存暟鎹被鍨嬨

         have_innodb

濡傛灉mysqld鏀寔InnoDB琛ㄥ垯涓YES銆傚鏋滀娇鐢--skip-innodb鍒欎负DISABLED

         have_isam

MySQL 5.1,鍙槸涓轰簡鍚戝悗鍏煎鏄剧ず璇ュ硷紝骞朵笖鎬绘槸NO锛屽洜涓轰笉鍐嶆敮鎸ISAM琛ㄣ

         have_ndbcluster

濡傛灉mysqld鏀寔NDB CLUSTER琛ㄥ垯涓YES銆傚鏋滀娇鐢ㄤ簡--skip-ndbcluster鍒欎负DISABLED

         have_partition_engine

濡傛灉mysqld鏀寔鍒嗗尯鍒欎负YES銆傚湪MySQL 5.1.1涓姞鍏ャ

         have_openssl

濡傛灉mysqld鏀寔瀹㈡埛绔/鏈嶅姟鍣ㄥ崗璁殑SSL(鍔犲瘑)鍒欎负YES

         have_query_cache

濡傛灉mysqld鏀寔鏌ヨ缂撳瓨鍒欎负YES

         have_raid

濡傛灉mysqld鏀寔RAID閫夐」鍒欎负YES

         have_rtree_keys

RTREE绱㈠紩鏄惁鍙敤銆(鐢ㄤ簬MyISAM琛ㄧ殑绌洪棿绱㈠紩锛

         have_symlink

鏄惁鍚敤绗﹀彿閾炬帴鏀寔銆傚湪Unix涓渶瑕佺敤浜庢敮鎸DATA DIRECTORYINDEX DIRECTORY琛ㄩ夐」銆

         init_connect

鏈嶅姟鍣ㄤ负姣忎釜杩炴帴鐨勫鎴风鎵ц鐨勫瓧绗︿覆銆傚瓧绗︿覆鐢变竴涓垨澶氫釜SQL璇彞缁勬垚銆傝鎯虫寚瀹氬涓鍙ワ紝鐢ㄥ垎鍙烽棿闅斿紑銆備緥濡傦紝姣忎釜瀹㈡埛绔紑濮嬫椂榛樿鍚敤autocommit妯″紡銆傛病鏈夊叏灞鏈嶅姟鍣ㄥ彉閲忓彲浠ヨ瀹autocommit榛樿鎯呭喌涓嬪簲绂佺敤锛屼絾鍙互鐢init_connect鏉ヨ幏寰楃浉鍚岀殑鏁堟灉锛

SET GLOBAL init_connect='SET AUTOCOMMIT=0';

杩樺彲浠ュ湪鍛戒护琛屾垨閫夐」鏂囦欢涓缃鍙橀噺銆傝鎯充娇鐢ㄩ夐」鏂囦欢璁剧疆鍙橀噺锛屽簲鍖呮嫭涓嬭堪琛岋細

[mysqld]
init_connect='SET AUTOCOMMIT=0'

璇锋敞鎰init_connect鐨勫唴瀹瑰苟涓嶄负鎷ユ湁SUPER鏉冮檺鐨勭敤鎴锋墽琛岋紱瀹為檯鏄唴瀹硅缃敊璇(鍖呭惈閿欒鏌ヨ锛屼緥濡傝娉曢敊璇)锛岃繖鏍蜂娇鎵鏈夎繛鎺ュけ璐ャ備笉涓SUPER鐢ㄦ埛鎵ц锛屼娇SUPER鐢ㄦ埛鍙互鎵撳紑杩炴帴骞跺浐瀹init_connect

         init_file

鍚姩鏈嶅姟鍣ㄦ椂鐢--init-file閫夐」鎸囧畾鐨勬枃浠跺悕銆傛枃浠朵腑鍖呭惈鏈嶅姟鍣ㄥ惎鍔ㄦ椂瑕佹墽琛岀殑SQL璇彞銆傛瘡涓鍙ュ繀椤诲湪鍚屼竴琛屼腑骞朵笖涓嶈兘鍖呮嫭娉ㄩ噴銆

         init_slave

璇ュ彉閲忕被浼init_connect锛屼絾鏄瘡娆SQL绾跨▼鍚姩鏃朵粠鏈嶅姟鍣ㄥ簲鎵ц璇ュ瓧绗︿覆銆傝瀛楃涓茬殑鏍煎紡涓init_connect鍙橀噺鐩稿悓銆

         innodb_xxx

InnoDB绯荤粺鍙橀噺鍒楀叆15.2.4鑺傦紝鈥淚nnoDB鍚姩閫夐」鈥

         interactive_timeout

鏈嶅姟鍣ㄥ叧闂氦浜掑紡杩炴帴鍓嶇瓑寰呮椿鍔ㄧ殑绉掓暟銆備氦浜掑紡瀹㈡埛绔畾涔変负鍦mysql_real_connect()涓娇鐢CLIENT_INTERACTIVE閫夐」鐨勫鎴风銆傚張瑙wait_timeout

         join_buffer_size

鐢ㄤ簬瀹屽叏鑱旀帴鐨勭紦鍐插尯鐨勫ぇ灏(褰撲笉浣跨敤绱㈠紩鐨勬椂鍊欎娇鐢ㄨ仈鎺ユ搷浣)銆備竴鑸儏鍐佃幏寰楀揩閫熻仈鎺ョ殑鏈濂芥柟娉曟槸娣诲姞绱㈠紩銆傚綋澧炲姞绱㈠紩鏃朵笉鍙兘閫氳繃澧炲姞join_buffer_size鍊兼潵鑾峰緱蹇熷畬鍏ㄨ仈鎺ャ傚皢涓轰袱涓〃涔嬮棿鐨勬瘡涓畬鍏ㄨ仈鎺ュ垎閰嶈仈鎺ョ紦鍐插尯銆傚浜庡涓〃涔嬮棿涓嶄娇鐢ㄧ储寮曠殑澶嶆潅鑱旀帴锛岄渶瑕佸鑱旀帴缂撳啿鍖恒

         key_buffer_size

MyISAM琛ㄧ殑绱㈠紩鍧楀垎閰嶄簡缂撳啿鍖猴紝鐢辨墍鏈夌嚎绋嬪叡浜key_buffer_size鏄储寮曞潡缂撳啿鍖虹殑澶у皬銆傞敭鍊肩紦鍐插尯鍗充负閿肩紦瀛樸

key_buffer_size鐨勬渶澶у厑璁歌瀹氬间负4GB銆傛湁鏁堟渶澶у煎彲浠ユ洿灏忥紝鍙栧喅浜庡彲鐢ㄧ墿鐞RAM鍜屾搷浣滅郴缁熸垨纭欢骞冲彴寮哄姞鐨勬瘡涓繘绋嬬殑RAM闄愬埗銆

澧炲姞璇ュ硷紝杈惧埌浣犲彲浠ユ彁渚涚殑鏇村ソ鐨勭储寮曞鐞(鎵鏈夎鍜屽涓啓鎿嶄綔)銆傞氬父涓轰富瑕佽繍琛MySQL鐨勬満鍣ㄥ唴瀛樼殑25%銆備絾鏄紝濡傛灉浣犲皢璇ュ艰寰楄繃澶(渚嬪锛屽ぇ浜庢诲唴瀛樼殑50%)锛岀郴缁熷皢杞崲涓洪〉骞跺彉寰楁瀬鎱€MySQL渚濊禆鎿嶄綔绯荤粺鏉ユ墽琛屾暟鎹鍙栨椂鐨勬枃浠剁郴缁熺紦瀛橈紝鍥犳浣犲繀椤讳负鏂囦欢绯荤粺缂撳瓨鐣欎竴浜涚┖闂淬

鍚屾椂鍐欏琛屾椂瑕佹兂閫熷害鏇村揩锛屽簲浣跨敤LOCK TABLES銆傚弬瑙13.4.5鑺傦紝鈥淟OCK TABLES鍜孶NLOCK TABLES璇硶鈥

浣犲彲浠ラ氳繃鎵цSHOW STATUS璇彞骞舵鏌Key_read_requestsKey_readsKey_write_requestsKey_writes鐘舵佸彉閲忔潵妫鏌ラ敭鍊肩紦鍐插尯鐨勬ц兘銆傚弬瑙13.5.4鑺傦紝鈥淪HOW璇硶鈥

Key_reads/Key_read_requests姣斾緥涓鑸簲灏忎簬0.01銆傚鏋滀綘浣跨敤鏇存柊鍜屽垹闄わ紝Key_writes/Key_write_requests姣斾緥閫氬父鎺ヨ繎1锛屼絾濡傛灉浣犳洿鏂版椂浼氬悓鏃跺奖鍝嶅埌澶氳鎴栧鏋滀綘姝d娇鐢DELAY_KEY_WRITE琛ㄩ夐」锛屽彲鑳藉皬寰楀銆

key_buffer_size缁撳悎Key_blocks_unused鐘舵佸彉閲忓拰缂撳啿鍖哄潡澶у皬锛屽彲浠ョ‘瀹氫娇鐢ㄧ殑閿肩紦鍐插尯鐨勬瘮渚嬨備粠key_cache_block_size鏈嶅姟鍣ㄥ彉閲忓彲浠ヨ幏寰楃紦鍐插尯鍧楀ぇ灏忋備娇鐢ㄧ殑缂撳啿鍖虹殑姣斾緥涓猴細

1 - ((Key_blocks_unused * key_cache_block_size) / key_buffer_size)

璇ュ间负绾︽暟锛屽洜涓洪敭鍊肩紦鍐插尯鐨勯儴鍒嗙┖闂磋鍒嗛厤鐢ㄤ綔鍐呴儴绠$悊缁撴瀯銆

鍙互鍒涘缓澶氫釜MyISAM閿肩紦瀛樸4GB闄愬埗鍙互閫傚悎姣忎釜缂撳瓨锛岃屼笉鏄竴涓粍銆傚弬瑙7.4.6鑺傦紝鈥淢yISAM閿珮閫熺紦鍐测

         key_cache_age_threshold

璇ュ兼帶鍒跺皢缂撳啿鍖轰粠閿肩紦瀛樼儹瀛愰摼(sub-chain)闄嶇骇鍒版俯瀛愰摼(sub-chain)銆傚鏋滃兼洿浣庯紝鍒欓檷绾ф洿蹇傛渶灏忓间负100銆 榛樿鍊兼槸300銆傚弬瑙7.4.6鑺傦紝鈥淢yISAM閿珮閫熺紦鍐测

         key_cache_block_size

閿肩紦瀛樺唴鍧楃殑瀛楄妭澶у皬銆傞粯璁ゅ兼槸1024銆傚弬瑙7.4.6鑺傦紝鈥淢yISAM閿珮閫熺紦鍐测

         key_cache_division_limit

閿肩紦瀛樼紦鍐插尯閾剧儹瀛愰摼鍜屾俯瀛愰摼鐨勫垝鍒嗙偣銆傝鍊间负缂撳啿鍖洪摼鐢ㄤ簬娓╁瓙閾剧殑鐧惧垎姣斻傚厑璁哥殑鍊肩殑鑼冨洿涓1100銆 榛樿鍊兼槸100銆傚弬瑙7.4.6鑺傦紝鈥淢yISAM閿珮閫熺紦鍐测

         language

閿欒娑堟伅鎵鐢ㄨ瑷銆

          large_file_support

mysqld缂栬瘧鏃舵槸鍚︿娇鐢ㄤ簡澶ф枃浠舵敮鎸侀夐」銆

         large_pages

璇存槑鏄惁鍚敤浜嗗ぇ椤甸潰鏀寔銆

         license

鏈嶅姟鍣ㄧ殑璁稿彲绫诲瀷銆

         local_infile

鏄惁LOCAL鏀寔LOAD DATA INFILE璇彞銆

         locked_in_memory

鏄惁鐢memlockmysqld閿佸湪鍐呭瓨涓

         log

鏄惁鍚敤灏嗘墍鏈夋煡璇㈣褰曞埌甯歌鏌ヨ鏃ュ織涓傚弬瑙5.11.2鑺傦紝鈥滈氱敤鏌ヨ鏃ュ織鈥

         log_bin

鏄惁鍚敤浜岃繘鍒舵棩蹇椼傚弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥

         log_bin_trust_routine_creators

鑻ュ惎鐢ㄤ簡浜岃繘鍒惰褰曪紝鍒欒鍙橀噺閫傜敤銆傚畠鎺у埗鏄惁鍙互淇′换淇濆瓨鐨勭▼搴忕殑浣滆呬笉浼氬垱寤哄悜浜岃繘鍒舵棩蹇楀啓鍏ヤ笉瀹夊叏浜嬩欢鐨勭▼搴忋傚鏋滆缃负0(榛樿鎯呭喌)锛屼笉鍏佽鐢ㄦ埛鍒涘缓鎴栦慨鏀逛繚瀛樼殑绋嬪簭锛岄櫎闈炰粬浠笉浠呮嫢鏈CREATE ROUTINEALTER ROUTINE鏉冮檺杩樻嫢鏈SUPER鏉冮檺銆

璁剧疆涓0杩樺己鍒堕檺鍒讹紝绋嬪簭蹇呴』鐢DETERMINISTIC 鐗瑰緛鎴栫敤READS SQL DATANO SQL鐗瑰緛澹版槑銆傚鏋滃彉閲忚缃负1,MySQL涓嶅淇濆瓨绋嬪簭鐨勫垱寤哄己鍔犻檺鍒躲

鍙傝20.4鑺傦紝鈥滃瓨鍌ㄥ瓙绋嬪簭鍜岃Е鍙戠▼搴忕殑浜岃繘鍒舵棩蹇楀姛鑳解

         log_error

閿欒鏃ュ織鐨勪綅缃

         log_slave_updates

鏄惁浠庢湇鍔″櫒浠庝富鏈嶅姟鍣ㄦ敹鍒扮殑鏇存柊搴旇鍏ヤ粠鏈嶅姟鍣ㄨ嚜宸辩殑浜岃繘鍒舵棩蹇椼傝鎯崇敓鏁堬紝蹇呴』鍚敤浠庢湇鍔″櫒鐨勪簩杩涘埗璁板綍銆傚弬瑙6.8鑺傦紝鈥滃鍒跺惎鍔ㄩ夐」鈥

         log_slow_queries

鏄惁璁板綍鎱㈡煡璇€傜敤long_query_time鍙橀噺鐨勫兼潵纭畾鈥滄參鏌ヨ鈥濄傚弬瑙5.11.4鑺傦紝鈥滄參閫熸煡璇㈡棩蹇椻

         log_warnings

鏄惁浜х敓鍏跺畠璀﹀憡娑堟伅銆傞粯璁ゆ儏鍐典笅鍚敤銆傛斁寮冪殑杩炴帴涓嶈鍏ラ敊璇棩蹇楋紝闄ら潪鍊煎ぇ浜1

         long_query_time

濡傛灉鏌ヨ鏃堕棿瓒呰繃璇ュ硷紝鍒欏鍔Slow_queries鐘舵佸彉閲忋傚鏋滀綘姝d娇鐢--log-slow-queries閫夐」锛屽垯鏌ヨ璁板叆鎱㈡煡璇㈡棩蹇楁枃浠躲傜敤瀹為檯鏃堕棿娴嬮噺璇ュ硷紝鑰屼笉鏄CPU鏃堕棿锛屽洜姝や綆浜庤交璐熻浇绯荤粺闃堝肩殑鏌ヨ鍙兘瓒呰繃閲嶈礋杞界郴缁熺殑闃堝笺傚弬瑙5.11.4鑺傦紝鈥滄參閫熸煡璇㈡棩蹇椻

         low_priority_updates

濡傛灉璁剧疆涓1锛屾墍鏈INSERTUPDATEDELETELOCK TABLE WRITE璇彞灏嗙瓑寰呯洿鍒板彈褰卞搷鐨勮〃娌℃湁鎸傝捣鐨SELECTLOCK TABLE READ銆傝鍙橀噺浠ュ墠鍙仛sql_low_priority_updates

         lower_case_file_system

璇ュ彉閲忚鏄庢槸鍚︽暟鎹洰褰曟墍鍦ㄧ殑鏂囦欢绯荤粺瀵规枃浠跺悕鐨勫ぇ灏忓啓鏁忔劅銆ON璇存槑瀵规枃浠跺悕鐨勫ぇ灏忓啓涓嶆晱鎰燂紝OFF琛ㄧず鏁忔劅銆

           lower_case_table_names

濡傛灉璁剧疆涓1,琛ㄥ悕鐢ㄥ皬鍐欎繚瀛樺埌纭洏涓婏紝骞朵笖琛ㄥ悕姣旇緝鏃朵笉瀵瑰ぇ灏忓啓鏁忔劅銆傚鏋滆缃负2锛屾寜鐓ф寚瀹氱殑淇濆瓨琛ㄥ悕锛屼絾鎸夌収灏忓啓鏉ユ瘮杈冦傝閫夐」杩橀傚悎鏁版嵁搴撳悕鍜岃〃鐨勫埆鍚嶃傚弬瑙9.2.2鑺傦紝鈥滆瘑鍒澶у皬鍐欐晱鎰熸р

濡傛灉浣犳浣跨敤InnoDB琛紝浣犲簲鍦ㄦ墍鏈夊钩鍙颁笂灏嗚鍙橀噺璁剧疆涓1锛屽己鍒跺皢鍚嶅瓧杞崲涓哄皬鍐欍

濡傛灉杩愯MySQL鐨勭郴缁熷鏂囦欢鍚嶇殑澶у皬鍐欎笉鏁忔劅(渚嬪WindowsMac OS X)锛屼綘涓嶅簲灏嗚鍙橀噺璁剧疆涓0銆傚鏋滃惎鍔ㄦ椂娌℃湁璁剧疆璇ュ彉閲忥紝骞朵笖鏁版嵁鐩綍鎵鍦ㄦ枃浠剁郴缁熷鏂囦欢鍚嶇殑澶у皬鍐欎笉鏁忔劅锛MySQL鑷姩灏lower_case_table_names璁剧疆涓2

         max_allowed_packet

鍖呮垨浠讳綍鐢熸垚鐨/涓棿瀛楃涓茬殑鏈澶уぇ灏忋

鍖呮秷鎭紦鍐插尯鍒濆鍖栦负net_buffer_length瀛楄妭锛屼絾闇瑕佹椂鍙互澧為暱鍒max_allowed_packet瀛楄妭銆傝鍊奸粯璁ゅ緢灏忥紝浠ユ崟鑾峰ぇ鐨(鍙兘鏄敊璇殑)鏁版嵁鍖呫

濡傛灉浣犱娇鐢ㄥぇ鐨BLOB 鍒楁垨闀垮瓧绗︿覆锛屼綘蹇呴』澧炲姞璇ュ笺傚簲鍚屼綘鎯宠浣跨敤鐨勬渶澶х殑BLOB涓鏍峰ぇ銆max_allowed_packet鐨勫崗璁檺鍒朵负1GB

         max_binlog_cache_size

濡傛灉澶氳鍙ヤ簨鍔¢渶瑕佹洿澶х殑鍐呭瓨锛屼綘浼氬緱鍒伴敊璇Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage

         max_binlog_size

濡傛灉浜岃繘鍒舵棩蹇楀啓鍏ョ殑鍐呭瓒呭嚭缁欏畾鍊硷紝鏃ュ織灏变細鍙戠敓婊氬姩銆備綘涓嶈兘灏嗚鍙橀噺璁剧疆涓哄ぇ浜1GB鎴栧皬浜4096瀛楄妭銆 榛樿鍊兼槸1GB

璇锋敞鎰忓鏋滀綘姝d娇鐢ㄤ簨鍔★細浜嬪姟浠ヤ竴涓潡鍐欏叆浜岃繘鍒舵棩蹇楋紝鍥犳涓嶄笉鑳借鍑犱釜浜岃繘鍒舵棩蹇楁媶鍒嗐傚洜姝わ紝濡傛灉浣犳湁澶х殑浜嬪姟锛屼簩杩涘埗鏃ュ織鍙兘浼氬ぇ浜max_binlog_size

濡傛灉max_relay_log_size0, max_binlog_size鐨勫间篃閫傜敤浜庝腑缁ф棩蹇

         max_connect_errors

濡傛灉涓柇鐨勪笌涓绘満鐨勮繛鎺ヨ秴杩囪鏁扮洰锛岃涓绘満鍒欓樆濉炲悗闈㈢殑杩炴帴銆備綘鍙互鐢 FLUSH HOSTS璇彞瑙i攣閿佸畾鐨勪富鏈恒

         max_connections

鍏佽鐨勫苟琛屽鎴风杩炴帴鏁扮洰銆傚澶ц鍊煎垯澧炲姞mysqld 闇瑕佺殑鏂囦欢鎻忚堪绗︾殑鏁伴噺銆傚叧浜庢枃浠舵弿杩扮闄愬埗鐨勬敞閲婂弬瑙7.4.9鑺傦紝鈥淢ySQL濡備綍鎵撳紑鍜屽叧闂〃鈥銆傝繕鍙弬瑙A.2.6鑺傦紝鈥滆繛鎺ユ暟杩囧鈥

         max_delayed_threads

涓嶈鍚姩澶т簬璇ユ暟鐩殑绾跨▼鏉ュ鐞INSERT DELAYED璇彞銆傚鏋滄墍鏈INSERT DELAYED绾跨▼宸茬粡鍦ㄤ娇鐢紝浣犳兂鍦ㄦ柊琛ㄤ腑鎻掑叆鏁版嵁锛岃 鎻掑叆鏃跺ソ鍍忔湭鎸囧畾DELAYED灞炴с傚鏋滀綘灏嗚鍊艰缃负0,MySQL涓嶄細鍒涘缓绾跨▼鏉ュ鐞DELAYED琛岋紱鍏剁粨鏋滄槸瀹屽叏绂佺敤浜DELAYED

         max_error_count

淇濆瓨鐢SHOW ERRORSSHOW WARNINGS鏄剧ず鐨勯敊璇佽鍛婂拰娉ㄨВ鐨勬渶澶ф暟鐩

         max_heap_table_size

璇ュ彉閲忚缃MEMORY (HEAP)琛ㄥ彲浠ュ闀垮埌鐨勬渶澶х┖闂村ぇ灏忋傝鍙橀噺鐢ㄦ潵璁$畻MEMORY琛ㄧ殑MAX_ROWS鍊笺傚湪宸叉湁鐨MEMORY琛ㄤ笂璁剧疆璇ュ彉閲忔病鏈夋晥鏋滐紝闄ら潪鐢CREATE TABLETRUNCATE TABLE绛夎鍙ラ噸鏂板垱寤鸿〃銆

         max_insert_delayed_threads

璇ュ彉閲忎负max_delayed_threads鐨勫悓涔夎瘝銆

         max_join_size

涓嶅厑璁稿彲鑳介渶瑕佹鏌ュ浜max_join_size(涓哄崟涓〃璇彞)鎴栬缁勫悎(涓哄涓〃璇彞)鎴栧彲鑳芥墽琛屽ぇ浜max_join_size娆$‖鐩樻煡璇㈢殑SELECT璇彞銆傞氳繃璁剧疆璇ュ硷紝浣犲彲浠ユ崟鑾烽敭浣跨敤涓嶆纭苟鍙兘鑺卞緢闀挎椂闂寸殑SELECT璇彞銆傚鏋滅敤鎴锋兂瑕佹墽琛屾病鏈WHERE瀛愬彞鐨勮姳杈冮暱鏃堕棿鎴栬繑鍥炴暟鐧句竾琛岀殑鑱旀帴锛屽垯璁剧疆瀹冦

灏嗚鍙橀噺璁剧疆涓DEFAULT涔嬪鐨勫硷紝灏SQL_BIG_SELECTS鐨勫奸噸璁句负0濡傛灉浣犻噸鏂拌缃SQL_BIG_SELECTS鍊硷紝max_join_size鍙橀噺琚拷鐣ャ

濡傛灉鏌ヨ缁撴灉浣嶄簬鏌ヨ缂撳瓨涓紝鍒欎笉妫鏌ョ粨鏋滃ぇ灏忥紝鍥犱负鍓嶉潰宸茬粡璁$畻浜嗙粨鏋滐紝涓嶄細瑕佹眰鏈嶅姟鍣ㄥ皢瀹冨彂閫佺粰瀹㈡埛绔

璇ュ彉閲忎互鍓嶅彨鍋sql_max_join_size

         max_length_for_sort_data

纭畾浣跨敤鐨filesort绠楁硶鐨勭储寮曞煎ぇ灏忕殑闄愬笺傚弬瑙7.2.12鑺傦紝鈥淢ySQL濡備綍浼樺寲ORDER BY

         max_relay_log_size

濡傛灉澶嶅埗浠庢湇鍔″櫒鍐欏叆涓户鏃ュ織鏃惰秴鍑虹粰瀹氬硷紝鍒欐粴鍔ㄤ腑缁ф棩蹇椼傞氳繃璇ュ彉閲忎綘鍙互瀵逛腑缁ф棩蹇楀拰浜岃繘鍒舵棩蹇楄缃笉鍚岀殑闄愬埗銆備絾鏄紝灏嗚鍙橀噺璁剧疆涓0MySQL鍙互瀵逛簩杩涘埗鏃ュ織鍜屼腑缁ф棩蹇椾娇鐢max_binlog_sizemax_relay_log_size蹇呴』璁剧疆鍦4096瀛楄妭鍜1GB(鍖呮嫭)涔嬮棿锛屾垨涓0銆 榛樿鍊兼槸0銆傚弬瑙6.3鑺傦紝鈥滃鍒跺疄鏂界粏鑺傗

         max_seeks_for_key

闄愬埗鏍规嵁閿煎鎵捐鏃剁殑鏈澶ф悳绱㈡暟銆MySQL浼樺寲鍣ㄥ亣瀹氬綋鐢ㄦ壂鎻忛敭鍦ㄨ〃鍐呮悳绱㈠尮閰嶇殑琛屾椂锛屼笉闇瑕佽秴杩囪鏁伴噺鐨勯敭鍊兼悳绱紝鑰屼笉绠¢敭鐨勫疄闄呭熀鏁版槸浠涔(鍙傝13.5.4.11鑺傦紝鈥淪HOW INDEX璇硶鈥)銆傚皢璇ュ艰缃负杈冧綆鐨勫(100?)锛屼綘鍙互寮哄埗MySQL閫夋嫨閿艰屼笉閫夋嫨琛ㄦ壂鎻忋

         max_sort_length

褰撴帓搴BLOBTEXT鍊兼椂浣跨敤鐨勫瓧鑺傛暟銆傚彧浣跨敤姣忎釜鍊肩殑鍓max_sort_length瀛楄妭锛涘叾瀹冪殑琚拷鐣ャ

         max_tmp_tables

瀹㈡埛绔彲浠ュ悓鏃舵墦寮鐨勪复鏃惰〃鐨勬渶澶ф暟銆(浣嗚閫夐」杩樻湭鐢熸晥锛

         max_user_connections

浠讳綍缁欏畾鐨MySQL璐︽埛鍏佽鐨勬渶澶у悓鏃惰繛鎺ユ暟銆0鍊艰〃绀衡滄病鏈闄愬埗鈥濄

璇ュ彉閲忓叿鏈夊叏灞鑼冨洿鍜(鍙)浼氳瘽鑼冨洿銆備細璇濆彉閲忕殑鐨勫间笌鍏ㄥ眬鍙橀噺鐨勫肩浉鍚岋紝闄ら潪褰撳墠璐︽埛鍏锋湁闈為浂MAX_USER_CONNECTIONS璧勬簮闄愬埗銆傚湪杩欑鎯呭喌涓嬶紝浼氳瘽鍊煎弽搴斾簡璐︽埛闄愬埗銆

         max_write_lock_count

瓒呰繃鍐欓攣瀹氶檺鍒跺悗锛屽厑璁搁儴鍒嗚閿佸畾銆

         myisam_data_pointer_size

榛樿鎸囬拡澶у皬锛屽崟浣嶆槸瀛楄妭锛屽綋鏈寚瀹MAX_ROWS閫夐」鏃讹紝CREATE TABLE浣跨敤璇ュ彉閲忓垱寤MyISAM琛ㄣ傝鍙橀噺涓嶈兘灏忎簬2鎴栧ぇ浜7銆 榛樿鍊兼槸6銆傚弬瑙A.2.11鑺傦紝鈥滆〃宸叉弧鈥

         (DEPRECATED) myisam_max_extra_sort_file_size

閲婏細MySQL 5.1涓嶆敮鎸佽鍙橀噺銆傝缁嗕俊鎭弬瑙MySQL 5.0 鍙傝冩墜鍐

         myisam_max_sort_file_size

閲嶅缓MyISAM绱㈠紩(REPAIR TABLEALTER TABLELOAD DATA INFILE杩囩▼涓)鏃讹紝鍏佽MySQL浣跨敤鐨勪复鏃舵枃浠剁殑鏈澶х┖闂村ぇ灏忋傚鏋滄枃浠剁殑澶у皬瓒呰繃璇ュ硷紝鍒欎娇鐢ㄩ敭鍊肩紦瀛樺垱寤虹储寮曪紝瑕佹參寰楀銆傝鍊肩殑鍗曚綅涓哄瓧鑺傘

         myisam_recover_options

--myisam-recover閫夐」鐨勫笺

         myisam_repair_threads

濡傛灉璇ュ煎ぇ浜1锛屽湪Repair by sorting杩囩▼涓苟琛屽垱寤MyISAM琛ㄧ储寮(姣忎釜绱㈠紩鍦ㄨ嚜宸辩殑绾跨▼鍐)銆 榛樿鍊兼槸1閲婏細澶氱嚎绋嬬淮鎶や粛鐒舵槸alpha 缂栫爜銆

         myisam_sort_buffer_size

褰撳湪REPAIR TABLE鎴栫敤CREATE INDEX鍒涘缓绱㈠紩鎴ALTER TABLE杩囩▼涓帓搴 MyISAM绱㈠紩鍒嗛厤鐨勭紦鍐插尯銆

         myisam_stats_method

褰撲负MyISAM琛ㄦ悳闆嗗叧浜庣储寮曞煎垎鍙戠殑缁熻淇℃伅鏃舵湇鍔″櫒濡備綍澶勭悊NULL鍊笺傝鍙橀噺鏈変袱涓彲鑳界殑鍊硷紝nulls_equalnulls_unequal銆傚浜nulls_equal锛岃涓烘墍鏈NULL绱㈠紩鍊兼椂鐩哥瓑鐨勶紝骞跺舰鎴愪竴涓暟鍊肩粍锛屽叾绌洪棿澶у皬绛変簬NULL鍊肩殑鏁般傚浜nulls_unequalNULL鍊艰涓烘槸涓嶇浉绛夌殑锛屾瘡涓NULL褰㈡垚涓涓暟鍊肩粍锛屽ぇ灏忎负1

鏂规硶鐢ㄤ簬鐢熸垚琛ㄧ粺璁′俊鎭紝褰卞搷浼樺寲鍣ㄥ浣曢夋嫨绱㈠紩鏉ユ墽琛屾煡璇紝璇︾粏鎻忚堪瑙7.4.7鑺傦紝鈥淢yISAM绱㈠紩缁熻闆嗗悎鈥

         multi_read_range

鎸囧畾鑼冨洿閫夋嫨杩囩▼涓彂閫佸埌瀛樺偍寮曟搸鐨勮寖鍥寸殑鏈澶у笺傞粯璁ゅ兼槸256銆傚悜寮曟搸鍙戦佸涓寖鍥村彲浠ュぇ澶ф敼杩涙煇浜涢夋嫨鐨勬ц兘锛岀壒鍒槸瀵NDBCLUSTER銆傝寮曟搸闇瑕佸悜鎵鏈夎妭鐐瑰彂閫佽寖鍥磋姹傦紝鍚屾椂鍙戦佽澶氳姹傚彲浠ュぇ澶ч檷浣庨氫俊鎴愭湰銆

         named_pipe

(鍙傜敤Windows)璇存槑鏈嶅姟鍣ㄦ槸鍚︽敮鎸佸懡鍚嶇閬撹繛鎺ャ

         net_buffer_length

鍦ㄦ煡璇箣闂村皢閫氫俊缂撳啿鍖洪噸璁句负璇ュ笺備竴鑸儏鍐典笉搴旀敼鍙橈紝浣嗗鏋滃唴瀛樺緢灏忥紝鍙互灏嗗畠璁剧疆涓烘湡鏈涚殑瀹㈡埛绔彂閫佺殑SQL璇彞鐨勯暱搴︺傚鏋滆鍙ヨ秴鍑鸿闀垮害锛岀紦鍐插尯鑷姩鎵╁ぇ锛岀洿鍒max_allowed_packet瀛楄妭銆

         net_read_timeout

涓柇璇诲墠绛夊緟杩炴帴鐨勫叾瀹冩暟鎹殑绉掓暟銆傚綋鏈嶅姟鍣ㄤ粠瀹㈡埛绔鏁版椂锛net_read_timeout鎸囨帶鍒朵綍鏃朵腑鏂殑瓒呮椂鍊笺傚綋鏈嶅姟鍣ㄥ悜瀹㈡埛绔啓鏃讹紝net_write_timeout鎸囨帶鍒朵綍鏃朵腑鏂殑瓒呮椂鍊笺傚張瑙slave_net_timeout

         net_retry_count

濡傛灉鏌愪釜閫氫俊绔彛鐨勮鎿嶄綔涓柇浜嗭紝鍦ㄦ斁寮冨墠閲嶈瘯澶氭銆傚湪FreeBSD涓鍊煎簲璁惧緱寰堥珮锛屽洜涓哄唴閮ㄤ腑鏂皢鍙戦佽嚦鎵鏈夌嚎绋嬨

         net_write_timeout

涓柇鍐欎箣鍓嶇瓑寰呭潡鍐欏叆杩炴帴鐨勭鏁般傚張瑙net_read_timeout

         new

MySQL 4.0涓娇鐢ㄨ鍙橀噺鏉ユ墦寮4.1涓殑涓浜涜涓猴紝骞剁敤浜庡悜鍚庡吋瀹规с傚湪MySQL 5.1,瀹冪殑鍊间竴鐩存槸OFF.

         old_passwords

鏄惁鏈嶅姟鍣ㄥ簲涓MySQL鐢ㄦ埛璐︽埛浣跨敤pre-4.1-style瀵嗙爜銆傚弬瑙A.2.3鑺傦紝鈥滃鎴风涓嶆敮鎸侀壌瀹氬崗璁

         one_shot

杩欎笉鏄竴涓彉閲忥紝浣嗗綋璁剧疆鍙橀噺鏄彲浠ヤ娇鐢ㄥ畠銆傚叾鎻忚堪瑙13.5.3鑺傦紝鈥淪ET璇硶鈥

         one_shot

杩欎笉鏄竴涓彉閲忥紝浣嗗綋璁剧疆鍙橀噺鏄彲浠ヤ娇鐢ㄥ畠銆傚叾鎻忚堪瑙13.5.3鑺傦紝鈥淪ET璇硶鈥

         open_files_limit

鎿嶄綔绯荤粺鍏佽mysqld鎵撳紑鐨勬枃浠剁殑鏁伴噺銆傝繖鏄郴缁熷厑璁哥殑瀹為檯鍊硷紝鍙兘涓庝綘鍦ㄥ惎鍔ㄩ夐」涓祴缁mysqld鐨勫间笉鍚屻傝嫢鍦ㄧ郴缁熶腑MySQL涓嶈兘鏇存敼鎵撳紑鐨勬枃浠剁殑鏁伴噺锛屽垯璇ュ间负0

         optimizer_prune_level

鍦ㄦ煡璇紭鍖栦粠浼樺寲鍣ㄦ悳绱㈢┖闂磋鍑忎綆甯屾湜灞閮ㄨ鍒掍腑浣跨敤鐨勬帶鍒舵柟娉曘0鍊肩鐢ㄨ鏂规硶锛屼互渚夸紭鍖栧櫒杩涜绌蜂妇鎼滅储銆傚间负1浣夸紭鍖栧櫒鏍规嵁涓棿鏂规涓緱鍑虹殑琛屾暟鏉ヨ鍑忔柟妗堛

         optimizer_search_depth

鏌ヨ浼樺寲鍣ㄨ繘琛岀殑鎼滅储鐨勬渶澶ф繁搴︺傚鏋滃煎ぇ浜庢煡璇腑鐨勫叧绯绘暟鍒欐煡璇㈡柟妗堟瘮杈冧匠锛屼絾鐢熸垚鏌ヨ鎵ц鏂规闇瑕佺殑鏃堕棿鏇撮暱銆傚煎ぇ浜庢煡璇腑鐨勫叧绯绘暟鍒欒繑鍥炵殑鎵ц鏂规鏇村揩锛屼絾鏂规杩滄病鏈変紭鍖栥傚鏋滆缃负0, 绯荤粺鑷姩閫夋嫨鍚堢悊鐨勫笺傚鏋滆缃负鏌ヨ涓娇鐢ㄧ殑琛ㄧ殑鏈澶ф暟鍔2,浼樺寲鍣ㄨ浆鎹负MySQL 5.0.0(鍜屼互鍓嶇殑鐗堟湰)涓娇鐢ㄧ殑绠楁硶骞舵悳绱€

         pid_file

杩涚▼ID (PID)鏂囦欢鐨勮矾寰勫悕銆傚彲浠ョ敤--pid-file閫夐」璁剧疆璇ュ彉閲忋

         plugin_dir

鎻掍欢鐩綍鐨勮矾寰勩傚湪MySQL 5.1.2涓姞鍏ヤ簡璇ュ彉閲忋

         port

鏈嶅姟鍣ㄥ抚鍚TCP/IP杩炴帴鎵鐢ㄧ鍙c傚彲浠ョ敤--port閫夐」璁剧疆璇ュ彉閲忋

         preload_buffer_size

閲嶈浇绱㈠紩鏃跺垎閰嶇殑缂撳啿鍖哄ぇ灏忋

         protocol_version

MySQL鏈嶅姟鍣ㄤ娇鐢ㄧ殑瀹㈡埛绔/鏈嶅姟鍣ㄥ崗璁殑鐗堟湰銆

         query_alloc_block_size

涓烘煡璇㈠垎鏋愬拰鎵ц杩囩▼涓垱寤虹殑瀵硅薄鍒嗛厤鐨勫唴瀛樺潡澶у皬銆傚鏋滃唴瀛樺垎娈佃繃绋嬩腑閬囧埌闂锛屽皢璇ュ彉閲忓鍔犱竴浣嶄細鏈夊府鍔┿

         query_cache_limit

涓嶈缂撳瓨澶т簬璇ュ肩殑缁撴灉銆傞粯璁ゅ兼槸1048576(1MB)

         query_cache_min_res_unit

鏌ヨ缂撳瓨鍒嗛厤鐨勬渶灏忓潡鐨勫ぇ灏(瀛楄妭)銆 榛樿鍊兼槸4096(4KB)銆傚叧浜庤鍙橀噺鐨勮皟鑺備俊鎭弬瑙5.13.3鑺傦紝鈥滄煡璇㈤珮閫熺紦鍐查厤缃

         query_cache_size

涓虹紦瀛樻煡璇㈢粨鏋滃垎閰嶇殑鍐呭瓨鐨勬暟閲忋傞粯璁ゅ兼槸0锛屽嵆绂佺敤鏌ヨ缂撳瓨銆傝娉ㄦ剰鍗充娇query_cache_type璁剧疆涓0涔熷皢鍒嗛厤姝ゆ暟閲忕殑鍐呭瓨銆傝缁嗕俊鎭弬瑙5.13.3鑺傦紝鈥滄煡璇㈤珮閫熺紦鍐查厤缃

         query_cache_type

璁剧疆鏌ヨ缂撳瓨绫诲瀷銆傝缃GLOBAL鍊煎彲浠ヨ缃悗闈㈢殑鎵鏈夊鎴风杩炴帴鐨勭被鍨嬨傚鎴风鍙互璁剧疆SESSION鍊间互褰卞搷浠栦滑鑷繁瀵规煡璇㈢紦瀛樼殑浣跨敤銆備笅闈㈢殑琛ㄦ樉绀轰簡鍙兘鐨勫硷細

閫夐」

鎻忚堪

0OFF

涓嶈缂撳瓨鎴栨煡璇㈢粨鏋溿傝娉ㄦ剰杩欐牱涓嶄細鍙栨秷鍒嗛厤鐨勬煡璇㈢紦瀛樺尯銆傝鎯冲彇娑堬紝浣犲簲灏query_cache_size璁剧疆涓0

1ON

缂撳瓨闄や簡浠SELECT SQL_NO_CACHE寮澶寸殑鎵鏈夋煡璇㈢粨鏋溿

2DEMAND

鍙紦瀛樹互SELECT SQL_NO_CACHE寮澶寸殑鏌ヨ缁撴灉銆

璇ュ彉閲忛粯璁よ涓ON

         query_cache_wlock_invalidate

涓鑸儏鍐碉紝褰撳鎴风瀵MyISAM琛ㄨ繘琛WRITE閿佸畾鏃讹紝濡傛灉鏌ヨ缁撴灉浣嶄簬鏌ヨ缂撳瓨涓紝鍒欏叾瀹冨鎴风鏈閿佸畾锛屽彲浠ュ璇ヨ〃杩涜鏌ヨ銆傚皢璇ュ彉閲忚缃负1锛屽垯鍙互瀵硅〃杩涜WRITE閿佸畾锛屼娇鏌ヨ缂撳瓨鍐呮墍鏈夊璇ヨ〃杩涜鐨勬煡璇㈠彉寰楅潪娉曘傝繖鏍峰綋閿佸畾鐢熸晥鏃讹紝鍙互寮哄埗鍏跺畠璇曞浘璁块棶琛ㄧ殑瀹㈡埛绔潵绛夊緟銆

         query_prealloc_size

鐢ㄤ簬鏌ヨ鍒嗘瀽鍜屾墽琛岀殑鍥哄畾缂撳啿鍖虹殑澶у皬銆傚湪鏌ヨ涔嬮棿璇ョ紦鍐插尯涓嶉噴鏀俱傚鏋滀綘鎵ц澶嶆潅鏌ヨ锛屽垎閰嶆洿澶х殑query_prealloc_size鍊煎彲浠ュ府鍔╂彁楂樻ц兘锛屽洜涓哄畠鍙互闄嶄綆鏌ヨ杩囩▼涓湇鍔″櫒鍒嗛厤鍐呭瓨鐨勯渶姹傘

         range_alloc_block_size

鑼冨洿浼樺寲鏃跺垎閰嶇殑鍧楃殑澶у皬銆

         read_buffer_size

姣忎釜绾跨▼杩炵画鎵弿鏃朵负鎵弿鐨勬瘡涓〃鍒嗛厤鐨勭紦鍐插尯鐨勫ぇ灏(瀛楄妭)銆傚鏋滆繘琛屽娆¤繛缁壂鎻忥紝鍙兘闇瑕佸鍔犺鍊硷紝 榛樿鍊间负131072

         read_only

褰撳彉閲忓澶嶅埗浠庢湇鍔″櫒璁剧疆涓ON鏃讹紝浠庢湇鍔″櫒涓嶅厑璁告洿鏂帮紝闄ら潪閫氳繃浠庢湇鍔″櫒鐨勭嚎绋嬫垨鐢ㄦ埛鎷ユ湁SUPER鏉冮檺銆傚彲浠ョ‘淇濅粠鏈嶅姟鍣ㄤ笉鎺ュ彈瀹㈡埛绔殑鏇存柊鍛戒护銆

         relay_log_purge

褰撲笉鍐嶉渶瑕佷腑缁ф棩蹇楁椂绂佺敤鎴栧惎鐢ㄨ嚜鍔ㄦ竻绌轰腑缁ф棩蹇椼傞粯璁ゅ兼槸1(鍚敤)

         read_rnd_buffer_size

褰撴帓搴忓悗鎸夋帓搴忓悗鐨勯『搴忚鍙栬鏃讹紝鍒欓氳繃璇ョ紦鍐插尯璇诲彇琛岋紝閬垮厤鎼滅储纭洏銆傚皢璇ュ彉閲忚缃负杈冨ぇ鐨勫煎彲浠ュぇ澶ф敼杩ORDER BY鐨勬ц兘銆備絾鏄紝杩欐槸涓烘瘡涓鎴风鍒嗛厤鐨勭紦鍐插尯锛屽洜姝や綘涓嶅簲灏嗗叏灞鍙橀噺璁剧疆涓鸿緝澶х殑鍊笺傜浉鍙嶏紝鍙负闇瑕佽繍琛屽ぇ鏌ヨ鐨勫鎴风鏇存敼浼氳瘽鍙橀噺銆

         secure_auth

濡傛灉鐢--secure-auth閫夐」鍚姩浜MySQL鏈嶅姟鍣紝瀹冨皢闃诲鏈夋棫鏍煎紡(4.1涔嬪墠)瀵嗙爜鐨勬墍鏈夎处鎴锋墍鍙戣捣鐨勮繛鎺ャ傚湪杩欑鎯呭喌涓嬶紝璇ュ彉閲忕殑鍊间负ON锛屽惁鍒欎负OFF

濡傛灉浣犳兂瑕侀槻姝娇鐢ㄦ棫鏍煎紡鐨勫瘑鐮(鑷翠娇缃戠粶閫氫俊涓嶅畨鍏)锛屼綘搴斿惎鐢ㄨ閫夐」銆

濡傛灉鍚敤璇ラ夐」骞朵笖鎺堟潈琛ㄤ负pre-4.1鏍煎紡锛屾湇鍔″櫒鍚姩澶辫触骞朵笖浼氬嚭鐜伴敊璇傚弬瑙A.2.3鑺傦紝鈥滃鎴风涓嶆敮鎸侀壌瀹氬崗璁

褰撶敤浜庡鎴风閫夐」鏃讹紝濡傛灉鏈嶅姟鍣ㄩ渶瑕佽瀹㈡埛绔处鎴风殑鏃ф牸寮忕殑瀵嗙爜锛屽垯瀹㈡埛绔嫆缁濊繛鎺ヨ鏈嶅姟鍣ㄣ

         server_id

--server-id閫夐」鐨勫笺傜敤浜庝富澶嶅埗鏈嶅姟鍣ㄥ拰浠庡鍒舵湇鍔″櫒銆

         shared_memory

(鍙敤浜Windows)鏈嶅姟鍣ㄦ槸鍚﹀厑璁稿叡浜唴瀛樿繛鎺ャ

         shared_memory_base_name

(鍙敤浜Windows)璇存槑鏈嶅姟鍣ㄦ槸鍚﹀厑璁稿叡浜唴瀛樿繛鎺ワ紝骞朵负鍏变韩鍐呭瓨璁剧疆璇嗗埆绗︺傚綋鍦ㄥ崟鍙版満鍣ㄤ笂杩愯澶氫釜MySQL瀹炰緥鏃跺緢鏈夌敤銆

         skip_external_locking

濡傛灉mysqld浣跨敤澶栭儴閿佸畾锛岃鍊间负OFF

         skip_networking

濡傛灉鏈嶅姟鍣ㄥ彧鍏佽鏈湴(TCP/IP)杩炴帴锛岃鍊间负ON銆傚湪Unix涓紝鏈湴杩炴帴浣跨敤Unix濂楁帴瀛楁枃浠躲傚湪Windows涓紝鏈湴杩炴帴浣跨敤鍛藉悕绠¢亾鎴栧叡浜唴瀛樸傚湪NetWare涓紝鍙敮鎸TCP/IP杩炴帴锛屽洜姝や笉瑕佸皢璇ュ彉閲忚缃负ON

         skip_show_database

闃叉涓嶅叿鏈SHOW DATABASES鏉冮檺鐨勪汉浠娇鐢SHOW DATABASES璇彞銆傚鏋滀綘鎷呭績鐢ㄦ埛鑳藉鐪嬭灞炰簬鍏跺畠鐢ㄦ埛鐨勬暟鎹簱锛岃繖鏍疯缃彲浠ユ彁楂樺畨鍏ㄦс傚叾鏁堟灉鍙栧喅浜SHOW DATABASES鏉冮檺锛氬鏋滃彉閲忓间负ON锛屽彧鍏佽鍏锋湁SHOW DATABASES鏉冮檺鐨勪汉浠娇鐢SHOW DATABASES 璇彞锛屽苟涓旇璇彞灏嗘樉绀烘墍鏈夋暟鎹簱鍚嶃傚鏋滃间负OFF锛屽厑璁告墍鏈夌敤鎴锋墽琛SHOW DATABASES锛屼絾鍙樉绀虹敤鎴峰叿鏈SHOW DATABASES鎴栧叾瀹冩潈闄愮殑鏁版嵁搴撶殑鍚嶇О銆

         slave_compressed_protocol

濡傛灉涓汇佷粠鏈嶅姟鍣ㄥ潎鏀寔锛岀‘瀹氭槸鍚︿娇鐢ㄤ粠/涓诲帇缂╁崗璁

         slave_load_tmpdir

浠庢湇鍔″櫒涓哄鍒LOAD DATA INFILE璇彞鍒涘缓涓存椂鏂囦欢鐨勭洰褰曞悕銆

         slave_net_timeout

鏀惧純璇绘搷浣滃墠绛夊緟涓/浠庤繛鎺ョ殑鏇村鏁版嵁鐨勭瓑寰呯鏁般

         slave_skip_errors

浠庢湇鍔″櫒搴旇烦杩(蹇借)鐨勫鍒堕敊璇

         slave_transaction_retries

濡傛灉鐢变簬ofInnoDB姝婚攣鎴栬秴杩InnoDBinnodb_lock_wait_timeoutNDBCLUSTERTransactionDeadlockDetectionTimeoutTransactionInactiveTimeout澶嶅埗浠庢湇鍔″櫒SQL绾跨▼鏈兘鎵ц浜嬪姟锛屽湪鎻愮ず閿欒骞跺仠姝㈠墠瀹冭嚜鍔ㄩ噸澶slave_transaction_retries娆° 榛樿鍊兼槸10

         slow_launch_time

濡傛灉鍒涘缓绾跨▼鐨勬椂闂磋秴杩囪绉掓暟锛屾湇鍔″櫒澧炲姞Slow_launch_threads鐘舵佸彉閲忋

         socket

Unix骞冲彴锛氱敤浜庢湰鍦板鎴风杩炴帴鐨勫鎺ュ瓧鏂囦欢銆傞粯璁や负/var/lib/mysql/mysql.sock

Windows锛氱敤浜庢湰鍦板鎴风杩炴帴鐨勫懡鍚嶇閬撳悕銆傞粯璁や负mysql

         sort_buffer_size

姣忎釜鎺掑簭绾跨▼鍒嗛厤鐨勭紦鍐插尯鐨勫ぇ灏忋傚鍔犺鍊煎彲浠ュ姞蹇ORDER BYGROUP BY鎿嶄綔銆傚弬瑙A.4.4鑺傦紝鈥淢ySQL灏嗕复鏃舵枃浠跺偍瀛樺湪鍝噷鈥

         sql_mode

褰撳墠鐨勬湇鍔″櫒SQL妯″紡锛屽彲浠ュ姩鎬佽缃傚弬瑙5.3.2鑺傦紝鈥淪QL鏈嶅姟鍣ㄦā寮忊

         sql_slave_skip_counter

浠庢湇鍔″櫒搴旇烦杩囩殑鏉ヨ嚜涓绘湇鍔″櫒鐨勪簨浠舵暟銆

         storage_engine

璇ュ彉閲忔槸table_typeis鐨勫悓涔夎瘝銆傚湪MySQL 5.1,棣栭storage_engine

         sync_binlog

濡傛灉涓烘锛屽綋姣忎釜sync_binlog'th鍐欏叆璇ヤ簩杩涘埗鏃ュ織鍚庯紝MySQL鏈嶅姟鍣ㄥ皢瀹冪殑浜岃繘鍒舵棩蹇楀悓姝ュ埌纭洏涓(fdatasync())銆傝娉ㄦ剰濡傛灉鍦autocommit妯″紡锛屾瘡鎵ц涓涓鍙ュ悜浜岃繘鍒舵棩蹇楀啓鍏ヤ竴娆★紝鍚﹀垯姣忎釜浜嬪姟鍐欏叆涓娆° 榛樿鍊兼槸0锛屼笉涓庣‖鐩樺悓姝ャ傚间负1鏄渶瀹夊叏鐨勯夋嫨锛屽洜涓哄穿婧冩椂锛屼綘鏈澶氫涪鎺変簩杩涘埗鏃ュ織涓殑涓涓鍙/浜嬪姟锛涗絾鏄紝杩欐槸鏈鎱㈢殑閫夋嫨(闄ら潪纭洏鏈夌數姹犲浠界紦瀛橈紝浠庤屼娇鍚屾宸ヤ綔杈冨揩)

         sync_frm

濡傛灉璇ュ彉閲忚涓1,褰撳垱寤洪潪涓存椂琛ㄦ椂瀹冪殑.frm鏂囦欢琚悓姝ュ埌纭洏涓(fdatasync())锛涜繖鏍疯緝鎱絾鍑虹幇宕╂簝鏃惰緝瀹夊叏銆 榛樿鍊间负1

         system_time_zone

鏈嶅姟鍣ㄧ郴缁熸椂鍖恒傚綋 鏈嶅姟鍣ㄥ紑濮嬫墽琛屾椂锛屽畠缁ф壙鏈哄櫒榛樿鏃跺尯璁剧疆鍊硷紝鍙互鐢辫繍琛屾湇鍔″櫒鐨勮处鎴锋垨鍦ㄥ惎鍔ㄨ剼鏈腑杩涜淇敼銆傝鍊肩敤鏉ヨ缃system_time_zone銆傚吀鍨嬫儏鍐电敤TZ鐜鍙橀噺鏉ユ寚瀹氭椂鍖恒傝繕鍙互鐢mysqld_safe鑴氭湰鐨--timez閫夐」鏉ユ寚瀹氥

         table_cache

鎵鏈夌嚎绋嬫墦寮鐨勮〃鐨勬暟鐩傚澶ц鍊煎彲浠ュ鍔mysqld闇瑕佺殑鏂囦欢鎻忚堪绗︾殑鏁伴噺銆備綘鍙互妫鏌Opened_tables鐘舵佸彉閲忔潵妫鏌ヤ綘鏄惁闇瑕佸鍔犺〃缂撳瓨銆傚弬瑙5.3.4鑺傦紝鈥滄湇鍔″櫒鐘舵佸彉閲忊銆傚鏋Opened_tables鍊艰緝澶э紝骞朵笖澶氭鎵цFLUSH TABLES(鍙槸寮哄埗鍏抽棴鎵鏈夎〃骞堕噸鏂)锛屽垯搴斿鍔table_cache鍙橀噺鐨勫笺

鍏充簬琛ㄧ紦瀛樼殑璇︾粏淇℃伅锛屽弬瑙7.4.9鑺傦紝鈥淢ySQL濡備綍鎵撳紑鍜屽叧闂〃鈥

         table_type

榛樿琛ㄧ被鍨(瀛樺偍寮曟搸)銆傝鎯冲湪鏈嶅姟鍣ㄥ惎鍔ㄦ椂璁剧疆琛ㄧ被鍨嬶紝浣跨敤--default-table-type閫夐」銆傚弬瑙5.3.1鑺傦紝鈥mysqld鍛戒护琛岄夐」鈥

         thread_cache_size

鏈嶅姟鍣ㄥ簲缂撳瓨澶氬皯绾跨▼浠ヤ究閲嶆柊浣跨敤銆傚綋瀹㈡埛绔柇寮杩炴帴鏃讹紝濡傛灉绾跨▼灏戜簬thread_cache_size锛屽垯瀹㈡埛绔殑绾跨▼琚斁鍏ョ紦瀛樸傚綋璇锋眰绾跨▼鏃跺鏋滃厑璁稿彲浠ヤ粠缂撳瓨涓噸鏂板埄鐢ㄧ嚎绋嬶紝骞朵笖鍙湁褰撶紦瀛樼┖浜嗘椂鎵嶄細鍒涘缓鏂扮嚎绋嬨傚鏋滄柊杩炴帴寰堝锛屽彲浠ュ鍔犺鍙橀噺浠ユ彁楂樻ц兘銆(涓鑸儏鍐碉紝濡傛灉绾跨▼鎵ц寰楀緢濂斤紝鎬ц兘鎻愰珮涓嶆槑鏄)銆傛鏌ConnectionsThreads_created鐘舵佸彉閲忕殑宸(璇﹁5.3.4鑺傦紝鈥滄湇鍔″櫒鐘舵佸彉閲忊)锛屼綘鍙互鐪嬭绾跨▼缂撳瓨鐨勬晥鐜囥

         thread_concurrency

Solaris涓紝mysqld鐢ㄨ鍊艰皟鐢thr_setconcurrency()銆傝鍑芥暟浣垮簲鐢ㄧ▼搴忓悜绾跨▼绯荤粺鎻愪緵闇瑕佸悓鏃惰繍琛岀殑鏈熸湜鐨勭嚎绋嬫暟鐩殑鎻愮ず銆

         thread_stack

姣忎釜绾跨▼鐨勫爢鏍堝ぇ灏忋傜敤crash-me娴嬭瘯妫娴嬪嚭鐨勮澶氶檺鍒跺彇鍐充簬璇ュ笺 榛樿鍊艰冻澶熷ぇ锛屽彲浠ユ弧瓒虫櫘閫氭搷浣溿傚弬瑙7.1.4鑺傦紝鈥淢ySQL鍩哄噯濂椾欢鈥

         time_format

璇ュ彉閲忎负浣跨敤銆

         time_zone

褰撳墠鐨勬椂鍖恒傚垵浣垮兼槸'SYSTEM'(浣跨敤system_time_zone鐨勫)锛屼絾鍙互鐢--default-time-zone閫夐」鍦ㄦ湇鍔″櫒鍚姩鏃舵樉寮忔寚瀹氥

         tmp_table_size

濡傛灉鍐呭瓨鍐呯殑涓存椂琛ㄨ秴杩囪鍊硷紝MySQL鑷姩灏嗗畠杞崲涓虹‖鐩樹笂鐨MyISAM琛ㄣ傚鏋滀綘鎵ц璁稿楂樼骇GROUP BY鏌ヨ骞朵笖鏈夊ぇ閲忓唴瀛橈紝鍒欏彲浠ュ鍔tmp_table_size鐨勫笺

         tmpdir

淇濆瓨涓存椂鏂囦欢鍜屼复鏃惰〃鐨勭洰褰曘傝鍙橀噺鍙互璁剧疆涓哄嚑涓矾寰勶紝鎸round-robin妯″紡浣跨敤銆傚湪Unix涓簲璇ョ敤鍐掑彿(:)闂撮殧寮璺緞锛屽湪WindowsNetWareOS/2涓敤鍒嗗彿()

鐢ㄦ潵灏嗚礋鑽峰垎鏁e埌鍑犱釜鐗╃悊纭洏涓娿傚鏋MySQL鏈嶅姟鍣ㄤ负澶嶅埗浠庢湇鍔″櫒锛屼綘涓嶅簲灏tmpdir璁剧疆涓烘寚鍚戝熀浜庡唴瀛樼殑鏂囦欢绯荤粺涓婄殑鐩綍鎴栧綋鏈嶅姟鍣ㄤ富鏈洪噸鍚椂澹版槑鐨勭洰褰曘傚鍒朵粠鏈嶅姟鍣ㄩ渶瑕侀儴鍒嗕复鏃舵枃浠舵潵鍦ㄦ満鍣ㄩ噸鍚悗浠嶅彲鐢紝浠ヤ究瀹冨彲浠ュ鍒朵复鏃惰〃鎴栨墽琛LOAD DATA INFILE鎿嶄綔銆傚鏋滄湇鍔″櫒閲嶅惎鏃朵复鏃舵枃浠跺す涓殑鏂囦欢涓㈠け浜嗭紝鍒欏鍒跺け璐ャ備絾鏄紝濡傛灉浣犱娇鐢MySQL 4.0.0鎴栨洿鏂扮増鏈紝浣犲彲浠ヤ娇鐢 slave_load_tmpdir鍙橀噺璁剧疆浠庢湇鍔″櫒鐨勪复鏃剁洰褰曘傚湪杩欑鎯呭喌涓嬶紝浠庢湇鍔″櫒涓嶅啀浣跨敤甯歌tmpdir锛岃鏄庝綘鍙互灏tmpdir璁剧疆鍒颁竴涓潪鍥哄畾浣嶇疆銆

         transaction_alloc_block_size

涓轰繚瀛樺皢淇濆瓨鍒颁簩杩涘埗鏃ュ織涓殑浜嬪姟鐨勬煡璇㈣屽垎閰嶇殑鍐呭瓨鍧楃殑澶у皬(瀛楄妭)

         transaction_prealloc_size

transaction_alloc_blocks鍒嗛厤鐨勫浐瀹氱紦鍐插尯鐨勫ぇ灏忥紙瀛楄妭锛夛紝鍦ㄤ袱娆℃煡璇箣闂翠笉浼氶噴鏀俱備娇璇ュ艰冻澶熷ぇ锛屽皢鎵鏈夋煡璇㈠浐瀹氬埌涓涓簨鍔′腑锛屽彲浠ラ伩鍏嶅娆malloc()璋冪敤銆

         tx_isolation

榛樿浜嬪姟闅旂绾у埆銆傞粯璁ゅ间负REPEATABLE-READ

         updatable_views_with_limit

璇ュ彉閲忔帶鍒跺鏋滄洿鏂板寘鍚LIMIT瀛愬彞锛屾槸鍚﹀彲浠ュ湪褰撳墠琛ㄤ腑浣跨敤涓嶅寘鍚富鍏抽敭瀛楃殑瑙嗗浘杩涜鏇存柊銆(閫氬父鐢GUI宸ュ叿鐢熸垚杩欑被鏇存柊)銆傛洿鏂版寚UPDATEDELETE璇彞銆傝繖鍎夸富鍏抽敭瀛楁寚PRIMARY KEY锛屾垨涓涓UNIQUE绱㈠紩锛屽叾涓换浣曞垪涓嶅彲浠ュ寘鍚NULL

璇ュ彉閲忔湁涓や釜鍊硷細

o        1YES锛氬彧鍙戝嚭璀﹀憡(娌℃湁閿欒娑堟伅)銆傝繖鏄 榛樿鍊笺

o        0NO锛氱姝㈡洿鏂般

         version

鏈嶅姟鍣ㄧ増鏈彿銆

         version_bdb

BDB瀛樺偍寮曟搸鐗堟湰銆

         version_comment

configure鑴氭湰鏈変竴涓--with-comment閫夐」锛屽綋鏋勫缓MySQL鏃跺彲浠ヨ繘琛屾敞閲娿傝鍙橀噺鍖呭惈娉ㄩ噴鍊笺

         version_compile_machine

MySQL鏋勫缓鐨勬満鍣ㄦ垨鏋舵瀯鐨勭被鍨嬨

         version_compile_os

MySQL鏋勫缓鐨勬搷浣滅郴缁熺殑绫诲瀷銆

         wait_timeout

鏈嶅姟鍣ㄥ叧闂潪浜や簰杩炴帴涔嬪墠绛夊緟娲诲姩鐨勭鏁般

鍦ㄧ嚎绋嬪惎鍔ㄦ椂锛屾牴鎹叏灞wait_timeout鍊兼垨鍏ㄥ眬interactive_timeout鍊煎垵濮嬪寲浼氳瘽wait_timeout鍊硷紝鍙栧喅浜庡鎴风绫诲瀷(mysql_real_connect()鐨勮繛鎺ラ夐」CLIENT_INTERACTIVE瀹氫箟)銆傚張瑙interactive_timeout

5.3.3.1. 鍔ㄦ佺郴缁熷彉閲

璁稿鏈嶅姟鍣ㄧ郴缁熷彉閲忔槸鍔ㄦ佺殑锛屽彲浠ヤ娇鐢SET GLOBALSET SESSION鍦ㄨ繍琛屾椂璁剧疆銆備綘杩樺彲浠ヤ娇鐢SELECT鑾峰緱瀹冧滑鐨勫笺傚弬瑙9.4鑺傦紝鈥滅郴缁熷彉閲忊

涓嬮潰鐨勮〃鍒楀嚭浜嗘墍鏈夊姩鎬佺郴缁熷彉閲忋傛渶鍚1鍒楄鏄庢瘡涓彉閲忔槸鍚﹂傜敤GLOBALSESSION(鎴栦簩鑰)

鍙橀噺鍚

鍊肩被鍨

绫诲瀷

autocommit

boolean

SESSION

big_tables

boolean

SESSION

binlog_cache_size

numeric

GLOBAL

bulk_insert_buffer_size

numeric

GLOBAL | SESSION

character_set_client

string

GLOBAL | SESSION

character_set_connection

string

GLOBAL | SESSION

character_set_results

string

GLOBAL | SESSION

character_set_server

string

GLOBAL | SESSION

collation_connection

string

GLOBAL | SESSION

collation_server

string

GLOBAL | SESSION

completion_type

numeric

GLOBAL | SESSION

concurrent_insert

boolean

GLOBAL

connect_timeout

numeric

GLOBAL

convert_character_set

string

GLOBAL | SESSION

default_week_format

numeric

GLOBAL | SESSION

delay_key_write

OFF | ON | ALL

GLOBAL

delayed_insert_limit

numeric

GLOBAL

delayed_insert_timeout

numeric

GLOBAL

delayed_queue_size

numeric

GLOBAL

div_precision_increment

numeric

GLOBAL | SESSION

engine_condition_pushdown

boolean

GLOBAL | SESSION

error_count

numeric

SESSION

expire_logs_days

numeric

GLOBAL

flush

boolean

GLOBAL

flush_time

numeric

GLOBAL

foreign_key_checks

boolean

SESSION

ft_boolean_syntax

numeric

GLOBAL

group_concat_max_len

numeric

GLOBAL | SESSION

identity

numeric

SESSION

innodb_autoextend_increment

numeric

GLOBAL

innodb_concurrency_tickets

numeric

GLOBAL

innodb_max_dirty_pages_pct

numeric

GLOBAL

innodb_max_purge_lag

numeric

GLOBAL

innodb_support_xa

boolean

GLOBAL | SESSION

innodb_sync_spin_loops

numeric

GLOBAL

innodb_table_locks

boolean

GLOBAL | SESSION

innodb_thread_concurrency

numeric GLOBAL

 

innodb_thread_sleep_delay

numeric GLOBAL

 

insert_id

boolean

SESSION

interactive_timeout

numeric

GLOBAL | SESSION

join_buffer_size

numeric

GLOBAL | SESSION

key_buffer_size

numeric

GLOBAL

last_insert_id

numeric

SESSION

local_infile

boolean

GLOBAL

log_warnings

numeric

GLOBAL

long_query_time

numeric

GLOBAL | SESSION

low_priority_updates

boolean

GLOBAL | SESSION

max_allowed_packet

numeric

GLOBAL | SESSION

max_binlog_cache_size

numeric

GLOBAL

max_binlog_size

numeric

GLOBAL

max_connect_errors

numeric

GLOBAL

max_connections

numeric

GLOBAL

max_delayed_threads

numeric

GLOBAL

max_error_count

numeric

GLOBAL | SESSION

max_heap_table_size

numeric

GLOBAL | SESSION

max_insert_delayed_threads

numeric

GLOBAL

max_join_size

numeric

GLOBAL | SESSION

max_relay_log_size

numeric

GLOBAL

max_seeks_for_key

numeric

GLOBAL | SESSION

max_sort_length

numeric

GLOBAL | SESSION

max_tmp_tables

numeric

GLOBAL | SESSION

max_user_connections

numeric

GLOBAL

max_write_lock_count

numeric

GLOBAL

myisam_stats_method

enum

GLOBAL | SESSION

multi_read_range

numeric

GLOBAL | SESSION

myisam_data_pointer_size

numeric

GLOBAL

log_bin_trust_routine_creators

boolean

GLOBAL

myisam_max_sort_file_size

numeric

GLOBAL | SESSION

myisam_repair_threads

numeric

GLOBAL | SESSION

myisam_sort_buffer_size

numeric

GLOBAL | SESSION

net_buffer_length

numeric

GLOBAL | SESSION

net_read_timeout

numeric

GLOBAL | SESSION

net_retry_count

numeric

GLOBAL | SESSION

net_write_timeout

numeric

GLOBAL | SESSION

old_passwords

numeric

GLOBAL | SESSION

optimizer_prune_level

numeric

GLOBAL | SESSION

optimizer_search_depth

numeric

GLOBAL | SESSION

preload_buffer_size

numeric

GLOBAL | SESSION

query_alloc_block_size

numeric

GLOBAL | SESSION

query_cache_limit

numeric

GLOBAL

query_cache_size

numeric

GLOBAL

query_cache_type

enumeration

GLOBAL | SESSION

query_cache_wlock_invalidate

boolean

GLOBAL | SESSION

query_prealloc_size

numeric

GLOBAL | SESSION

range_alloc_block_size

numeric

GLOBAL | SESSION

read_buffer_size

numeric

GLOBAL | SESSION

read_only

numeric

GLOBAL

read_rnd_buffer_size

numeric

GLOBAL | SESSION

rpl_recovery_rank

numeric

GLOBAL

safe_show_database

boolean

GLOBAL

secure_auth

boolean

GLOBAL

server_id

numeric

GLOBAL

slave_compressed_protocol

boolean

GLOBAL

slave_net_timeout

numeric

GLOBAL

slave_transaction_retries

numeric

GLOBAL

slow_launch_time

numeric

GLOBAL

sort_buffer_size

numeric

GLOBAL | SESSION

sql_auto_is_null

boolean

SESSION

sql_big_selects

boolean

SESSION

sql_big_tables

boolean

SESSION

sql_buffer_result

boolean

SESSION

sql_log_bin

boolean

SESSION

sql_log_off

boolean

SESSION

sql_log_update

boolean

SESSION

sql_low_priority_updates

boolean

GLOBAL | SESSION

sql_max_join_size

numeric

GLOBAL | SESSION

sql_mode

enumeration

GLOBAL | SESSION

sql_notes

boolean

SESSION

sql_quote_show_create

boolean

SESSION

sql_safe_updates

boolean

SESSION

sql_select_limit

numeric

SESSION

sql_slave_skip_counter

numeric

GLOBAL

updatable_views_with_limit

enumeration

GLOBAL | SESSION

sql_warnings

boolean

SESSION

sync_binlog

numeric

GLOBAL

sync_frm

boolean

GLOBAL

storage_engine

enumeration

GLOBAL | SESSION

table_cache

numeric

GLOBAL

table_type

enumeration

GLOBAL | SESSION

thread_cache_size

numeric

GLOBAL

time_zone

string

GLOBAL | SESSION

timestamp

boolean

SESSION

tmp_table_size

enumeration

GLOBAL | SESSION

transaction_alloc_block_size

numeric

GLOBAL | SESSION

transaction_prealloc_size

numeric

GLOBAL | SESSION

tx_isolation

enumeration

GLOBAL | SESSION

unique_checks

boolean

SESSION

wait_timeout

numeric

GLOBAL | SESSION

warning_count

numeric

SESSION

鏍囪涓string鐨勫彉閲忛噰鐢ㄥ瓧绗︿覆鍊笺傛爣璁颁负numeric鐨勫彉閲忛噰鐢ㄦ暟瀛楀笺傛爣璁颁负boolean鐨勫彉閲忓彲浠ヨ缃负01ONOFF銆傛爣璁颁负enumeration鐨勫彉閲忎竴鑸儏鍐靛簲璁剧疆涓鸿鍙橀噺鐨勬煇涓彲鐢ㄥ硷紝浣嗚繕鍙互璁剧疆涓哄搴旀湡鏈涚殑鏋氫妇鍊肩殑鏁板瓧銆傚浜鏋氫妇绯荤粺鍙橀噺锛岀1涓灇涓惧煎簲瀵瑰簲0銆傝繖涓嶅悓浜ENUM鍒楋紝绗1涓灇涓惧煎搴1

5.3.4. 鏈嶅姟鍣ㄧ姸鎬佸彉閲

鏈嶅姟鍣ㄧ淮鎶よ澶氭彁渚涙搷浣滅浉鍏充俊鎭殑鐘舵佸彉閲忋備綘鍙互閫氳繃SHOW STATUS璇彞鏌ョ湅杩欎簺鍙橀噺鍜屽畠浠殑鍊硷細

mysql> SHOW STATUS;
+-----------------------------------+------------+
| Variable_name                     | Value      |
+-----------------------------------+------------+
| Aborted_clients                   | 0          |
| Aborted_connects                  | 0          |
| Bytes_received                    | 155372598  |
| Bytes_sent                        | 1176560426 |
 
 
| Connections                       | 30023      |
| Created_tmp_disk_tables           | 0          |
| Created_tmp_files                 | 3          |
| Created_tmp_tables                | 2          |
 
 
| Threads_created                   | 217        |
| Threads_running                   | 88         |
| Uptime                            | 1389872    |
+-----------------------------------+------------+
 

FLUSH STATUS璇彞鍙互灏嗚澶氱姸鎬佸彉閲忛噸璁句负0

鐘舵佸彉閲忔湁浠ヤ笅鍚箟銆傛病鏈夋寚绀虹増鏈殑鍙橀噺鍦MySQL 5.1涔嬪墠宸茬粡鍑虹幇銆傚叧浜庡畠浠殑浣跨敤鍘嗗彶锛屽弬瑙MySQL 5.0鍙傝冩墜鍐

         Aborted_clients

鐢变簬瀹㈡埛绔病鏈夋纭叧闂繛鎺ュ鑷村鎴风缁堟鑰屼腑鏂殑杩炴帴鏁般傚弬瑙A.2.10鑺傦紝鈥滈氫俊閿欒鍜屽け鏁堣繛鎺モ

         Aborted_connects

璇曞浘杩炴帴鍒MySQL鏈嶅姟鍣ㄨ屽け璐ョ殑杩炴帴鏁般傚弬瑙A.2.10鑺傦紝鈥滈氫俊閿欒鍜屽け鏁堣繛鎺モ

         Binlog_cache_disk_use

浣跨敤涓存椂浜岃繘鍒舵棩蹇楃紦瀛樹絾瓒呰繃binlog_cache_size鍊煎苟浣跨敤涓存椂鏂囦欢鏉ヤ繚瀛樹簨鍔′腑鐨勮鍙ョ殑浜嬪姟鏁伴噺銆

         Binlog_cache_use

浣跨敤涓存椂浜岃繘鍒舵棩蹇楃紦瀛樼殑浜嬪姟鏁伴噺銆

         Bytes_received

浠庢墍鏈夊鎴风鎺ユ敹鍒扮殑瀛楄妭鏁般

         Bytes_sent

鍙戦佺粰鎵鏈夊鎴风鐨勫瓧鑺傛暟銆

         Com_xxx

Com_xxx 璇彞璁℃暟鍙橀噺琛ㄧず姣忎釜xxx 璇彞鎵ц鐨勬鏁般傛瘡绫昏鍙ユ湁涓涓姸鎬佸彉閲忋備緥濡傦紝Com_deleteCom_insert鍒嗗埆缁熻DELETE INSERT璇彞鎵ц鐨勬鏁般

Com_stmt_xxx鐘舵佸彉閲忎负锛

o        Com_stmt_prepare

o        Com_stmt_execute

o        Com_stmt_fetch

o        Com_stmt_send_long_data

o        Com_stmt_reset

o        Com_stmt_close

杩欎簺鍙橀噺浠h〃鍑嗗濂界殑璇彞鍛戒护銆傚畠浠殑鍚嶅瓧瀵瑰簲缃戠粶灞備娇鐢ㄧ殑COM_xxx 鍛戒护绯诲垪锛涙崲鍙ヨ瘽璇达細褰撳噯澶囧ソ鐨勮鍙API璋冪敤濡mysql_stmt_prepare()mysql_stmt_鎵ц()骞舵墽琛屾椂锛屽畠浠殑鍊煎鍔犮備絾鏄紝褰撴墽琛屼笅闈㈢殑SQL璇彞鏃讹紝Com_stmt_prepare, Com_stmt_executeCom_stmt_close涔熷鍔狅細PREPAREEXECUTEDEALLOCATE PREPARE銆傛澶栵紝鏃(MySQL 4.1.3璧峰彲鐢)璇彞璁℃暟鍙橀噺Com_prepare_sqlCom_execute_sqlCom_dealloc_sql鐨勫间篃闅PREPAREEXECUTEDEALLOCATE PREPARE璇彞澧炲姞銆Com_stmt_fetch浠h〃閫氳繃鍏夋爣鑾峰彇鐨勭綉缁round-trips鐨勬绘暟閲忋

鎵鏈Com_stmt_xxx鍙橀噺灏嗗鍔狅紝鍗充娇璇彞鍙傛暟鏈煡鎴栨墽琛岃繃绋嬩腑鍑虹幇閿欒銆傛崲鍙ヨ瘽璇达紝瀹冧滑鐨勫煎搴斿彂鍑虹殑璇锋眰鏁帮紝鑰屼笉鏄垚鍔熷畬鎴愮殑璇锋眰鏁般

         Connections

璇曞浘杩炴帴鍒(涓嶇鏄惁鎴愬姛)MySQL鏈嶅姟鍣ㄧ殑杩炴帴鏁般

         Created_tmp_disk_tables

鏈嶅姟鍣ㄦ墽琛岃鍙ユ椂鍦ㄧ‖鐩樹笂鑷姩鍒涘缓鐨勪复鏃惰〃鐨勬暟閲忋

         Created_tmp_files

mysqld宸茬粡鍒涘缓鐨勪复鏃舵枃浠剁殑鏁伴噺銆

         Created_tmp_files

鏈嶅姟鍣ㄦ墽琛岃鍙ユ椂鑷姩鍒涘缓鐨勫唴瀛樹腑鐨勪复鏃惰〃鐨勬暟閲忋傚鏋Created_tmp_disk_tables杈冨ぇ锛屼綘鍙兘瑕佸鍔tmp_table_size鍊间娇涓存椂 琛ㄥ熀浜庡唴瀛樿屼笉鍩轰簬纭洏銆

         Delayed_errors

INSERT DELAYED鍐欑殑鍑虹幇閿欒鐨勮鏁(鍙兘涓duplicate key)

         Delayed_insert_threads

浣跨敤鐨INSERT DELAYED澶勭悊鍣ㄧ嚎绋嬫暟銆

         Delayed_writes

鍐欏叆鐨INSERT DELAYED琛屾暟銆

         Flush_commands

鎵ц鐨FLUSH璇彞鏁般

         Handler_commit

鍐呴儴鎻愪氦璇彞鏁般

         Handler_discover

MySQL鏈嶅姟鍣ㄥ彲浠ラ棶NDB CLUSTER瀛樺偍寮曟搸鏄惁鐭ラ亾鏌愪竴鍚嶅瓧鐨勮〃銆傝繖琚О浣滃彂鐜般Handler_discover璇存槑閫氳繃璇ユ柟娉曞彂鐜扮殑娆℃暟銆

         Handler_delete

琛屼粠琛ㄤ腑鍒犻櫎鐨勬鏁般

         Handler_read_first

绱㈠紩涓涓鏉¤璇荤殑娆℃暟銆傚鏋滆緝楂橈紝瀹冨缓璁湇鍔″櫒姝f墽琛屽ぇ閲忓叏绱㈠紩鎵弿锛涗緥濡傦紝SELECT col1 FROM foo锛屽亣瀹col1鏈夌储寮曘

         Handler_read_key

鏍规嵁閿涓琛岀殑璇锋眰鏁般傚鏋滆緝楂橈紝璇存槑鏌ヨ鍜岃〃鐨勭储寮曟纭

         Handler_read_next

鎸夌収閿『搴忚涓嬩竴琛岀殑璇锋眰鏁般傚鏋滀綘鐢ㄨ寖鍥寸害鏉熸垨濡傛灉鎵ц绱㈠紩鎵弿鏉ユ煡璇㈢储寮曞垪锛岃鍊煎鍔犮

         Handler_read_prev

鎸夌収閿『搴忚鍓嶄竴琛岀殑璇锋眰鏁般傝璇绘柟娉曚富瑕佺敤浜庝紭鍖ORDER BY ... DESC

         Handler_read_rnd

鏍规嵁鍥哄畾浣嶇疆璇讳竴琛岀殑璇锋眰鏁般傚鏋滀綘姝f墽琛屽ぇ閲忔煡璇㈠苟闇瑕佸缁撴灉杩涜鎺掑簭璇ュ艰緝楂樸備綘鍙兘浣跨敤浜嗗ぇ閲忛渶瑕MySQL鎵弿鏁翠釜琛ㄧ殑鏌ヨ鎴栦綘鐨勮繛鎺ユ病鏈夋纭娇鐢ㄩ敭銆

         Handler_read_rnd_next

鍦ㄦ暟鎹枃浠朵腑璇讳笅涓琛岀殑璇锋眰鏁般傚鏋滀綘姝h繘琛屽ぇ閲忕殑琛ㄦ壂鎻忥紝璇ュ艰緝楂樸傞氬父璇存槑浣犵殑琛ㄧ储寮曚笉姝g‘鎴栧啓鍏ョ殑鏌ヨ娌℃湁鍒╃敤绱㈠紩銆

         Handler_rollback

鍐呴儴ROLLBACK璇彞鐨勬暟閲忋

         Handler_update

鍦ㄨ〃鍐呮洿鏂颁竴琛岀殑璇锋眰鏁般

         Handler_write

鍦ㄨ〃鍐呮彃鍏ヤ竴琛岀殑璇锋眰鏁般

         Innodb_buffer_pool_pages_data

鍖呭惈鏁版嵁鐨勯〉鏁(鑴忔垨骞插噣)

         Innodb_buffer_pool_pages_dirty

褰撳墠鐨勮剰椤垫暟銆

         Innodb_buffer_pool_pages_flushed

瑕佹眰娓呯┖鐨勭紦鍐叉睜椤垫暟銆

         Innodb_buffer_pool_pages_free

绌洪〉鏁般

         Innodb_buffer_pool_pages_latched

InnoDB缂撳啿姹犱腑閿佸畾鐨勯〉鏁般傝繖鏄綋鍓嶆璇绘垨鍐欐垨鐢变簬鍏跺畠鍘熷洜涓嶈兘娓呯┖鎴栧垹闄ょ殑椤垫暟銆

           Innodb_buffer_pool_pages_misc

蹇欑殑椤垫暟锛屽洜涓哄畠浠凡缁忚鍒嗛厤浼樺厛鐢ㄤ綔绠$悊锛屼緥濡傝閿佸畾鎴栭傜敤鐨勫搱甯岀储寮曘傝鍊艰繕鍙互璁$畻涓Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free - Innodb_buffer_pool_pages_data

         Innodb_buffer_pool_pages_total

缂撳啿姹犳诲ぇ灏忥紙椤垫暟锛夈

         Innodb_buffer_pool_read_ahead_rnd

InnoDB鍒濆鍖栫殑鈥闅忔満read-aheads鏁般傚綋鏌ヨ浠ラ殢鏈洪『搴忔壂鎻忚〃鐨勪竴澶ч儴鍒嗘椂鍙戠敓銆

         Innodb_buffer_pool_read_ahead_seq

InnoDB鍒濆鍖栫殑椤哄簭read-aheads鏁般傚綋InnoDB鎵ц椤哄簭鍏ㄨ〃鎵弿鏃跺彂鐢熴

         Innodb_buffer_pool_read_requests

InnoDB宸茬粡瀹屾垚鐨勯昏緫璇昏姹傛暟銆

         Innodb_buffer_pool_reads

涓嶈兘婊¤冻InnoDB蹇呴』鍗曢〉璇诲彇鐨勭紦鍐叉睜涓殑閫昏緫璇绘暟閲忋

         Innodb_buffer_pool_wait_free

涓鑸儏鍐碉紝閫氳繃鍚庡彴鍚InnoDB缂撳啿姹犲啓銆備絾鏄紝濡傛灉闇瑕佽鎴栧垱寤洪〉锛屽苟涓旀病鏈夊共鍑鐨勯〉鍙敤锛屽垯瀹冭繕闇瑕佸厛绛夊緟椤甸潰娓呯┖銆傝璁℃暟鍣ㄥ绛夊緟瀹炰緥杩涜璁版暟銆傚鏋滃凡缁忛傚綋璁剧疆缂撳啿姹犲ぇ灏忥紝璇ュ煎簲灏忋

         Innodb_buffer_pool_write_requests

InnoDB缂撳啿姹犵殑鍐欐暟閲忋

         Innodb_data_fsyncs

fsync()鎿嶄綔鏁般

         Innodb_data_pending_fsyncs

褰撳墠鎸傝捣鐨fsync()鎿嶄綔鏁般

         Innodb_data_pending_reads

褰撳墠鎸傝捣鐨勮鏁般

         Innodb_data_pending_writes

褰撳墠鎸傝捣鐨勫啓鏁般

         Innodb_data_read

鑷虫宸茬粡璇诲彇鐨勬暟鎹暟閲忥紙瀛楄妭锛夈

         Innodb_data_reads

鏁版嵁璇绘绘暟閲忋

         Innodb_data_writes

鏁版嵁鍐欐绘暟閲忋

         Innodb_data_written

鑷虫宸茬粡鍐欏叆鐨勬暟鎹噺锛堝瓧鑺傦級銆

         Innodb_dblwr_writes, Innodb_dblwr_pages_written

宸茬粡鎵ц鐨勫弻鍐欐搷浣滄暟閲忓拰涓烘鐩殑宸茬粡鍐欏ソ鐨勯〉鏁般傚弬瑙15.2.14.1鑺傦紝鈥滅鐩業/O鈥

         Innodb_log_waits

鎴戜滑蹇呴』绛夊緟鐨勬椂闂达紝鍥犱负鏃ュ織缂撳啿鍖哄お灏忥紝鎴戜滑鍦ㄧ户缁墠蹇呴』鍏堢瓑寰呭瀹冩竻绌恒

         Innodb_log_write_requests

鏃ュ織鍐欒姹傛暟銆

         Innodb_log_writes

鍚戞棩蹇楁枃浠剁殑鐗╃悊鍐欐暟閲忋

         Innodb_os_log_fsyncs

鍚戞棩蹇楁枃浠跺畬鎴愮殑fsync()鍐欐暟閲忋

         Innodb_os_log_pending_fsyncs

鎸傝捣鐨勬棩蹇楁枃浠fsync()鎿嶄綔鏁伴噺銆

         Innodb_os_log_pending_writes

鎸傝捣鐨勬棩蹇楁枃浠跺啓鎿嶄綔銆

         Innodb_os_log_written

鍐欏叆鏃ュ織鏂囦欢鐨勫瓧鑺傛暟銆

         Innodb_page_size

缂栬瘧鐨InnoDB椤靛ぇ灏(榛樿16KB)銆傝澶氬肩敤椤垫潵璁版暟锛涢〉鐨勫ぇ灏忓緢瀹规槗杞崲涓哄瓧鑺傘

         Innodb_pages_created

鍒涘缓鐨勯〉鏁般

         Innodb_pages_read

璇诲彇鐨勯〉鏁般

         Innodb_pages_written

鍐欏叆鐨勯〉鏁般

         Innodb_row_lock_current_waits

褰撳墠绛夊緟鐨勫緟閿佸畾鐨勮鏁般

         Innodb_row_lock_time

琛岄攣瀹氳姳璐圭殑鎬绘椂闂达紝鍗曚綅姣銆

         Innodb_row_lock_time_avg

琛岄攣瀹氱殑骞冲潎鏃堕棿锛屽崟浣嶆绉掋

         Innodb_row_lock_time_max

琛岄攣瀹氱殑鏈闀挎椂闂达紝鍗曚綅姣銆

         Innodb_row_lock_waits

涓琛岄攣瀹氬繀椤荤瓑寰呯殑鏃堕棿鏁般

         Innodb_rows_deleted

InnoDB琛ㄥ垹闄ょ殑琛屾暟銆

         Innodb_rows_inserted

鎻掑叆鍒InnoDB琛ㄧ殑琛屾暟銆

         Innodb_rows_read

InnoDB琛ㄨ鍙栫殑琛屾暟銆

         Innodb_rows_updated

InnoDB琛ㄥ唴鏇存柊鐨勮鏁般

         Key_blocks_not_flushed

閿紦瀛樺唴宸茬粡鏇存敼浣嗚繕娌℃湁娓呯┖鍒扮‖鐩樹笂鐨勯敭鐨勬暟鎹潡鏁伴噺銆

         Key_blocks_unused

閿紦瀛樺唴鏈娇鐢ㄧ殑鍧楁暟閲忋備綘鍙互浣跨敤璇ュ兼潵纭畾浣跨敤浜嗗灏戦敭缂撳瓨锛涘弬瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥Key_buffer_size鐨勮璁恒

         Key_blocks_used

閿紦瀛樺唴浣跨敤鐨勫潡鏁伴噺銆傝鍊间负楂樻按骞崇嚎鏍囪锛岃鏄庡凡缁忓悓鏃舵渶澶氫娇鐢ㄤ簡澶氬皯鍧椼

         Key_read_requests

浠庣紦瀛樿閿殑鏁版嵁鍧楃殑璇锋眰鏁般

         Key_reads

浠庣‖鐩樿鍙栭敭鐨勬暟鎹潡鐨勬鏁般傚鏋Key_reads杈冨ぇ锛屽垯Key_buffer_size鍊煎彲鑳藉お灏忋傚彲浠ョ敤Key_reads/Key_read_requests璁$畻缂撳瓨鎹熷け鐜囥

         Key_write_requests

灏嗛敭鐨勬暟鎹潡鍐欏叆缂撳瓨鐨勮姹傛暟銆

         Key_writes

鍚戠‖鐩樺啓鍏ュ皢閿殑鏁版嵁鍧楃殑鐗╃悊鍐欐搷浣滅殑娆℃暟銆

         Last_query_cost

鐢ㄦ煡璇紭鍖栧櫒璁$畻鐨勬渶鍚庣紪璇戠殑鏌ヨ鐨勬绘垚鏈傜敤浜庡姣斿悓涓鏌ヨ鐨勪笉鍚屾煡璇㈡柟妗堢殑鎴愭湰銆傞粯璁ゅ0琛ㄧず杩樻病鏈夌紪璇戞煡璇€ 榛樿鍊兼槸0Last_query_cost鍏锋湁浼氳瘽鑼冨洿銆

         Max_used_connections

鏈嶅姟鍣ㄥ惎鍔ㄥ悗宸茬粡鍚屾椂浣跨敤鐨勮繛鎺ョ殑鏈澶ф暟閲忋

         Not_flushed_delayed_rows

绛夊緟鍐欏叆INSERT DELAY闃熷垪鐨勮鏁般

         Open_files

鎵撳紑鐨勬枃浠剁殑鏁扮洰銆

         Open_streams

鎵撳紑鐨勬祦鐨勬暟閲(涓昏鐢ㄤ簬璁板綍)

         Open_tables

褰撳墠鎵撳紑鐨勮〃鐨勬暟閲忋

         Opened_tables

宸茬粡鎵撳紑鐨勮〃鐨勬暟閲忋傚鏋Opened_tables杈冨ぇ锛table_cache 鍊煎彲鑳藉お灏忋

         QCACHE_free_blocks

鏌ヨ缂撳瓨鍐呰嚜鐢卞唴瀛樺潡鐨勬暟閲忋

         QCACHE_free_memory

鐢ㄤ簬鏌ヨ缂撳瓨鐨勮嚜鐢卞唴瀛樼殑鏁伴噺銆

         QCACHE_hits

鏌ヨ缂撳瓨琚闂殑娆℃暟銆

         QCACHE_inserts

鍔犲叆鍒扮紦瀛樼殑鏌ヨ鏁伴噺銆

         QCACHE_lowmem_prunes

鐢变簬鍐呭瓨杈冨皯浠庣紦瀛樺垹闄ょ殑鏌ヨ鏁伴噺銆

         QCACHE_not_cached

闈炵紦瀛樻煡璇㈡暟(涓嶅彲缂撳瓨锛屾垨鐢变簬query_cache_type璁惧畾鍊兼湭缂撳瓨)

         Qcache_queries_in_cache

鐧昏鍒扮紦瀛樺唴鐨勬煡璇㈢殑鏁伴噺銆

         Qcache_total_blocks

鏌ヨ缂撳瓨鍐呯殑鎬诲潡鏁般

         Questions

宸茬粡鍙戦佺粰鏈嶅姟鍣ㄧ殑鏌ヨ鐨勪釜鏁般

         Rpl_status

澶辫触瀹夊叏澶嶅埗鐘舵(杩樻湭浣跨敤)

         Select_full_join

娌℃湁浣跨敤绱㈠紩鐨勮仈鎺ョ殑鏁伴噺銆傚鏋滆鍊间笉涓0,浣犲簲浠旂粏妫鏌ヨ〃鐨勭储寮曘

         Select_full_range_join

鍦ㄥ紩鐢ㄧ殑琛ㄤ腑浣跨敤鑼冨洿鎼滅储鐨勮仈鎺ョ殑鏁伴噺銆

         Select_range

鍦ㄧ涓涓〃涓娇鐢ㄨ寖鍥寸殑鑱旀帴鐨勬暟閲忋備竴鑸儏鍐典笉鏄叧閿棶棰橈紝鍗充娇璇ュ肩浉褰撳ぇ銆

         Select_range_check

鍦ㄦ瘡涓琛屾暟鎹悗瀵归敭鍊艰繘琛屾鏌ョ殑涓嶅甫閿肩殑鑱旀帴鐨勬暟閲忋傚鏋滀笉涓0锛屼綘搴斾粩缁嗘鏌ヨ〃鐨勭储寮曘

         Select_scan

瀵圭涓涓〃杩涜瀹屽叏鎵弿鐨勮仈鎺ョ殑鏁伴噺銆

         Slave_open_temp_tables

褰撳墠鐢变粠SQL绾跨▼鎵撳紑鐨勪复鏃惰〃鐨勬暟閲忋

         Slave_running

濡傛灉璇ユ湇鍔″櫒鏄繛鎺ュ埌涓绘湇鍔″櫒鐨勪粠鏈嶅姟鍣紝鍒欒鍊间负ON

         Slave_retried_transactions

鍚姩鍚庡鍒朵粠鏈嶅姟鍣SQL绾跨▼灏濊瘯浜嬪姟鐨勬绘鏁般

         Slow_launch_threads

鍒涘缓鏃堕棿瓒呰繃slow_launch_time绉掔殑绾跨▼鏁般

         Slow_queries

鏌ヨ鏃堕棿瓒呰繃long_query_time绉掔殑鏌ヨ鐨勪釜鏁般傚弬瑙5.11.4鑺傦紝鈥滄參閫熸煡璇㈡棩蹇椻

         Sort_merge_passes

鎺掑簭绠楁硶宸茬粡鎵ц鐨勫悎骞剁殑鏁伴噺銆傚鏋滆繖涓彉閲忓艰緝澶э紝搴旇冭檻澧炲姞sort_buffer_size绯荤粺鍙橀噺鐨勫笺

         Sort_range

鍦ㄨ寖鍥村唴鎵ц鐨勬帓搴忕殑鏁伴噺銆

         Sort_rows

宸茬粡鎺掑簭鐨勮鏁般

         Sort_scan

閫氳繃鎵弿琛ㄥ畬鎴愮殑鎺掑簭鐨勬暟閲忋

         Ssl_xxx

鐢ㄤ簬SSL杩炴帴鐨勫彉閲忋

         Table_locks_immediate

绔嬪嵆鑾峰緱鐨勮〃鐨勯攣鐨勬鏁般

         Table_locks_waited

涓嶈兘绔嬪嵆鑾峰緱鐨勮〃鐨勯攣鐨勬鏁般傚鏋滆鍊艰緝楂橈紝骞朵笖鏈夋ц兘闂锛屼綘搴旈鍏堜紭鍖栨煡璇紝鐒跺悗鎷嗗垎琛ㄦ垨浣跨敤澶嶅埗銆

         Threads_cached

绾跨▼缂撳瓨鍐呯殑绾跨▼鐨勬暟閲忋

         Threads_connected

褰撳墠鎵撳紑鐨勮繛鎺ョ殑鏁伴噺銆

         Threads_created

鍒涘缓鐢ㄦ潵澶勭悊杩炴帴鐨勭嚎绋嬫暟銆傚鏋Threads_created杈冨ぇ锛屼綘鍙兘瑕佸鍔thread_cache_size鍊笺傜紦瀛樿闂巼鐨勮绠楁柟娉Threads_created/Connections

           Threads_running

婵娲荤殑锛堥潪鐫$湢鐘舵侊級绾跨▼鏁般

         Uptime

鏈嶅姟鍣ㄥ凡缁忚繍琛岀殑鏃堕棿锛堜互绉掍负鍗曚綅锛夈

5.4. mysql_fix_privilege_tables锛氬崌绾ySQL绯荤粺琛

涓浜MySQL鍙戝竷瀵mysql鏁版嵁搴撲腑鐨勭郴缁熻〃鐨勭粨鏋勮繘琛屼簡鏇存敼锛屾坊鍔犱簡鏂版潈闄愭垨鐗规с傚綋浣犳洿鏂板埌鏂扮増鏈MySQL锛屼綘搴斿悓鏃舵洿鏂扮郴缁熻〃锛屼互纭繚瀹冧滑鐨勭粨鏋勬渶鏂般傞鍏堝浠mysql鏁版嵁搴擄紝鐒跺悗鎸夌収涓嬮潰鐨勭▼搴忔搷浣溿

UnixUnix绫荤郴缁熶腑锛岃繍琛mysql_fix_privilege_tables鑴氭湰鏉ユ洿鏂扮郴缁熻〃锛

shell> mysql_fix_privilege_tables

浣犲繀椤诲湪鏈嶅姟鍣ㄨ繍琛屾椂鎵ц璇ヨ剼鏈傚畠璇曞浘杩炴帴鏈満涓婄敤root杩愯鐨勬湇鍔″櫒銆傚鏋root璐︽埛闇瑕佸瘑鐮侊紝鍦ㄥ懡浠よ涓寜涓嬭堪鏂规硶缁欏嚭瀵嗙爜锛

shell> mysql_fix_privilege_tables--password=root_password

mysql_fix_privilege_tables鑴氭湰鍙互鎵ц灏嗙郴缁熻〃杞崲涓哄綋鍓嶆牸寮忕殑浠讳綍鍔ㄤ綔銆傝繍琛屾椂浣犲彲鑳戒細鐪嬭涓浜Duplicate column name璀﹀憡锛涗綘鍙互蹇界暐瀹冧滑銆

杩愯瀹岃剼鏈悗锛屽仠姝㈡湇鍔″櫒骞堕噸鍚

Windows绯荤粺涓紝MySQL鍒嗗彂鍖呮嫭mysql_fix_privilege_tables.sql SQL鑴氭湰锛屼綘鍙互鐢mysql瀹㈡埛绔潵杩愯銆備緥濡傦紝濡傛灉MySQL瀹夎鍒C:\Program Files\MySQL\MySQL Server 5.1锛屽懡浠ゅ簲涓猴細

C:\> C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql -u root -p mysql
mysql> SOURCE C:/Program Files/MySQL/MySQL Server 5.1/scripts/mysql_fix_privilege_tables.sql

濡傛灉瀹夎鍒板叾瀹冪洰褰曪紝鐩稿簲鍦版洿鏀硅矾寰勫悕銆

mysql鍛戒护灏嗘彁绀鸿緭鍏root瀵嗙爜锛涙寜鐓ф彁绀鸿緭鍏ュ瘑鐮併

Unix涓紝褰mysql澶勭悊mysql_fix_privilege_tables.sql script鑴氭湰涓殑璇彞鏃讹紝浣犲彲鑳戒細鐪嬭涓浜Duplicate column name璀﹀憡锛涗綘鍙互蹇界暐瀹冧滑銆

杩愯瀹岃剼鏈悗锛屽仠姝㈡湇鍔″櫒骞堕噸鍚

5.5. MySQL鏈嶅姟鍣ㄥ叧鏈鸿繘绋

  1.  鏈嶅姟鍣ㄥ叧闂繘绋嬪彲浠ユ鎷负锛

    1.    鍚姩鍏抽棴杩涚▼

    2.    鏈嶅姟鍣ㄦ牴鎹渶瑕佸垱寤哄叧闂嚎绋

    3.    鏈嶅姟鍣ㄥ仠姝㈡帴鏀舵柊杩炴帴

    4.    鏈嶅姟鍣ㄧ粓姝㈠綋鍓嶇殑娲诲姩

    5.    瀛樺偍寮曟搸琚仠鎺夋垨鍏抽棴

    6.    鏈嶅姟鍣ㄩ鍑

    涓嬮潰鏄洿璇︾粏鐨勬弿杩帮細

    1.    鍚姩鍏抽棴杩涚▼銆

    鍙互鐢ㄥ绉嶆柟娉曞惎鍔ㄦ湇鍔″櫒鐨勫叧闂備緥濡傦紝鎷ユ湁SHUTDOWN鏉冮檺鐨勭敤鎴峰彲浠ユ墽琛mysqladmin shutdown鍛戒护銆mysqladmin鍙互鐢ㄤ簬鎵鏈夋敮鎸MySQL鐨勫钩鍙颁笂銆傚叾瀹冩搷浣滅郴缁熺浉鍏崇殑鍏抽棴寮濮嬫柟娉曡繕鍙兘鏈夛細鍦Unix涓紝褰撴帴鏀跺埌SIGTERM淇″彿鍚庯紝鏈嶅姟鍣ㄥ叧闂傚浜庡湪Windows涓綔涓烘湇鍔¤繍琛岀殑鏈嶅姟鍣紝褰撴湇鍔$鐞嗗櫒璁╁畠鍏抽棴鏃讹紝鍒欏叧闂

    2.    鏈嶅姟鍣ㄦ牴鎹渶瑕佸垱寤哄叧闂嚎绋嬨

    鏍规嵁寮濮嬪叧闂殑鏂瑰紡锛屾湇鍔″櫒鍙互鍒涘缓绾跨▼鏉ュ鐞嗗叧闂繘绋嬨傚鏋滃鎴风闇瑕佸叧闂紝鍒欏垱寤哄叧闂嚎绋嬨傚鏋滄敹鍒SIGTERM淇″彿鍚庡叧闂紝淇″彿绾跨▼鍙互鑷繁鍏抽棴锛屾垨鑰呭垱寤哄崟鐙殑绾跨▼鏉ュ畬鎴愩傚鏋滄湇鍔″櫒灏濊瘯鍒涘缓鍏抽棴绾跨▼鑰屼笉鑳藉垱寤(渚嬪锛屽鏋滃唴瀛樿鑰楀敖)锛屽畠鍦ㄩ敊璇棩蹇椾腑缁欏嚭璇婃柇娑堟伅锛

    Error: Can't create thread to kill server

    3.    鏈嶅姟鍣ㄥ仠姝㈡帴鏀舵柊杩炴帴銆

    鍦ㄥ叧闂繃绋嬩腑瑕佹兂闃叉鍚姩鏂版椿鍔紝鏈嶅姟鍣ㄥ仠姝㈡帴鏀舵柊鐨勫鎴风杩炴帴銆傚畠灏嗗叧闂畠甯у惉鐨勭綉缁滆繛鎺ワ細TCP/IP绔彛銆Unix濂楁帴瀛楁枃浠躲Windows鍛藉悕绠¢亾鍜屽湪Windows涓殑鍏变韩鍐呭瓨銆

    4.    鏈嶅姟鍣ㄧ粓姝㈠綋鍓嶇殑娲诲姩銆

    瀵逛簬姣忎釜涓庡鎴风杩炴帴鐩稿叧鐨勭嚎绋嬶紝涓庡鎴风鐨勮繛鎺ヨ涓柇锛岀嚎绋嬭鏍囪涓衡滄潃鎺夌殑鈥濄傚綋绾跨▼娉ㄦ剰鍒版绫绘爣璁板悗鍒欑嚎绋嬬粓姝€傜┖闂茶繛鎺ョ殑绾跨▼寰堝揩缁堟銆傚綋鍓嶆澶勭悊鏌ヨ鐨勭嚎绋嬪畾鏈熸鏌ュ畠浠殑鐘舵侊紝缁堟鐨勬椂闂磋緝闀裤傚叧浜庣嚎绋嬬粓姝㈢殑璇︾粏淇℃伅锛屽弬瑙13.5.5.3鑺傦紝鈥淜ILL璇硶鈥锛岀壒鍒槸鍏充簬瀵MyISAM琛ㄧ殑鏉鎺夌殑REPAIR TABLEOPTIMIZE TABLE鎿嶄綔銆

    瀵逛簬鏈夋墦寮浜嬪姟鐨勭嚎绋嬶紝浜嬪姟琚洖婊氥傝娉ㄦ剰濡傛灉鏌愪釜绾跨▼姝e湪鏇存柊闈炰簨鍔¤〃锛屽琛UPDATEINSERT绛夋搷浣滀細浣胯〃閮ㄥ垎鏇存柊锛屽洜涓烘搷浣滃湪瀹屾垚鍓嶄細缁堟銆

    濡傛灉鏈嶅姟鍣ㄦ槸涓诲鍒舵湇鍔″櫒锛屼笌褰撳墠杩炴帴鐨勪粠鏈嶅姟鍣ㄧ浉鍏崇殑绾跨▼鐨勫鐞嗘柟寮忓悓鍏跺畠瀹㈡埛绔嚎绋嬨傚嵆姣忎釜绾跨▼琚爣璁颁负鏉鎺夌殑锛屽湪涓嬫妫鏌ヤ粬鐨勭姸鎬佸悗浼氶鍑恒

    濡傛灉鏈嶅姟鍣ㄦ槸浠庡鍒舵湇鍔″櫒锛屽湪瀹㈡埛绔嚎绋嬫爣璁颁负鏉鎺夌殑涔嬪墠锛屾縺娲荤殑I/OSQL绾跨▼琚仠姝€SQL绾跨▼鍏佽鍏堢粨鏉熷畠褰撳墠鐨勮鍙(浠ラ伩鍏嶉犳垚澶嶅埗闂)鐒跺悗鍋滄銆傚鏋滄鏃SQL绾跨▼姝d綅浜庝簨鍔′腑閮紝浜嬪姟鍒 鍥炴粴銆

    5.    瀛樺偍寮曟搸琚仠鎺夋垨鍏抽棴銆

    鍦ㄨ闃舵锛岃〃缂撳瓨琚竻绌猴紝鎵鏈夋墦寮鐨勮〃琚叧闂

    姣忎釜瀛樺偍寮曟搸鎵ц瀹冪鐞嗙殑琛ㄩ渶瑕佺殑浠讳綍鍔ㄤ綔銆備緥濡傦紝MyISAM娓呯┖浠讳綍鎸傝捣鐨勮〃绱㈠紩鍐欐搷浣溿InnoDB灏嗗畠鐨勭紦鍐叉睜娓呯┖鍒扮‖鐩樹笂锛堥櫎闈innodb_fast_shutdown2锛夛紝灏嗗綋鍓嶇殑LSN鍐欏叆琛ㄥ唴锛屽苟缁堟鑷繁鐨勫唴閮ㄧ嚎绋嬨

    6.    鏈嶅姟鍣ㄩ鍑恒

5.6. 涓鑸畨鍏ㄩ棶棰

鏈妭鎻忚堪涓浜涘父瑙佺殑闇瑕佹敞鎰忕殑瀹夊叏闂锛屼互鍙婁竴浜涘彲浠ヤ娇浣犵殑MySQL瀹夎鏇村姞瀹夊叏浠ラ槻姝㈤粦瀹㈠拰璇敤鐨勬帾鏂姐傚叧浜MySQL鐢ㄤ簬璁剧疆鐢ㄦ埛璐︽埛骞舵鏌ユ暟鎹簱璁块棶鐨勮闂帶鍒剁郴缁熺殑鍏蜂綋淇℃伅锛屽弬瑙5.7鑺傦紝鈥淢ySQL璁块棶鏉冮檺绯荤粺鈥

5.6.1. 閫氱敤瀹夊叏鎸囧崡

浠讳綍鍦ㄤ笌Internet鑱旂綉鐨勮绠楁満涓婁娇鐢MySQL鐨勭敤鎴烽兘搴斾粩缁嗛槄璇绘湰鑺傦紝浠ラ伩鍏嶆渶甯歌鐨勫畨鍏ㄩ棶棰樸

璁ㄨ瀹夊叏鏃讹紝鎴戜滑寮鸿皟蹇呴』瀹屽叏淇濇姢鏁翠釜鏈嶅姟鍣ㄤ富鏈虹殑瀹夊叏(鑰屼笉鍙槸MySQL鏈嶅姟鍣)闃茶寖鍚勭绫诲瀷鐨勫彲鑳界殑鏀诲嚮锛氬伔鍚佷慨鏀广侀噸鏀惧拰鎷掔粷鏈嶅姟銆傛垜浠湪杩欓噷涓嶈兘瑕嗙洊鍚勬柟闈㈢殑鍐呭鍜屾帾鏂姐

MySQL鏍规嵁璁块棶鎺у埗鍒楄〃(ACL)瀵规墍鏈夎繛鎺ャ佹煡璇㈠拰鍏跺畠鐢ㄦ埛灏濊瘯鎵ц鐨勬搷浣滆繘琛屽畨鍏ㄧ鐞嗐MySQL瀹㈡埛绔拰鏈嶅姟鍣ㄤ箣闂磋繕鏀寔SSL-鍔犲瘑杩炴帴銆傝繖鍎胯璁虹殑璁稿姒傚康骞朵笉鏄MySQL涓撴湁鐨勶紱璇ユ濇兂鍑犱箮鍚屾牱閫傚悎鎵鏈夊簲鐢ㄧ▼搴忋

杩愯MySQL鏃讹紝搴斿敖閲忛伒浠庝笅闈㈢殑鎸囧锛

         涓嶈璁╀换浣曚汉(闄や簡MySQL root璐︽埛)璁块棶mysql鏁版嵁搴撲腑鐨user琛紒杩欏緢鍏抽敭銆鍔犲瘑鐨勫瘑鐮佹墠鏄MySQL涓殑鐪熸鐨勫瘑鐮併鐭ラ亾user琛ㄤ腑鎵鍒楃殑瀵嗙爜骞朵笖鑳借闂璐︽埛瀹㈣闂殑涓绘満鐨勪汉鍙互寰堝鏄撳湴鐢ㄨ鐢ㄦ埛鐧诲綍

         瀛︿範MySQL璁块棶鏉冮檺绯荤粺銆傜敤GRANTREVOKE璇彞鏉ユ帶鍒跺MySQL鐨勮闂備笉瑕佹巿浜堣秴杩囬渶姹傜殑鏉冮檺銆傚喅涓嶈兘涓烘墍鏈変富鏈烘巿鏉冦

妫鏌ユ竻鍗曪細

o        璇曡瘯mysql -u root銆傚鏋滀綘鑳藉鎴愬姛杩炴帴鏈嶅姟鍣ㄨ屾病鏈夎浠讳綍瀵嗙爜锛屽垯璇存槑鏈夐棶棰樸備换浣曚汉鍙互浣滀负MySQLroot鐢ㄦ埛鐢ㄥ畠鐨勫叏閮ㄦ潈闄愭潵杩炴帴MySQL鏈嶅姟鍣紒鏌ラ槄MySQL瀹夎璇存槑锛屽簲鐗瑰埆娉ㄦ剰鍏充簬璁剧疆root瀵嗙爜鐨勪俊鎭傚弬瑙2.9.3鑺傦紝鈥滀娇鍒濆MySQL璐︽埛瀹夊叏鈥

o        閫氳繃SHOW GRANTS璇彞妫鏌ユ煡鐪嬭皝宸茬粡璁块棶浜嗕粈涔堛傜劧鍚庝娇鐢REVOKE璇彞鍒犻櫎涓嶅啀闇瑕佺殑鏉冮檺銆

         涓嶈灏嗙函鏂囨湰瀵嗙爜淇濆瓨鍒版暟鎹簱涓傚鏋滀綘鐨勮绠楁満鏈夊畨鍏ㄥ嵄闄╋紝鍏ヤ镜鑰呭彲浠ヨ幏寰楁墍鏈夌殑瀵嗙爜骞朵娇鐢ㄥ畠浠傜浉鍙嶏紝搴斾娇鐢MD5()SHA1()鎴栧崟鍚戝搱甯屽嚱鏁般

         涓嶈浠庤瘝鍏镐腑閫夋嫨瀵嗙爜銆傛湁涓撻棬鐨勭▼搴忓彲浠ョ牬瑙e畠浠傚嵆浣胯薄鈥xfish98鈥濊繖鏍风殑瀵嗙爜涔熷緢宸傝屸duag98鈥濊濂藉緱澶氾紝铏界劧鍖呭惈浜嗙浉鍚岀殑瀛椻fish鈥濓紝浣嗕粠鏍囧噯QWERTY閿洏鍚戝乏杈撳叆銆傚彟涓绉嶆柟娉曟槸浣跨敤鈥Mhall鈥濓紝鏉ヨ嚜鍙ュ瓙鈥Mary had a little lamb.鈥濅腑姣忎釜瀛楃殑绗竴涓瓧绗︺傝繖鏍峰緢瀹规槗璁颁綇骞惰緭鍏ワ紝浣嗘槸涓嶇煡閬撶殑浜哄緢闅剧寽鍑烘潵銆

         璐拱闃茬伀澧欍傝繖鏍峰彲浠ヤ繚鎶や綘闃茶寖鍚勭杞欢涓嚦灏50%鐨勫悇绉嶇被鍨嬬殑鏀诲嚮銆傛妸MySQL鏀惧埌闃茬伀澧欏悗鎴栭殧绂诲尯(DMZ)

妫鏌ユ竻鍗曪細

o        璇曡瘯浠Internet浣跨敤nmap宸ュ叿鎵弿绔彛銆MySQL榛樿浣跨敤绔彛3306銆備笉搴斾粠涓嶅彲淇′换涓绘満璁块棶璇ョ鍙c傚彟涓绉嶆鏌ユ槸鍚MySQL绔彛鎵撳紑鐨勭畝鍗曟柟寮忔槸浠庤繙绋嬫満鍣ㄨ瘯璇曚笅闈㈢殑鍛戒护锛屽叾涓server_hostMySQL鏈嶅姟鍣ㄨ繍琛岀殑涓绘満锛

o                     shell> telnet server_host 3306

濡傛灉寰楀埌杩炴帴骞跺緱鍒颁竴浜涘瀮鍦惧瓧绗︼紝鍒欑鍙f墦寮鐫锛屽垯搴斾粠闃茬伀澧欐垨璺敱鍣ㄤ笂鍏抽棴锛岄櫎闈炰綘鏈夊悎鐞嗙殑鐞嗙敱璁╁畠寮鐫銆傚鏋telnet鎸傝捣鎴栬繛鎺ヨ鎷掔粷锛屽垯绔彛琚樆濉烇紝杩欐槸浣犳墍甯屾湜鐨勩

涓嶈淇′换搴旂敤绋嬪簭鐨勭敤鎴疯緭鍏ョ殑浠讳綍鏁版嵁銆傚畠浠彲浠ョ敤Web褰㈠紡銆URL鎴栨瀯寤虹殑搴旂敤绋嬪簭杈撳叆鐗规畩鎴栭冩孩瀛楃搴忓垪鏉ュ皾璇曟楠椾綘鐨勪唬鐮併傚鏋滄煇涓敤鎴疯緭鍏モ; DROP DATABASE mysql;鈥濈瓑鍐呭锛屽簲纭繚浣犵殑搴旂敤绋嬪簭淇濇寔瀹夊叏銆傝繖鏄壒渚嬶紝浣嗗綋榛戝浣跨敤绫讳技鎶鏈椂锛屽鏋滀綘娌℃湁鍋氬ソ鍑嗗锛岀粨鏋滃彲鑳戒細鍑虹幇澶х殑瀹夊叏婕忔礊鍜屾暟鎹涪澶便

涓涓父瑙佺殑閿欒鏄彧淇濇姢瀛楃涓叉暟鎹笺備竴瀹氳璁颁綇杩樺簲妫鏌ユ暟瀛楁暟鎹傚鏋滃綋鐢ㄦ埛杈撳叆鍊234鏃讹紝搴旂敤绋嬪簭鐢熸垚鏌ヨSELECT * FROM table WHERE ID=234鐢ㄦ埛鍙互杈撳叆鍊234 OR 1=1浣垮簲鐢ㄧ▼搴忕敓鎴愭煡璇SELECT * FROM table WHERE ID=234 OR 1=1銆傜粨鏋滄槸鏈嶅姟鍣ㄦ煡鎵捐〃鍐呯殑姣忎釜璁板綍銆傝繖鏍蜂細鏆撮湶姣忎釜璁板綍骞堕犳垚杩囧鐨勬湇鍔″櫒璐熻浇銆備繚鎶ら槻鑼冭繖绫绘敾鍑荤殑鏈绠鍗曠殑鏂规硶鏄娇鐢ㄥ崟寮曞彿灏嗘暟瀛楀父閲忓紩璧锋潵锛SELECT * FROM table WHERE ID='234'銆傚鏋滅敤鎴疯緭鍏ュ叾瀹冧俊鎭紝鍧囧彉涓哄瓧绗︿覆鐨勪竴閮ㄥ垎銆傚湪鏁板瓧閮ㄥ垎锛MySQL鑷姩灏嗗瓧绗︿覆杞崲涓烘暟瀛楀苟鍓ョ瀛楃涓插寘鍚殑闄勫姞鐨勯潪鏁板瓧瀛楃銆

鏈夋椂鍊欎汉浠細璁や负濡傛灉鏁版嵁搴撳彧鍖呭惈渚涘叕鍏变娇鐢ㄧ殑鏁版嵁锛屽垯涓嶉渶瑕佷繚鎶ゃ傝繖鏄笉姝g‘鐨勩傚嵆浣垮厑璁告樉绀烘暟鎹簱涓殑浠讳綍璁板綍锛屼綘浠嶇劧搴斾繚鎶ら槻鑼冩嫆缁濇湇鍔℃敾鍑(渚嬪锛屽熀浜庡墠闈㈡钀戒腑鎵杩扮殑鎶鏈殑鏀诲嚮锛屼細浣挎湇鍔″櫒娴垂璧勬簮)銆傚惁鍒欙紝浣犵殑鏈嶅姟鍣ㄤ笉鍐嶅搷搴斿悎娉曠敤鎴枫

妫鏌ユ竻鍗曪細

o        璇曡瘯鐢Web褰㈠紡杈撳叆鍗曞紩鍙峰拰鍙屽紩鍙('鈥欏拰鈥")銆傚鏋滃緱鍒颁换浣曞舰寮忕殑MySQL閿欒锛岀珛鍗冲垎鏋愬師鍥犮

o        璇曡瘯淇敼鍔ㄦURL锛屽彲浠ュ湪鍏朵腑娣诲姞%22(")%23(#)%27(')

o        璇曡瘯鍦ㄥ姩鎬URL涓慨鏀规暟鎹被鍨嬶紝浣跨敤鍓嶉潰绀轰緥涓殑瀛楃锛屽寘鎷暟瀛楀拰瀛楃绫诲瀷銆備綘鐨勫簲鐢ㄧ▼搴忓簲瓒冲瀹夊叏锛屽彲浠ラ槻鑼冩绫讳慨鏀瑰拰绫讳技鏀诲嚮銆

o        璇曡瘯杈撳叆瀛楃銆佺┖鏍煎拰鐗规畩绗﹀彿锛屼笉瑕佽緭鍏ユ暟鍊煎瓧娈电殑鏁板瓧銆備綘鐨勫簲鐢ㄧ▼搴忓簲鍦ㄥ皢瀹冧滑浼犻掑埌MySQL涔嬪墠灏嗗畠浠垹闄ゆ垨鐢熸垚閿欒銆傚皢鏈粡杩囨鏌ョ殑鍊间紶閫掔粰MySQL鏄緢鍗遍櫓鐨勶紒

o        灏嗘暟鎹紶缁MySQL涔嬪墠鍏堟鏌ュ叾澶у皬銆

o        鐢ㄧ鐞嗚处鎴蜂箣澶栫殑鐢ㄦ埛鍚嶅皢搴旂敤绋嬪簭杩炴帴鍒版暟鎹簱銆備笉瑕佺粰搴旂敤绋嬪簭浠讳綍涓嶉渶瑕佺殑璁块棶鏉冮檺銆

         璁稿搴旂敤绋嬪簭缂栫▼鎺ュ彛鎻愪緵浜嗘帾鏂介冮告暟鎹间腑鐨勭壒娈婂瓧绗︺傚鏋滀娇鐢ㄦ纭紝鍙互闃叉搴旂敤绋嬪簭鐢ㄦ埛杈撳叆浣垮簲鐢ㄧ▼搴忕敓鎴愪笉鏈熸湜鐨勬晥鏋滅殑璇彞鐨勬暟鍊硷細

o        MySQL C API锛氫娇鐢mysql_real_escape_string() API璋冪敤銆

o        MySQL++锛氭煡璇㈡祦浣跨敤escapequote淇绗︺

o        PHP锛氫娇鐢mysql_escape_string()鍑芥暟鍩轰簬MySQL C API涓殑鍚屽悕鍑芥暟銆(PHP 4.0.3涔嬪墠,浣跨敤addslashes()PHP 5,鍙互浣跨敤mysqli鎵╁睍鍚嶏紝瀹冩敮鎸佹敼杩涚殑MySQL閴村畾鍗忚鍜屽瘑鐮侊紝浠ュ強鐢ㄥ崰浣嶇缂栧啓鐨勮鍙ャ

o        Perl DBI锛氫娇鐢quote()鏂规硶鎴栦娇鐢ㄥ崰浣嶇銆

o        Java JDBC锛氫娇鐢ㄤ竴涓PreparedStatement瀵硅薄鍜屽崰浣嶇銆

鍏跺畠缂栫▼鎺ュ彛鏈夌被浼肩殑鍔熻兘銆

         涓嶈閫氳繃Internet浼犻佹槑鏂(鏈姞瀵嗙殑)鏁版嵁銆傝淇℃伅鍙互琚湁瓒冲鏃堕棿鍜岃兘鍔涙潵鎴彇瀹冨苟鐢ㄤ簬涓汉鐩殑鐨勪换浣曚汉璁块棶銆傜浉鍙嶏紝搴斾娇鐢ㄥ姞瀵嗗崗璁紝渚嬪SSLSSHMySQL鏀寔鍐呴儴SSL杩炴帴锛屼緥濡傜増鏈 4.0.0銆傚彲浠ヤ娇鐢SSH绔彛鏄犲皠涓洪氫俊鍒涘缓鍔犲瘑(骞跺帇缂)鐨勯毀閬撱

         瀛︿細浣跨敤tcpdumpstrings宸ュ叿銆傚湪澶у鏁版儏鍐典笅锛屼綘鍙互浣跨敤涓嬮潰鐨勫懡浠ゆ鏌ユ槸鍚MySQL鏁版嵁娴佹湭鍔犲瘑锛

                shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings

(璇ュ懡浠ゅ湪Linux涓彲浠ュ伐浣滐紝鍦ㄥ叾瀹冪郴缁熶腑缁忚繃灏忓皬鐨勪慨鏀瑰悗搴斿彲浠ュ伐浣滐級璀﹀憡锛氬鏋滀綘娌℃湁鐪嬭鏄庢枃鏁版嵁锛屽苟涓嶄竴瀹氳鏄庝俊鎭疄闄呬笂琚姞瀵嗕簡銆傚鏋滀綘闇瑕佽緝楂樼骇鍒殑瀹夊叏锛屼綘搴斿挩璇㈠畨鍏ㄤ笓瀹躲

5.6.2. 浣縈ySQL鍦ㄦ敾鍑昏呴潰鍓嶄繚鎸佸畨鍏

褰撲綘杩炴帴鍒MySQL鏈嶅姟鍣ㄦ椂锛屼綘搴斾娇鐢ㄤ竴涓瘑鐮併傚瘑鐮佷笉浠ユ槑鏂囧湪涓婁紶杈撱傚鎴风杩炴帴搴忓垪涓殑瀵嗙爜澶勭悊鍦MySQL 4.1.1涓凡缁忓崌绾э紝寰堝畨鍏ㄣ傚鏋滀綘浠嶇劧浣跨敤pre-4.1.1-椋庢牸鐨勫瘑鐮侊紝鍔犲瘑绠楁硶涓嶅鏂扮畻娉曞己锛涢氳繃涓浜涘伐浣滐紝鍙互绐冨彇瀹㈡埛绔拰鏈嶅姟鍣ㄤ箣闂寸殑閫氫俊鐨勮仾鏄庣殑鏀诲嚮鑰呭彲浠ョ牬瑙e瘑鐮併(鍏充簬涓嶅悓鐨勫瘑鐮佸鐞嗘柟娉曠殑璁ㄨ鍙傝5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥 濡傛灉瀹㈡埛绔拰鏈嶅姟鍣ㄤ箣闂寸殑杩炴帴閫氳繃涓嶅彲淇′换缃戠粶锛屼綘搴斾娇鐢SSH闅ч亾鏉ュ姞瀵嗛氫俊銆

鎵鏈夊叾瀹冧俊鎭互鏂囨湰浼犻侊紝鍙互琚彲浠ョ湅鍒拌繛鎺ョ殑浠讳綍浜鸿鍙栥傚鏋滀綘鎷呭績杩欎釜锛屼綘鍙互浣跨敤鍘嬬缉鍗忚鏉ヤ娇閫氫俊鏇撮毦浠ヨВ瀵嗐傝鎯充娇杩炴帴鏇村姞瀹夊叏锛屼綘搴斾娇鐢SSH鏉ヨ幏寰楀姞瀵嗙殑MySQL鏈嶅姟鍣ㄥ拰MySQL瀹㈡埛绔箣闂寸殑TCP/IP杩炴帴銆備綘鍙互浠http://www.openssh.org/鎵惧埌寮鏀炬簮鐮SSH 瀹㈡埛绔紝骞跺彲浠ヤ粠http://www.ssh.com/鑾峰緱鍟嗕笟SSH瀹㈡埛绔

浣犺繕鍙互浣跨敤MySQL鍐呴儴OpenSSL鏀寔銆傚弬瑙5.8.7鑺傦紝鈥滀娇鐢ㄥ畨鍏ㄨ繛鎺モ

涓轰簡浣MySQL绯荤粺瀹夊叏锛屽己鐑堣姹備綘鑰冭檻涓嬪垪寤鸿锛

         瀵规墍鏈MySQL鐢ㄦ埛浣跨敤瀵嗙爜銆傚鎴风绋嬪簭涓嶉渶瑕佺煡閬撹繍琛屽畠鐨勪汉鍛樼殑韬唤銆傚浜庡鎴风/鏈嶅姟鍣ㄥ簲鐢ㄧ▼搴忥紝鐢ㄦ埛鍙互鎸囧畾瀹㈡埛绔▼搴忕殑鐢ㄦ埛鍚嶃備緥濡傦紝濡傛灉other_user娌℃湁瀵嗙爜锛屼换浣曚汉鍙互绠鍗曞湴鐢mysql -u other_user db_name鍐掑厖浠栦汉璋冪敤mysql绋嬪簭杩涜杩炴帴銆傚鏋滄墍鏈夌敤鎴锋湁瀵嗙爜锛屼娇鐢ㄥ叾瀹冪敤鎴风殑璐︽埛杩涜杩炴帴瑕佸洶闅惧緱澶氥

瑕佹兂鏇存敼鐢ㄦ埛鐨勫瘑鐮侊紝搴斾娇鐢SET PASSWORD璇彞銆傝繕鍙互鐩存帴鏇存柊mysql鏁版嵁搴撲腑鐨user琛ㄣ備緥濡傦紝瑕佹洿鏀规墍鏈root鐢ㄦ埛鐨MySQL璐︽埛鐨勫瘑鐮侊紝搴旓細

shell> mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd')
    -> WHERE User='root';
mysql> FLUSH PRIVILEGES;

         缁濆涓嶈浣滀负Unixroot鐢ㄦ埛杩愯MySQL鏈嶅姟鍣ㄣ傝繖鏍峰仛闈炲父鍗遍櫓锛屽洜涓轰换浣曞叿鏈FILE鏉冮檺鐨勭敤鎴疯兘澶熺敤root鍒涘缓鏂囦欢(渚嬪锛~root/.bashrc)銆備负浜嗛槻姝紝mysqld鎷掔粷鐢root杩愯锛岄櫎闈炰娇鐢--user=root閫夐」鏄庢樉鎸囧畾銆

搴斿彲浠(骞朵笖搴旇)鐢ㄦ櫘閫氶潪鐗规潈鐢ㄦ埛杩愯mysqld銆備綘鍙互鍒涘缓鐙珛鐨Unix涓殑mysql璐︽埛鏉ヤ互渚夸娇鎵鏈夊唴瀹规洿鍔犲畨鍏ㄣ傝璐︽埛鍙敤浜庣鐞MySQL銆傝鎯崇敤鍏跺畠Unix鐢ㄦ埛鍚姩mysqld锛屽鍔user閫夐」鎸囧畾/etc/my.cnf閫夐」鏂囦欢鎴栨湇鍔″櫒鏁版嵁鐩綍鐨my.cnf閫夐」鏂囦欢涓殑[mysqld]缁勭殑鐢ㄦ埛鍚嶃備緥濡傦細

[mysqld]
user=mysql

璇ュ懡浠や娇鏈嶅姟鍣ㄧ敤鎸囧畾鐨勭敤鎴锋潵鍚姩锛屾棤璁轰綘鎵嬪姩鍚姩鎴栭氳繃mysqld_safemysql.server鍚姩銆傝缁嗕俊鎭弬瑙A.3.2鑺傦紝鈥滃浣曚互鏅氱敤鎴疯韩浠借繍琛孧ySQL鈥

浣滀负鍏跺畠Unix鐢ㄦ埛鑰屼笉鐢root杩愯mysqld锛屼綘涓嶉渶瑕佹洿鏀user琛ㄤ腑鐨root鐢ㄦ埛鍚嶏紝鍥犱负MySQL璐︽埛鐨勭敤鎴峰悕涓Unix璐︽埛鐨勭敤鎴峰悕鏃犲叧銆

         涓嶈鍏佽浣跨敤琛ㄧ殑绗﹀彿閾炬帴銆(鍙互鐢--skip-symbolic-links閫夐」绂佺敤锛濡傛灉浣犵敤root杩愯mysqld鍒欑壒鍒噸瑕侊紝鍥犱负浠讳綍瀵规湇鍔″櫒鐨勬暟鎹洰褰曟湁鍐欒闂潈闄愮殑浜哄垯鑳藉鍒犻櫎绯荤粺涓殑浠讳綍鏂囦欢锛佸弬瑙7.6.1.2鑺傦紝鈥滃湪Unix骞冲彴涓婁娇鐢ㄨ〃鐨勭鍙烽摼鎺鈥濄

         纭繚mysqld杩愯鏃讹紝鍙娇鐢ㄥ鏁版嵁搴撶洰褰曞叿鏈夎鎴栧啓鏉冮檺鐨Unix鐢ㄦ埛鏉ヨ繍琛屻

         涓嶈灏PROCESSSUPER鏉冮檺鎺堢粰闈炵鐞嗙敤鎴枫mysqladmin processlist鐨勮緭鍑烘樉绀哄嚭褰撳墠鎵ц鐨勬煡璇㈡鏂囷紝濡傛灉鍙﹀鐨勭敤鎴峰彂鍑轰竴涓UPDATE user SET password=PASSWORD('not_secure')鏌ヨ锛岃鍏佽鎵ц閭d釜鍛戒护鐨勪换浣曠敤鎴峰彲鑳界湅寰楀埌銆

mysqld涓烘湁SUPER鏉冮檺鐨勭敤鎴蜂笓闂ㄤ繚鐣欎竴涓澶栫殑杩炴帴锛屽洜姝ゅ嵆浣挎墍鏈夋櫘閫氳繛鎺ヨ鍗犵敤锛MySQL root鐢ㄦ埛浠嶅彲浠ョ櫥褰曞苟妫鏌ユ湇鍔″櫒鐨勬椿鍔ㄣ

鍙互浣跨敤SUPER鏉冮檺鏉ョ粓姝㈠鎴风杩炴帴锛岄氳繃鏇存敼绯荤粺鍙橀噺鐨勫兼洿鏀规湇鍔$殑鍣ㄦ搷浣滐紝骞舵帶鍒跺鍒舵湇鍔″櫒銆

         涓嶈鍚戦潪绠$悊鐢ㄦ埛鎺堜簣FILE鏉冮檺銆傛湁杩欐潈闄愮殑浠讳綍鐢ㄦ埛鑳藉湪鎷ユ湁mysqld瀹堟姢杩涚▼鏉冮檺鐨勬枃浠剁郴缁熼偅閲屽啓涓涓枃浠讹紒涓轰簡鏇村姞瀹夊叏锛岀敱SELECT ... INTO OUTFILE鐢熸垚鐨勬墍鏈夋枃浠跺姣忎釜浜烘槸鍙啓鐨勶紝骞朵笖浣犱笉鑳借鐩栧凡缁忓瓨鍦ㄧ殑鏂囦欢銆

file鏉冮檺涔熷彲浠ヨ鐢ㄦ潵璇诲彇浠讳綍浣滀负杩愯鏈嶅姟鍣ㄧ殑Unix鐢ㄦ埛鍙鍙栨垨璁块棶鐨勬枃浠躲備娇鐢ㄨ鏉冮檺锛屼綘鍙互灏嗕换浣曟枃浠惰鍏ユ暟鎹簱琛ㄣ傝繖鍙兘琚互鐢紝渚嬪锛岄氳繃浣跨敤LOAD DATA瑁呰浇/etc/passwd杩涗竴涓暟鎹簱琛紝鐒跺悗鑳界敤SELECT鏄剧ず瀹

         濡傛灉浣犱笉淇′换浣犵殑DNS锛屼綘搴旇鍦ㄦ巿鏉冭〃涓娇鐢IP鏁板瓧鑰屼笉鏄富鏈哄悕銆傚湪浠讳綍鎯呭喌涓嬶紝浣犲簲璇ラ潪甯稿皬蹇冨湴浣跨敤鍖呭惈閫氶厤绗︾殑涓绘満鍚嶆潵鍒涘缓 鎺堟潈琛ㄦ潯鐩紒

         濡傛灉浣犳兂瑕侀檺鍒跺崟涓处鎴峰厑璁哥殑杩炴帴鏁伴噺锛屼綘鍙互璁剧疆mysqld涓殑max_user_connections鍙橀噺鏉ュ畬鎴愩GRANT璇彞涔熷彲浠ユ敮鎸 璧勬簮鎺у埗閫夐」鏉ラ檺鍒舵湇鍔″櫒瀵逛竴涓处鎴峰厑璁哥殑浣跨敤鑼冨洿銆傚弬瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥

5.6.3. Mysqld瀹夊叏鐩稿叧鍚姩閫夐」

涓嬪垪mysqld閫夐」褰卞搷瀹夊叏锛

         --allow-suspicious-udfs

璇ラ夐」鎺у埗鏄惁鍙互杞藉叆涓诲嚱鏁板彧鏈xxx绗︾殑鐢ㄦ埛瀹氫箟鍑芥暟銆傞粯璁ゆ儏鍐典笅锛岃閫夐」琚叧闂紝骞朵笖鍙兘杞藉叆鑷冲皯鏈夎緟鍔╃鐨UDF銆傝繖鏍峰彲浠ラ槻姝粠鏈寘鍚悎娉UDF鐨勫叡浜璞℃枃浠惰浇鍏ュ嚱鏁般傚弬瑙27.2.3.6鑺傦紝鈥滅敤鎴峰畾涔夊嚱鏁板畨鍏ㄦ敞鎰忎簨椤光

         --local-infile[={0|1}]

濡傛灉鐢--local-infile=0鍚姩鏈嶅姟鍣鍒欏鎴风涓嶈兘浣跨敤LOCAL in LOAD DATA璇彞銆傚弬瑙5.6.4鑺傦紝鈥淟OAD DATA LOCAL瀹夊叏闂

         --old-passwords

寮哄埗鏈嶅姟鍣ㄤ负鏂板瘑鐮佺敓鎴愮煭(pre-4.1)瀵嗙爜鍝堝笇銆傚綋鏈嶅姟鍣ㄥ繀椤绘敮鎸佹棫鐗堟湰瀹㈡埛绔▼搴忔椂锛屼负浜嗕繚璇佸吋瀹规ц繖寰堟湁鐢ㄣ傚弬瑙5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥

         (OBSOLETE) --safe-show-database

鍦ㄤ互鍓嶇増鏈殑MySQL涓紝璇ラ夐」浣SHOW DATABASES璇彞鍙樉绀虹敤鎴峰叿鏈夐儴鍒嗘潈闄愮殑鏁版嵁搴撳悕銆傚湪MySQL 5.1涓紝璇ラ夐」涓嶅啀浣滀负鐜板湪鐨 榛樿琛屼负浣跨敤锛屾湁涓涓SHOW DATABASES鏉冮檺鍙互鐢ㄦ潵鎺у埗姣忎釜璐︽埛瀵规暟鎹簱鍚嶇殑璁块棶銆傚弬瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥

         --safe-user-create

濡傛灉鍚敤锛岀敤鎴蜂笉鑳界敤GRANT璇彞鍒涘缓鏂扮敤鎴凤紝闄ら潪鐢ㄦ埛鏈mysql.user琛ㄧ殑INSERT鏉冮檺銆傚鏋滀綘鎯宠鐢ㄦ埛鍏锋湁鎺堟潈鏉冮檺鏉ュ垱寤烘柊鐢ㄦ埛锛屼綘搴旂粰鐢ㄦ埛鎺堜簣涓嬮潰鐨勬潈闄愶細

mysql> GRANT INSERT(user) ON mysql.user TO 'user_name'@'host_name';

杩欐牱纭繚鐢ㄦ埛涓嶈兘鐩存帴鏇存敼鏉冮檺鍒楋紝蹇呴』浣跨敤GRANT璇彞缁欏叾瀹冪敤鎴锋巿浜堣鏉冮檺銆

         --secure-auth

涓嶅厑璁搁壌瀹氭湁鏃(pre-4.1)瀵嗙爜鐨勮处鎴枫

         --skip-grant-tables

杩欎釜閫夐」瀵艰嚧鏈嶅姟鍣ㄦ牴鏈笉浣跨敤鏉冮檺绯荤粺銆傝繖缁欐瘡涓汉浠瀹屽叏璁块棶鎵鏈夌殑鏁版嵁搴撶殑鏉冨姏锛侊紙閫氳繃鎵цmysqladmin flush-privilegesmysqladmin reload鍛戒护锛屾垨鎵цFLUSH PRIVILEGES璇彞锛屼綘鑳藉憡璇変竴涓鍦ㄨ繍琛岀殑鏈嶅姟鍣ㄥ啀娆″紑濮嬩娇鐢ㄦ巿鏉冭〃銆傦級  

         --skip-name-resolve

涓绘満鍚嶄笉琚В鏋愩傛墍鏈夊湪鎺堟潈琛ㄧ殑Host鐨勫垪鍊煎繀椤绘槸IP鍙锋垨localhost

         --skip-networking

鍦ㄧ綉缁滀笂涓嶅厑璁TCP/IP杩炴帴銆傛墍鏈夊埌mysqld鐨勮繛鎺ュ繀椤荤粡鐢Unix濂楁帴瀛楄繘琛屻

         --skip-show-database

浣跨敤璇ラ夐」锛屽彧鍏佽鏈SHOW DATABASES鏉冮檺鐨勭敤鎴锋墽琛SHOW DATABASES璇彞锛岃璇彞鏄剧ず鎵鏈夋暟鎹簱鍚嶃備笉浣跨敤璇ラ夐」锛屽厑璁告墍鏈夌敤鎴锋墽琛SHOW DATABASES锛屼絾鍙樉绀虹敤鎴锋湁SHOW DATABASES鏉冮檺鎴栭儴鍒嗘暟鎹簱鏉冮檺鐨勬暟鎹簱鍚嶃傝娉ㄦ剰鍏ㄥ眬鏉冮檺鎸囨暟鎹簱鐨勬潈闄愩

5.6.4. LOAD DATA LOCAL瀹夊叏闂

LOAD DATA璇彞鍙互瑁呰浇鏈嶅姟鍣ㄤ富鏈轰笂鐨勬枃浠讹紝鑻ユ寚瀹LOCAL鍏抽敭瀛楋紝鍙互瑁呰浇瀹㈡埛绔枃浠躲

鏀寔LOCAL鐗堟湰鐨LOAD DATA璇彞鏈変袱涓彲鑳界殑瀹夊叏闂锛

         MySQL鏈嶅姟鍣ㄥ惎鍔ㄦ枃浠朵粠瀹㈡埛绔悜鏈嶅姟鍣ㄤ富鏈虹殑浼犺緭銆傜悊璁轰笂锛屾墦杩囪ˉ涓佺殑鏈嶅姟鍣ㄥ彲浠ュ憡璇夊鎴风绋嬪簭浼犺緭鏈嶅姟鍣ㄩ夋嫨鐨勬枃浠讹紝鑰屼笉鏄鎴风敤LOAD DATA璇彞鎸囧畾鐨勬枃浠躲傝繖鏍锋湇鍔″櫒鍙互璁块棶瀹㈡埛绔笂瀹㈡埛鏈夎璁块棶鏉冮檺鐨勪换浣曟枃浠躲

         Web鐜涓紝瀹㈡埛浠Web鏈嶅姟鍣ㄨ繛鎺ワ紝鐢ㄦ埛鍙互浣跨敤LOAD DATA LOCAL鏉ヨ鍙Web鏈嶅姟鍣ㄨ繘绋嬫湁璇昏闂潈闄愮殑浠讳綍鏂囦欢(鍋囧畾鐢ㄦ埛鍙互杩愯SQL鏈嶅姟鍣ㄧ殑浠讳綍鍛戒护)銆傚湪杩欑鐜涓紝MySQL鏈嶅姟鍣ㄧ殑瀹㈡埛瀹為檯涓婃槸Web鏈嶅姟鍣紝鑰屼笉鏄繛鎺Web鏈嶅姟鍣ㄧ殑鐢ㄦ埛杩愯鐨勭▼搴忋

瑕佸鐞嗚繖浜涢棶棰橈紝鎴戜滑鏇存敼浜MySQL 3.23.49MySQL 4.0.2(Windows涓殑4.0.13)涓殑LOAD DATA LOCAL鐨勫鐞嗘柟娉曪細

         榛樿鎯呭喌涓嬶紝鐜板湪鎵鏈変簩杩涘埗鍒嗕腑鐨勫彂MySQL瀹㈡埛绔拰搴撴槸鐢--enable-local-infile閫夐」缂栬瘧锛屼互渚夸笌MySQL 3.23.48鍜屼互鍓嶇殑鐗堟湰鍏煎銆

         濡傛灉浣犱粠婧愮爜鏋勫缓MySQL浣嗘病鏈変娇鐢--enable-local-infile閫夐」鏉ヨ繘琛configure锛屽垯瀹㈡埛涓嶈兘浣跨敤LOAD DATA LOCAL锛岄櫎闈炴樉寮忚皟鐢mysql_options (...MYSQL_OPT_鏈湴_INFILE0)銆傚弬瑙25.2.3.48鑺傦紝鈥渕ysql_options()鈥

         浣犲彲浠ョ敤--local-infile=0閫夐」鍚姩mysqld浠庢湇鍔″櫒绔鐢ㄦ墍鏈LOAD DATA LOCAL鍛戒护銆

         瀵逛簬mysql鍛戒护琛屽鎴风锛屽彲浠ラ氳繃鎸囧畾--local-infile[=1]閫夐」鍚敤LOAD DATA LOCAL锛屾垨閫氳繃--local-infile=0閫夐」绂佺敤銆傜被浼煎湴锛屽浜mysqlimport--local or -L閫夐」鍚敤鏈湴鏁版嵁鏂囦欢瑁呰浇銆傚湪浠讳綍鎯呭喌涓嬶紝鎴愬姛杩涜鏈湴瑁呰浇闇瑕佹湇鍔″櫒鍚敤鐩稿叧閫夐」銆

         濡傛灉浣犱娇鐢LOAD DATA LOCAL Perl鑴氭湰鎴栧叾瀹冭閫夐」鏂囦欢涓殑[client]缁勭殑绋嬪簭锛屼綘鍙互鍦ㄧ粍鍐呮坊鍔local-infile=1閫夐」銆備絾鏄紝涓轰簡渚块潰涓嶇悊瑙local-infile鐨勭▼搴忎骇鐢熼棶棰橈紝鍒欒瀹氫娇鐢loose- prefix

                [client]
                loose-local-infile=1

         濡傛灉LOAD DATA LOCAL INFILE鍦ㄦ湇鍔″櫒鎴栧鎴风琚鐢紝璇曞浘鎵ц璇ヨ鍙ョ殑瀹㈡埛绔皢鏀跺埌涓嬮潰鐨勯敊璇秷鎭細

ERROR 1148: The used command is not allowed with this MySQL version

5.7. MySQL璁块棶鏉冮檺绯荤粺

MySQL鏈夊厛杩涗絾闈炴爣鍑嗙殑瀹夊叏/鏉冮檺绯荤粺銆傛湰鑺傛弿杩板畠鐨勫伐浣滃師鐞嗐

5.7.1. 鏉冮檺绯荤粺鐨勪綔鐢

MySQL鏉冮檺绯荤粺鐨勪富瑕佸姛鑳芥槸璇佸疄杩炴帴鍒颁竴鍙扮粰瀹氫富鏈虹殑鐢ㄦ埛锛屽苟涓旇祴浜堣鐢ㄦ埛鍦ㄦ暟鎹簱涓婄殑SELECTINSERTUPDATEDELETE鏉冮檺銆

闄勫姞鐨勫姛鑳藉寘鎷湁鍖垮悕鐨勭敤鎴峰苟瀵逛簬MySQL鐗瑰畾鐨勫姛鑳戒緥濡LOAD DATA INFILE杩涜鎺堟潈鍙婄鐞嗘搷浣滅殑鑳藉姏銆

5.7.2. 鏉冮檺绯荤粺宸ヤ綔鍘熺悊

MySQL鏉冮檺绯荤粺淇濊瘉鎵鏈夌殑鐢ㄦ埛鍙墽琛屽厑璁稿仛鐨勪簨鎯呫傚綋浣犺繛鎺MySQL鏈嶅姟鍣ㄦ椂锛屼綘鐨勮韩浠界敱浣犱粠閭e効杩炴帴鐨勪富鏈浣犳寚瀹氱殑鐢ㄦ埛鍚鏉ュ喅瀹氥傝繛鎺ュ悗鍙戝嚭璇锋眰鍚庯紝绯荤粺鏍规嵁浣犵殑韬唤鍜浣犳兂鍋氫粈涔鏉ユ巿浜堟潈闄愩

MySQL鍦ㄨ瀹氳韩浠戒腑鑰冭檻浣犵殑涓绘満鍚嶅拰鐢ㄦ埛鍚嶅瓧锛屾槸鍥犱负鍑犱箮娌℃湁鍘熷洜鍋囧畾涓涓粰瀹氱殑鐢ㄦ埛鍦ㄥ洜鐗圭綉涓婂睘浜庡悓涓涓汉銆備緥濡傦紝浠office.com杩炴帴鐨勭敤鎴joe涓嶄竴瀹氬拰浠elsewhere.com杩炴帴鐨joe鏄悓涓涓汉銆MySQL閫氳繃鍏佽浣犲尯鍒嗗湪涓嶅悓鐨勪富鏈轰笂纰板阀鏈夊悓鏍峰悕瀛楃殑鐢ㄦ埛鏉ュ鐞嗗畠锛氫綘鍙互瀵joeoffice.com杩涜鐨勮繛鎺ユ巿涓庝竴涓潈闄愰泦锛岃屼负joeelsewhere.com鐨勮繛鎺ユ巿浜堜竴涓笉鍚岀殑鏉冮檺闆嗐

MySQL瀛樺彇鎺у埗鍖呭惈2涓樁娈碉細

  • 闃舵1锛氭湇鍔″櫒妫鏌ユ槸鍚﹀厑璁镐綘杩炴帴銆
  • 闃舵2锛氬亣瀹氫綘鑳借繛鎺ワ紝鏈嶅姟鍣ㄦ鏌ヤ綘鍙戝嚭鐨勬瘡涓姹傘傜湅浣犳槸鍚︽湁瓒冲鐨勬潈闄愬疄鏂藉畠銆備緥濡傦紝濡傛灉浣犱粠鏁版嵁搴撹〃涓夋嫨(select)琛屾垨浠庢暟鎹簱鍒犻櫎琛紝鏈嶅姟鍣ㄧ‘瀹氫綘瀵硅〃鏈SELECT鏉冮檺鎴栧鏁版嵁搴撴湁DROP鏉冮檺銆

濡傛灉杩炴帴鏃朵綘鐨勬潈闄愯鏇存敼浜(閫氳繃浣犲拰鍏跺畠浜)锛岃繖浜涙洿鏀逛笉涓瀹氱珛鍗冲浣犲彂鍑虹殑涓嬩竴涓鍙ョ敓鏁堛傝鎯呭弬瑙5.7.7鑺傦紝鈥滄潈闄愭洿鏀逛綍鏃剁敓鏁堚

鏈嶅姟鍣ㄥ湪mysql鏁版嵁搴撶殑 鎺堟潈琛ㄤ腑淇濆瓨鏉冮檺淇℃伅(鍗冲湪mysql鏁版嵁搴撲腑)銆傚綋MySQL鏈嶅姟鍣ㄥ惎鍔ㄦ椂灏嗚繖浜涜〃鐨勫唴瀹硅鍏ュ唴瀛橈紝鍦5.7.7鑺傦紝鈥滄潈闄愭洿鏀逛綍鏃剁敓鏁堚鐨勭幆澧冧笅閲嶆柊璇诲彇瀹冧滑銆傝闂帶鍒跺喅绛栧彇鍐充簬鍐呭瓨涓殑 鎺堟潈琛ㄧ殑浠芥暟銆

涓鑸儏鍐碉紝浣犻氳繃GRANTREVOKE璇彞闂存帴鏉ユ搷浣 鎺堟潈琛ㄧ殑鍐呭锛岃缃处鎴峰苟鎺у埗涓汉鐨勬潈闄愩傚弬瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥銆備笅闈㈣璁轰簡 鎺堟潈琛ㄧ殑缁撴瀯浠ュ強鏈嶅姟鍣ㄤ笌瀹㈡埛绔氦浜掓搷浣滄椂濡備綍浣跨敤鍏跺唴瀹广

鏈嶅姟鍣ㄥ湪瀛樺彇鎺у埗鐨勪袱涓樁娈典娇鐢mysql鏁版嵁搴撲腑鐨userdbhost琛紝杩欎簺鎺堟潈琛ㄤ腑鐨勫垪濡備笅锛

琛ㄥ悕

user

db

host

鍒楄寖鍥

Host

Host

Host

 

User

Db

Db

 

Password

User

 

鏉冮檺鍒

Select_priv

Select_priv

Select_priv

 

Insert_priv

Insert_priv

Insert_priv

 

Update_priv

Update_priv

Update_priv

 

Delete_priv

Delete_priv

Delete_priv

 

Index_priv

Index_priv

Index_priv

 

Alter_priv

Alter_priv

Alter_priv

 

Create_priv

Create_priv

Create_priv

 

Drop_priv

Drop_priv

Drop_priv

 

Grant_priv

Grant_priv

Grant_priv

 

Create_view_priv

Create_view_priv

Create_view_priv

 

Show_view_priv

Show_view_priv

Show_view_priv

 

Create_routine_priv

Create_routine_priv

 

 

Alter_routine_priv

Alter_routine_priv

 

 

References_priv

References_priv

References_priv

 

Reload_priv

 

 

 

Shutdown_priv

 

 

 

Process_priv

 

 

 

File_priv

 

 

 

Show_db_priv

 

 

 

Super_priv

 

 

 

Create_tmp_table_priv

Create_tmp_table_priv

Create_tmp_table_priv

 

Lock_tables_priv

Lock_tables_priv

Lock_tables_priv

 

Execute_priv

 

 

 

Repl_slave_priv

 

 

 

Repl_client_priv

 

 

瀹夊叏鍒

ssl_type

 

 

 

ssl_cipher

 

 

 

x509_issuer

 

 

 

x509_subject

 

 

璧勬簮鎺у埗鍒

max_questions

 

 

 

max_updates

 

 

 

max_connections

 

 

 

max_user_connections

 

 

瀵瑰瓨鍙栨帶鍒剁殑绗簩闃舵(璇锋眰璇佸疄)锛屾湇鍔″櫒鎵ц璇锋眰楠岃瘉浠ョ‘淇濇瘡涓鎴风鏈夊厖鍒嗙殑鏉冮檺婊¤冻鍚勯渶姹傘傞櫎浜userdbhost鎺堟潈琛紝濡傛灉璇锋眰娑夊強琛紝鏈嶅姟鍣ㄥ彲浠ュ彟澶栧弬鑰tables_privcolumns_priv琛ㄣtables_privcolumns_priv琛ㄥ彲浠ュ琛ㄥ拰鍒楁彁渚涙洿绮剧‘鐨勬潈闄愭帶鍒躲傝繖浜涜〃鐨勫垪濡備笅锛

琛ㄥ悕

tables_priv

columns_priv

鑼冨洿鍒

Host

Host

 

Db

Db

 

User

User

 

Table_name

Table_name

 

 

Column_name

鏉冮檺鍒

Table_priv

Column_priv

 

Column_priv

 

鍏跺畠鍒

Timestamp

Timestamp

 

Grantor

 

TimestampGrantor鍒楀綋鍓嶈繕鏈娇鐢紝杩欏効涓嶅啀杩涗竴姝ヨ璁恒

涓轰簡瀵规秹鍙婁繚瀛樼▼搴忕殑璇锋眰杩涜楠岃瘉锛屾湇鍔″櫒灏嗘煡闃procs_priv琛ㄣ傝琛ㄥ叿鏈変互涓嬪垪锛

琛ㄥ悕

procs_priv

鑼冨洿鍒

Host

 

Db

 

User

 

Routine_name

 

Routine_type

鏉冮檺鍒

Proc_priv

鍏跺畠鍒

Timestamp

 

Grantor

Routine_type鍒椾负ENUM鍒楋紝鍊间负'FUNCTION''PROCEDURE'锛岃〃绀鸿鎵鎸囩殑绋嬪簭绫诲瀷銆傝鍒楀厑璁镐负鍚屽悕鍑芥暟鍜岀▼搴忓崟鐙巿鏉冦

TimestampGrantor鍒楀綋鍓嶈繕鏈娇鐢紝杩欏効涓嶅啀杩涗竴姝ヨ璁恒

姣忎釜鎺堟潈琛ㄥ寘鍚寖鍥村垪鍜屾潈闄愬垪锛

l        鑼冨洿鍒楀喅瀹氳〃涓瘡涓潯鐩紙琛岋級鐨勮寖鍥达紝鍗筹紝琛岄傜敤鐨勪笂涓嬫枃銆備緥濡, 涓涓user琛ㄨ鐨HostUser鍊间负'thomas.loc.gov''bob'灏嗚鐢ㄤ簬璇佸疄鏉ヨ嚜涓绘満thomas.loc.govbob瀵规湇鍔″櫒鐨勮繛鎺ャ傚悓鏍凤紝涓涓db琛ㄨ鐨HostUserDb鍒楃殑鍊兼槸'thomas.loc.gov''bob''reports'灏嗙敤鍦bob浠庝富鏈thomas.loc.gov鑱旀帴璁块棶reports鏁版嵁搴撶殑鏃跺欍tables_privcolumns_priv琛ㄥ寘鍚寖鍥村垪锛屾寚鍑烘瘡涓閫傜敤鐨勮〃鎴栬〃/鍒楃殑缁勫悎銆procs_priv鑼冨洿鍒楁寚鍑烘瘡涓閫傜敤鐨勪繚瀛樼▼搴忋

瀵逛簬妫鏌ュ瓨鍙栫殑鐢ㄩ旓紝姣旇緝Host鍊兼槸蹇界暐澶у皬鍐欑殑銆UserPasswordDbTable_name鍊兼槸鍖哄垎澶у皬鍐欑殑銆Column_name鍊煎湪MySQL3.22.12鎴栦互鍚庣増鏈槸蹇界暐澶у皬鍐欑殑銆

l        鏉冮檺鍒楁寚鍑虹敱涓涓〃琛屾巿浜堢殑鏉冮檺锛屽嵆锛屽彲瀹炴柦浠涔堟搷浣溿傛湇鍔″櫒缁勫悎鍚勭鐨勬巿鏉冭〃鐨勪俊鎭舰鎴愪竴涓敤鎴锋潈闄愮殑瀹屾暣鎻忚堪銆備负姝や娇鐢ㄧ殑瑙勫垯鍦5.7.6鑺傦紝鈥滆闂帶鍒, 闃舵2锛氳姹傛牳瀹炩鎻忚堪銆

鑼冨洿鍒楀寘鍚瓧绗︿覆锛屽涓嬫墍杩帮紱姣忎釜鍒楃殑榛樿鍊兼槸绌哄瓧绗︿覆锛

鍒楀悕

绫诲瀷

Host

CHAR(60)

User

CHAR(16)

Password

CHAR(16)

Db

CHAR(64)

Table_name

CHAR(64)

Column_name

CHAR(64)

Routine_name

CHAR(64)

涓轰簡璁块棶妫鏌ョ洰鐨勶紝Host鍊肩殑姣旇緝瀵瑰ぇ灏忓啓涓嶆晱鎰熴UserPasswordDbTable_name鍊煎澶у皬鍐欐晱鎰熴Column_name鍊煎澶у皬鍐欎笉鏁忔劅銆

userdbhost琛ㄤ腑锛屾墍鏈夋潈闄愬垪浜庡崟鐙殑鍒楀唴锛岃澹版槑涓ENUM('N','Y') DEFAULT 'N'鎹㈠彞璇濊姣忎竴涓潈闄愰兘鍙互琚鐢ㄥ拰鍚敤锛屽苟涓 榛樿鏄鐢

tables_privcolumns_privprocs_priv琛ㄤ腑锛屾潈闄愬垪琚0鏄庝负SET鍒椼傝繖浜涘垪鐨勫煎彲浠ュ寘鍚琛ㄦ帶鍒剁殑鏉冮檺鐨勭粍鍚堬細

琛ㄥ悕

鍒楀悕

鍙兘鐨勮缃厓绱

tables_priv

Table_priv

'Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter'

tables_priv

Column_priv

'Select', 'Insert', 'Update', 'References'

columns_priv

Column_priv

'Select', 'Insert', 'Update', 'References'

procs_priv

Proc_priv

'Execute', 'Alter Routine', 'Grant'

绠鍗曞湴璇达紝鏈嶅姟鍣ㄤ娇鐢ㄨ繖鏍风殑鎺堟潈琛細

         user琛ㄨ寖鍥村垪鍐冲畾鏄惁鍏佽鎴栨嫆缁濆埌鏉ョ殑杩炴帴銆傚浜庡厑璁哥殑杩炴帴锛user琛ㄦ巿浜堢殑鏉冮檺鎸囧嚭鐢ㄦ埛鐨勫叏灞(瓒呯骇鐢ㄦ埛)鏉冮檺銆傝繖浜涙潈闄愰傜敤浜庢湇鍔″櫒涓婄殑all鏁版嵁搴撱

         db琛ㄨ寖鍥村垪鍐冲畾鐢ㄦ埛鑳戒粠鍝釜涓绘満瀛樺彇鍝釜鏁版嵁搴撱傛潈闄愬垪鍐冲畾鍏佽鍝釜鎿嶄綔銆傛巿浜堢殑鏁版嵁搴撶骇鍒殑鏉冮檺閫傜敤浜庢暟鎹簱鍜屽畠鐨勮〃銆

         褰撲綘鎯宠涓涓粰瀹氱殑db琛ㄨ搴旂敤浜庤嫢骞蹭富鏈烘椂锛dbhost琛ㄤ竴璧蜂娇鐢ㄣ備緥濡傦紝濡傛灉浣犳兂瑕佷竴涓敤鎴疯兘鍦ㄤ綘鐨勭綉缁滀粠鑻ュ共涓绘満浣跨敤涓涓暟鎹簱锛屽湪鐢ㄦ埛鐨db琛ㄨ鐨Host鍊艰涓虹┖鍊硷紝鐒跺悗灏嗛偅浜涗富鏈虹殑姣忎竴涓Щ鍏host琛ㄣ傝繖涓満鍒惰缁嗘弿杩板湪5.7.6鑺傦紝鈥滆闂帶鍒, 闃舵2锛氳姹傛牳瀹炩

閲婏細host琛ㄤ笉鍙GRANTREVOKE璇彞鐨勫奖鍝嶃傚ぇ澶氭暟MySQL瀹夎鏍规湰涓嶉渶瑕佷娇鐢ㄨ琛ㄣ

         tables_privcolumns_priv琛ㄧ被浼间簬db琛紝浣嗘槸鏇寸簿鑷达細瀹冧滑鍦ㄨ〃鍜屽垪绾у簲鐢ㄨ岄潪鍦ㄦ暟鎹簱绾с傛巿浜堣〃绾у埆鐨勬潈闄愰傜敤浜庤〃鍜屾墍鏈夊畠鐨勫垪銆傛巿浜堝垪绾у埆鐨勬潈闄愬彧閫傜敤浜庝笓鐢ㄥ垪銆

         procs_priv琛ㄩ傜敤浜庝繚瀛樼殑绋嬪簭銆傛巿浜堢▼搴忕骇鍒殑鏉冮檺鍙傜敤浜庡崟涓▼搴忋

绠$悊鏉冮檺(渚嬪RELOADSHUTDOWN绛夌瓑)浠呭湪user琛ㄤ腑琚寚瀹氥傝繖鏄洜涓虹鐞嗘ф搷浣滄槸鏈嶅姟鍣ㄦ湰韬殑鎿嶄綔骞朵笖涓嶆槸鐗瑰畾鏁版嵁搴擄紝鍥犳娌℃湁鐞嗙敱鍦ㄥ叾浠栨巿鏉冭〃涓垪鍑鸿繖鏍风殑鏉冮檺銆備簨瀹炰笂锛屽彧闇瑕佹煡璇user琛ㄦ潵鍐冲畾浣犳槸鍚︽墽琛屼竴涓鐞嗘搷浣溿

FILE鏉冮檺涔熶粎鍦user琛ㄤ腑鎸囧畾銆傚畠涓嶆槸绠$悊鎬ф潈闄愶紝浣嗕綘鍦ㄦ湇鍔″櫒涓绘満涓婅鎴栧啓鏂囦欢鐨勮兘鍔涗笌浣犳鍦ㄥ瓨鍙栫殑鏁版嵁搴撴棤鍏炽

mysqld鏈嶅姟鍣ㄥ惎鍔ㄦ椂锛屽皢鎺堟潈琛ㄧ殑鍐呭璇诲叆鍒板唴瀛樹腑銆備綘鍙互閫氳繃FLUSH PRIVILEGES璇彞鎴栨墽琛mysqladmin flush-privilegesmysqladmin reload鍛戒护璁╁畠閲嶆柊璇诲彇琛ㄣ傚鎺堟潈琛ㄧ殑鏇存敼鐢熸晥鍦5.7.7鑺傦紝鈥滄潈闄愭洿鏀逛綍鏃剁敓鏁堚鎻忚堪銆

褰撲綘淇敼鎺堟潈琛ㄧ殑鍐呭鏃讹紝纭繚浣犳寜浣犳兂瑕佺殑鏂瑰紡鏇存敼鏉冮檺璁剧疆鏄竴涓ソ涓绘剰銆傝妫鏌ョ粰瀹氳处鎴风殑鏉冮檺锛屼娇鐢SHOW GRANTS璇彞銆備緥濡傦紝瑕佹鏌HostUser鍊煎垎鍒负pc84.example.combob鐨勮处鎴锋墍鎺堜簣鐨勬潈闄愶紝搴旈氳繃璇彞锛

 

mysql> SHOW GRANTS FOR 'bob'@'pc84.example.com';

涓涓湁鐢ㄧ殑璇婃柇宸ュ叿鏄mysqlaccess鑴氭湰锛岀敱Carlier Yves 鎻愪緵缁MySQL鍒嗗彂銆備娇鐢--help閫夐」璋冪敤mysqlaccess鏌ユ槑瀹冩庢牱宸ヤ綔銆傛敞鎰忥細mysqlaccess浠呯敤userdbhost琛ㄦ鏌ュ瓨鍙栥傚畠涓嶆鏌tables_privcolumns_privprocs_priv琛ㄤ腑鎸囧畾鐨勮〃銆佸垪鍜岀▼搴忕骇鏉冮檺銆

瀵逛簬璇婃柇鏉冮檺鐩稿叧鐨勯棶棰樼殑鍏跺畠甯姪锛屽弬瑙5.7.8鑺傦紝鈥滄嫆缁濊闂敊璇殑鍘熷洜銆傚浜庡畨鍏ㄩ棶棰樺父瑙勫缓璁紝鍙傝5.6鑺傦紝鈥滀竴鑸畨鍏ㄩ棶棰樷

5.7.3. MySQL鎻愪緵鐨勬潈闄

璐︽埛鏉冮檺淇℃伅琚瓨鍌ㄥ湪mysql鏁版嵁搴撶殑userdbhosttables_privcolumns_privprocs_priv琛ㄤ腑銆傚湪MySQL鍚姩鏃跺苟鍦5.7.7鑺傦紝鈥滄潈闄愭洿鏀逛綍鏃剁敓鏁堚鎵璇寸殑鎯呭喌鏃讹紝鏈嶅姟鍣ㄥ皢杩欎簺鏁版嵁搴撹〃鍐呭璇诲叆鍐呭瓨銆

GRANTREVOKE璇彞鎵鐢ㄧ殑娑夊強鏉冮檺鐨勫悕绉版樉绀哄湪涓嬭〃锛岃繕鏈夊湪鎺堟潈琛ㄤ腑姣忎釜鏉冮檺鐨勮〃鍒楀悕绉板拰姣忎釜鏉冮檺鏈夊叧鐨勪笂涓嬫枃銆傚叧浜庢瘡涓潈闄愮殑鍚箟鐩稿叧鐨勮缁嗕俊鎭弬瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥

鏉冮檺

涓婁笅鏂

CREATE

Create_priv

鏁版嵁搴撱佽〃鎴栫储寮

DROP

Drop_priv

鏁版嵁搴撴垨琛

GRANT OPTION

Grant_priv

鏁版嵁搴撱佽〃鎴栦繚瀛樼殑绋嬪簭

REFERENCES

References_priv

鏁版嵁搴撴垨琛

ALTER

Alter_priv

DELETE

Delete_priv

INDEX

Index_priv

INSERT

Insert_priv

SELECT

Select_priv

UPDATE

Update_priv

CREATE VIEW

Create_view_priv

瑙嗗浘

SHOW VIEW

Show_view_priv

瑙嗗浘

ALTER ROUTINE

Alter_routine_priv

淇濆瓨鐨勭▼搴

CREATE ROUTINE

Create_routine_priv

淇濆瓨鐨勭▼搴

EXECUTE

Execute_priv

淇濆瓨鐨勭▼搴

FILE

File_priv

鏈嶅姟鍣ㄤ富鏈轰笂鐨勬枃浠惰闂

CREATE TEMPORARY TABLES

Create_tmp_table_priv

鏈嶅姟鍣ㄧ鐞

LOCK TABLES

Lock_tables_priv

鏈嶅姟鍣ㄧ鐞

CREATE USER

Create_user_priv

鏈嶅姟鍣ㄧ鐞

PROCESS

Process_priv

鏈嶅姟鍣ㄧ鐞

RELOAD

Reload_priv

鏈嶅姟鍣ㄧ鐞

REPLICATION CLIENT

Repl_client_priv

鏈嶅姟鍣ㄧ鐞

REPLICATION SLAVE

Repl_slave_priv

鏈嶅姟鍣ㄧ鐞

SHOW DATABASES

Show_db_priv

鏈嶅姟鍣ㄧ鐞

SHUTDOWN

Shutdown_priv

鏈嶅姟鍣ㄧ鐞

SUPER

Super_priv

鏈嶅姟鍣ㄧ鐞

褰撲粠鏃╂湡鐨勬病鏈CREATE VIEWSHOW VIEWCREATE ROUTINEALTER ROUTINEEXECUTE鏉冮檺鐨勭増鏈殑MySQL涓崌绾ф椂锛岃鎯充娇鐢ㄨ繖浜涙潈闄愶紝浣犲繀椤讳娇鐢MySQL鍒嗗彂鎻愪緵鐨mysql_fix_privilege_tables鑴氭湰鍗囩骇 鎺堟潈琛ㄣ傚弬瑙2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥

濡傛灉鍚敤浜嗕簩杩涘埗璁板綍锛岃鎯冲垱寤烘垨淇敼淇濆瓨鐨勭▼搴忥紝浣犺繕闇瑕SUPER鏉冮檺锛岃缁嗘弿杩拌20.4鑺傦紝鈥滃瓨鍌ㄥ瓙绋嬪簭鍜岃Е鍙戠▼搴忕殑浜岃繘鍒舵棩蹇楀姛鑳解

閫氳繃CREATEDROP鏉冮檺锛屼綘鍙互鍒涘缓鏂版暟鎹簱鍜岃〃锛屾垨鍒犻櫎(绉绘帀)宸叉湁鏁版嵁搴撳拰琛ㄣ濡傛灉浣犲皢mysql鏁版嵁搴撲腑鐨DROP鏉冮檺鎺堜簣鏌愮敤鎴凤紝鐢ㄦ埛鍙互鍒犳帀MySQL璁块棶鏉冮檺淇濆瓨鐨勬暟鎹簱銆

SELECTINSERTUPDATEDELETE鏉冮檺鍏佽浣犲湪涓涓暟鎹簱鐜版湁鐨勮〃涓婂疄鏂芥搷浣溿

SELECT璇彞鍙湁鍦ㄤ粬浠湡姝d粠涓涓〃涓绱㈣鏃舵墠闇瑕SELECT鏉冮檺銆備竴浜SELECT璇彞涓嶈闂〃锛岀敋鑷虫病鏈変换浣曞埌鏈嶅姟鍣ㄤ笂鐨勬暟鎹簱閲岀殑瀛樺彇浠讳綍涓滆タ鐨勮鍙備緥濡傦紝浣犲彲浣跨敤mysql瀹㈡埛绔綔涓轰竴涓畝鍗曠殑璁$畻鍣ㄦ潵璇勪及鏈紩鐢ㄨ〃鐨勮〃杈惧紡锛

mysql> SELECT 1+1;
mysql> SELECT PI()*2;

INDEX鏉冮檺鍏佽浣犲垱寤烘垨鍒犻櫎绱㈠紩銆INDEX閫傜敤宸叉湁琛濡傛灉浣犲叿鏈夋煇涓〃鐨CREATE鏉冮檺锛屼綘鍙互鍦CREATE TABLE璇彞涓寘鎷储寮曞畾涔夈

閫氳繃ALTER鏉冮檺锛屼綘鍙互浣跨敤ALTER TABLE鏉ユ洿鏀硅〃鐨勭粨鏋勫拰閲嶆柊鍛藉悕琛

闇瑕CREATE ROUTINE鏉冮檺鏉ュ垱寤轰繚瀛樼殑绋嬪簭锛堝嚱鏁板拰绋嬪簭锛夛紝ALTER ROUTINE鏉冮檺鏉ユ洿鏀瑰拰鍒犻櫎淇濆瓨鐨勭▼搴忥紝EXECUTE鏉ユ墽琛屼繚瀛樼殑绋嬪簭銆

GRANT鏉冮檺鍏佽浣犳妸浣犺嚜宸辨嫢鏈夌殑閭d簺鏉冮檺鎺堢粰鍏朵粬鐨勭敤鎴枫傚彲浠ョ敤浜庢暟鎹簱銆佽〃鍜屼繚瀛樼殑绋嬪簭銆

FILE鏉冮檺缁欎簣浣犵敤LOAD DATA INFILESELECT ... INTO OUTFILE璇彞璇诲拰鍐欐湇鍔″櫒涓婄殑鏂囦欢锛屼换浣曡鎺堜簣FILE鏉冮檺鐨勭敤鎴烽兘鑳借鎴栧啓MySQL鏈嶅姟鍣ㄨ兘璇绘垨鍐欑殑浠讳綍鏂囦欢銆(璇存槑鐢ㄦ埛鍙互璇讳换浣曟暟鎹簱鐩綍涓嬬殑鏂囦欢锛屽洜涓烘湇鍔″櫒鍙互璁块棶杩欎簺鏂囦欢锛FILE鏉冮檺鍏佽鐢ㄦ埛鍦MySQL鏈嶅姟鍣ㄥ叿鏈夊啓鏉冮檺鐨勭洰褰曚笅鍒涘缓鏂版枃浠躲備笉鑳借鐩栧凡鏈夋枃浠躲

鍏朵綑鐨勬潈闄愮敤浜庣鐞嗘ф搷浣滐紝瀹冧娇鐢mysqladmin绋嬪簭鎴SQL璇彞瀹炴柦銆備笅琛ㄦ樉绀烘瘡涓鐞嗘ф潈闄愬厑璁镐綘鎵ц鐨mysqladmin鍛戒护锛

鏉冮檺

鏉冮檺鎷ユ湁鑰呭厑璁告墽琛岀殑鍛戒护

RELOAD

flush-hosts, flush-logs, flush-privileges, flush-status, flush-tables, flush-threads, refresh, reload

SHUTDOWN

shutdown

PROCESS

processlist

SUPER

kill

reload鍛戒护鍛婅瘔鏈嶅姟鍣ㄥ皢鎺堟潈琛ㄩ噸鏂拌鍏ュ唴瀛樸flush-privilegesreload鐨勫悓涔夎瘝锛refresh鍛戒护娓呯┖鎵鏈夎〃骞舵墦寮骞跺叧闂褰曟枃浠讹紝鍏跺畠flush-xxx鍛戒护鎵ц绫讳技refresh鐨勫姛鑳斤紝浣嗘槸鑼冨洿鏇存湁闄愶紝骞朵笖鍦ㄦ煇浜涙儏鍐典笅鍙兘鏇村ソ鐢ㄣ備緥濡傦紝濡傛灉浣犲彧鏄兂娓呯┖璁板綍鏂囦欢锛flush-logsrefresh鏄洿濂界殑閫夋嫨銆

shutdown鍛戒护鍏虫帀鏈嶅姟鍣ㄣ傚彧鑳戒粠mysqladmin鍙戝嚭鍛戒护銆傛病鏈夌浉搴旂殑SQL璇彞銆

processlist鍛戒护鏄剧ず鍦ㄦ湇鍔″櫒鍐呮墽琛岀殑绾跨▼鐨勪俊鎭紙鍗冲叾瀹冭处鎴风浉鍏崇殑瀹㈡埛绔墽琛岀殑璇彞锛夈kill鍛戒护鏉姝绘湇鍔″櫒绾跨▼銆備綘鎬绘槸鑳芥樉绀烘垨鏉姝讳綘鑷繁鐨勭嚎绋嬶紝浣嗘槸浣犻渶瑕PROCESS鏉冮檺鏉ユ樉绀烘垨鏉姝诲叾浠栫敤鎴峰拰SUPER鏉冮檺鍚姩鐨勭嚎绋嬨鍙傝13.5.5.3鑺傦紝鈥淜ILL璇硶鈥

鎷ユ湁CREATE TEMPORARY TABLES鏉冮檺渚垮彲浠ヤ娇鐢CREATE TABLE璇彞涓殑鍏抽敭瀛TEMPORARY

鎷ユ湁LOCK TABLES鏉冮檺渚垮彲浠ョ洿鎺ヤ娇鐢LOCK TABLES璇彞鏉ラ攣瀹氫綘鎷ユ湁SELECT鏉冮檺鐨勮〃銆傚寘鎷娇鐢ㄥ啓閿佸畾锛屽彲浠ラ槻姝粬浜鸿閿佸畾鐨勮〃銆

鎷ユ湁REPLICATION CLIENT鏉冮檺渚垮彲浠ヤ娇鐢SHOW MASTER STATUSSHOW SLAVE STATUS

REPLICATION SLAVE鏉冮檺搴旀巿浜堜粠鏈嶅姟鍣ㄦ墍浣跨敤鐨勫皢褰撳墠鏈嶅姟鍣ㄨ繛鎺ヤ负涓绘湇鍔″櫒鐨勮处鎴銆傛病鏈夎繖涓潈闄愶紝浠庢湇鍔″櫒涓嶈兘鍙戝嚭瀵逛富鏈嶅姟鍣ㄤ笂鐨勬暟鎹簱鎵鍙戝嚭鐨勬洿鏂拌姹傘

鎷ユ湁SHOW DATABASES鏉冮檺渚垮厑璁歌处鎴蜂娇鐢SHOW DATABASE璇彞鏉ユ煡鐪嬫暟鎹簱鍚嶃傛病鏈夎鏉冮檺鐨勮处鎴峰彧鑳界湅鍒颁粬浠叿鏈夐儴鍒嗘潈闄愮殑鏁版嵁搴擄紝 濡傛灉鏁版嵁搴撶敤--skip-show-database閫夐」鍚姩锛屽垯鏍规湰涓嶈兘浣跨敤杩欎簺璇彞銆傝娉ㄦ剰鍏ㄥ眬鏉冮檺鎸囨暟鎹簱鐨勬潈闄愩

鎬荤殑璇存潵锛屽彧鎺堜簣鏉冮檺缁欓渶瑕佷粬浠殑閭d簺鐢ㄦ埛鏄ソ涓绘剰锛屼絾鏄綘搴旇鍦ㄦ巿浜FILE鍜岀鐞嗘潈闄愭椂璇曢獙鐗瑰畾鐨勮鍛婏細

  • FILE鏉冮檺鍙互琚互鐢ㄤ簬灏嗘湇鍔″櫒涓绘満涓MySQL鑳借鍙栫殑浠讳綍鏂囦欢璇诲叆鍒版暟鎹簱琛ㄤ腑銆傚寘鎷换浣曚汉鍙鐨勬枃浠跺拰鏈嶅姟鍣ㄦ暟鎹洰褰曚腑鐨勬枃浠躲傚彲浠ヤ娇鐢SELECT璁块棶鏁版嵁搴撹〃锛岀劧鍚庡皢鍏跺唴瀹逛紶杈撳埌瀹㈡埛绔笂銆
  • GRANT鏉冮檺鍏佽鐢ㄦ埛灏嗕粬浠殑鏉冮檺缁欏叾浠栫敤鎴枫傛湁涓嶅悓鐨勬潈闄愬苟鏈GRANT鏉冮檺鐨2涓敤鎴峰彲浠ュ悎骞舵潈闄愩
  • ALTER鏉冮檺鍙互鐢ㄤ簬閫氳繃閲嶆柊鍛藉悕琛ㄦ潵鎺ㄧ炕鏉冮檺绯荤粺銆
  • SHUTDOWN鏉冮檺閫氳繃缁堟鏈嶅姟鍣ㄥ彲浠ヨ婊ョ敤瀹屽叏鎷掔粷涓哄叾浠栫敤鎴锋湇鍔°
  • PROCESS鏉冮檺鑳借鐢ㄦ潵瀵熺湅褰撳墠鎵ц鐨勬煡璇㈢殑鏄庢枃鏂囨湰锛屽寘鎷瀹氭垨鏀瑰彉瀵嗙爜鐨勬煡璇€
  • SUPER鏉冮檺鑳界敤鏉ョ粓姝㈠叾瀹冪敤鎴锋垨鏇存敼鏈嶅姟鍣ㄧ殑鎿嶄綔鏂瑰紡銆
  • 鎺堢粰mysql鏁版嵁搴撴湰韬殑鏉冮檺鑳界敤鏉ユ敼鍙樺瘑鐮佸拰鍏朵粬璁块棶鏉冮檺淇℃伅銆傚瘑鐮佽鍔犲瘑瀛樺偍锛屾墍浠ユ伓鎰忕殑鐢ㄦ埛涓嶈兘绠鍗曞湴璇诲彇浠栦滑浠ョ煡閬撴槑鏂囧瘑鐮併傜劧鑰岋紝鍏锋湁userPassword鍒楀啓璁块棶鏉冮檺鐨勭敤鎴峰彲浠ユ洿鏀硅处鎴风殑瀵嗙爜锛屽苟鍙互鐢ㄨ璐︽埛杩炴帴MySQL鏈嶅姟鍣ㄣ

鏈変竴浜涗簨鎯呬綘涓嶈兘鐢MySQL鏉冮檺绯荤粺鍋氬埌锛

  • 浣犱笉鑳芥槑鏄惧湴鎸囧畾鏌愪釜缁欏畾鐨勭敤鎴峰簲璇ヨ鎷掔粷璁块棶銆傚嵆锛屼綘涓嶈兘鏄庢樉鍦板尮閰嶇敤鎴风劧鍚庢嫆缁濊繛鎺ャ
  • 浣犱笉鑳芥寚瀹氱敤鎴锋湁鏉冨垱寤虹珛鎴栧垹闄ゆ暟鎹簱涓殑琛紝浣嗕笉鑳藉垱寤烘垨鍒犻櫎鏁版嵁搴撴湰韬

5.7.4. 涓嶮ySQL鏈嶅姟鍣ㄨ繛鎺

褰撲綘鎯宠璁块棶MySQL鏈嶅姟鍣ㄦ椂锛MySQL瀹㈡埛绔▼搴忎竴鑸姹備綘鎸囧畾鍙傛暟锛

         MySQL鏈嶅姟鍣ㄨ繍琛岀殑涓绘満鍚

         濮撳悕

         瀵嗙爜

渚嬪锛屽彲浠ヤ粠鍛戒护琛屾寜鐓т笅杩版彁绀哄惎鍔MySQL瀹㈡埛绔(shell>琛ㄧず)

shell> MySQL -h host_name -u user_name -pyour_pass

-h, -u-p閫夐」杩樺彲浠ラ噰鐢ㄥ舰寮--host=host_name--user=user_name--password=your_pass銆傝娉ㄦ剰鍦-p--password=鍜屽悗闈㈢殑瀵嗙爜涔嬮棿娌℃湁绌烘牸

濡傛灉浣犱娇鐢-p--password閫夐」浣嗘病鏈夋寚瀹氬瘑鐮佸硷紝瀹㈡埛绔▼搴忔彁绀轰綘杈撳叆瀵嗙爜銆傚綋浣犺緭鍏ュ瘑鐮佹椂骞朵笉鏄剧ず瀵嗙爜銆傝繖姣斿湪鍦ㄥ懡浠よ杈撳叆瀵嗙爜瑕佸畨鍏ㄥ緱澶氥傜郴缁熶笂鐨勪换浣曠敤鎴峰彲浠ラ氳繃鍛戒护ps auxww鍦ㄥ懡浠よ涓寚瀹氬瘑鐮併傚弬瑙5.8.6鑺傦紝鈥滀娇浣犵殑瀵嗙爜瀹夊叏鈥

濡傛灉娌℃湁鎸囧畾杩炴帴鍙傛暟锛MySQL瀹㈡埛绔▼搴忎娇鐢ㄩ粯璁ゅ硷細

  • 榛樿涓绘満鍚嶆槸localhost
  • 榛樿鐢ㄦ埛鍚嶅湪Windows涓槸ODBC锛屽湪Unix涓槸浣犵殑Unix鐧诲綍鍚嶃

         濡傛灉娌℃湁-p锛屽垯涓嶆彁渚涘瘑鐮併

杩欐牱, Unix鐢ㄦ埛joe锛屼笅鍒楀懡浠ゆ槸绛変环鐨勶細

shell> MySQL -h localhost -u joe
shell> MySQL -h localhost
shell> MySQL -u joe
shell> MySQL

鍏跺畠MySQL瀹㈡埛绔▼搴忕被浼笺

褰撹繘琛岃繛鎺ユ椂锛屼綘鍙互鎸囧畾瑕佷娇鐢ㄧ殑涓嶅悓鐨勯粯璁ゅ硷紝杩欐牱涓嶅繀姣忔鍦ㄤ綘璋冪敤瀹㈡埛绔▼搴忔槸鍦ㄥ懡浠よ涓婅緭鍏ュ畠浠傝繖鍙互鏈夊緢澶氭柟娉曞仛鍒帮細

  • 浣犲彲浠ュ湪閫夐」鏂囦欢鐨[client]灏忚妭閲屾寚瀹氳繛鎺ュ弬鏁般傛枃浠剁殑鐩稿叧灏忚妭鐪嬩笂鍘诲彲鑳藉儚杩欐牱锛
                [client]
                host=host_name
                user=user_name
                password=your_pass

4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥涓缁嗚璁轰簡閫夐」鏂囦欢銆

5.7.5. 璁块棶鎺у埗, 闃舵1锛氳繛鎺ユ牳瀹

褰撲綘璇曞浘杩炴帴MySQL鏈嶅姟鍣ㄦ椂锛屾湇鍔″櫒鍩轰簬浣犵殑韬唤浠ュ強浣犳槸鍚﹁兘閫氳繃渚涘簲姝g‘鐨勫瘑鐮侀獙璇佽韩浠芥潵鎺ュ彈鎴栨嫆缁濊繛鎺ャ傚鏋滀笉鏄紝鏈嶅姟鍣ㄥ畬鍏ㄦ嫆缁濅綘鐨勮闂紝鍚﹀垯锛屾湇鍔″櫒鎺ュ彈杩炴帴锛岀劧鍚庤繘鍏ラ樁娈2骞朵笖绛夊緟璇锋眰銆

浣犵殑韬唤鍩轰簬2涓俊鎭細

  • 浣犱粠閭d釜涓绘満杩炴帴
  • 浣犵殑MySQL鐢ㄦ埛鍚

韬唤妫鏌ヤ娇鐢3user(Host, UserPassword)鑼冨洿鍒楁墽琛屻傛湇鍔″櫒鍙湁鍦user琛ㄨ褰曠殑HostUser鍒楀尮閰嶅鎴风涓绘満鍚嶅拰鐢ㄦ埛鍚嶅苟涓旀彁渚涗簡姝g‘鐨勫瘑鐮佹椂鎵嶆帴鍙楄繛鎺ャ

userHost鍊肩殑鎸囧畾鏂规硶锛

  • Host鍊煎彲浠ユ槸涓绘満鍚嶆垨IP鍙凤紝鎴'localhost'鎸囧嚭鏈湴涓绘満銆
  • 浣犲彲浠ュ湪Host鍒楀间娇鐢ㄩ氶厤绗﹀瓧绗%_
  • Host'%'鍖归厤浠讳綍涓绘満鍚嶏紝绌Host鍊肩瓑浠蜂簬'%'銆傚畠浠殑鍚箟涓LIKE鎿嶄綔绗︾殑妯″紡鍖归厤鎿嶄綔鐩稿悓銆備緥濡傦紝'%'Host鍊间笌鎵鏈変富鏈哄悕鍖归厤锛岃'%.mysql.com'鍖归厤mysql.com鍩熺殑鎵鏈変富鏈恒

         瀵逛簬鎸囧畾涓IP鍙风殑Host鍊硷紝浣犲彲浠ユ寚瀹氫竴涓綉缁滄帺鐮侊紝璇存槑浣跨敤澶氬皯浣嶅湴鍧浣嶆潵璇勬瘮缃戠粶鍙枫備緥濡傦細

                mysql> GRANT ALL PRIVILEGES ON db.*
                    -> -> TO david@'192.58.197.0/255.255.255.0';

鍏佽david浠庝换浣曞鎴风鐢IPclient_ip鏉ヨ繛鎺ワ紝涓嬮潰鐨勬潯浠朵负鐪燂細

client_ip & netmask = host_ip

That is, for the GRANT statement just shown:

client_ip & 255.255.255.0 = 192.58.197.0

婊¤冻璇ユ潯浠跺苟鍙互杩炴帴MySQL鏈嶅姟鍣ㄧ殑IP鍙风殑鑼冨洿涓192.58.197.0192.58.197.255

         娉ㄩ噴锛氱綉缁滄帺鐮佸彧鐢ㄦ潵鍛婅瘔鏈嶅姟鍣ㄤ娇鐢8162432浣嶅湴鍧锛屼緥濡傦細

                192.0.0.0/255.0.0.0(192 A绫荤綉缁滅殑浠讳綍鍦板潃)
                192.168.0.0/255.255.0.0(192.168 A绫荤綉缁滅殑浠讳綍鍦板潃)
                192.168.1.0/255.255.255.0(192.168.1 C绫荤綉缁滅殑浠讳綍鍦板潃)
                192.168.1.1(鍙湁璇IP)

涓嬮潰鐨勭綉缁滄帺鐮(28 )鏃犳晥锛

192.168.0.1/255.255.255.240

         db琛ㄨ褰曚腑鐨勭┖Host鍊艰〃绀哄畠鐨勬潈闄愬簲缁撳悎鍖归厤瀹㈡埛绔悕鐨host琛ㄤ腑鐨勮浣跨敤銆傞氳繃AND(鐩镐笌)鑰屼笉鏄垨(鑱斿悎)鎿嶄綔灏嗘潈闄愮粍鍚堝埌涓璧枫備綘鍙互浠5.7.6鑺傦紝鈥滆闂帶鍒, 闃舵2锛氳姹傛牳瀹炩鎵惧埌鍏充簬host琛ㄧ殑璇︾粏淇℃伅銆

鍏跺畠grant琛ㄧ殑绌Host鍊间笌'%'鐩稿悓銆

鏃㈢劧浣犺兘鍦Host瀛楁浣跨敤IP閫氶厤绗﹀(渚嬪锛'144.155.166.%'鍖归厤鍦ㄤ竴涓瓙缃戜笂鐨勬瘡鍙颁富鏈)锛屾湁鍙兘鏌愪汉鍙兘浼佸浘鎺㈢┒杩欑鑳藉姏锛岄氳繃鍛藉悕涓鍙颁富鏈轰负144.155.166.somewhere.com銆備负浜嗛樆姝㈣繖鏍风殑浼佸浘锛MySQL涓嶅厑璁稿尮閰嶄互鏁板瓧鍜屼竴涓偣璧峰鐨勪富鏈哄悕锛岃繖鏍凤紝濡傛灉浣犵敤涓涓懡鍚嶄负绫讳技1.2.foo.com鐨勪富鏈猴紝瀹冪殑鍚嶅瓧鍐充笉浼氬尮閰嶆巿鏉冭〃涓殑Host鍒椼傚彧鏈変竴涓IP鏁板瓧鑳藉尮閰IP閫氶厤绗﹀笺

閫氶厤绗﹀瓧绗﹀湪User鍒椾腑涓嶅厑璁革紝浣嗘槸浣犺兘鎸囧畾绌虹殑鍊硷紝瀹冨尮閰嶄换浣曞悕瀛椼傚鏋user琛ㄥ尮閰嶇殑杩炴帴鏈変竴涓┖鐢ㄦ埛鍚嶏紝鐢ㄦ埛琚涓烘槸鍖垮悕鐢ㄦ埛(娌℃湁鍚嶅瓧鐨勭敤鎴)锛岃岄潪瀹㈡埛绔疄闄呮寚瀹氱殑鍚嶅瓧銆傝繖鎰忓懗鐫涓涓┖鐨勭敤鎴峰悕琚敤浜庡湪杩炴帴鏈熼棿鐨勮繘涓姝ョ殑璁块棶妫鏌(鍗筹紝鍦ㄩ樁娈2鏈熼棿)

Password鍒楀彲浠ユ槸绌虹殑銆傝繖涓嶆槸閫氶厤绗︼紝涔熶笉鎰忓懗鐫鍖归厤浠讳綍瀵嗙爜锛屽畠鎰忓懗鐫鐢ㄦ埛蹇呴』涓嶆寚瀹氫竴涓瘑鐮佽繘琛岃繛鎺ャ

user琛ㄤ腑鐨闈炵┖Password鍊间唬琛ㄥ姞瀵嗙殑瀵嗙爜銆MySQL涓嶄互浠讳綍浜哄彲浠ョ湅鐨勬槑鏂囨枃鏈牸寮忓瓨鍌ㄥ瘑鐮侊紝鐩稿弽锛屾鍦ㄨ瘯鍥捐仈鎺ョ殑鐢ㄦ埛鎻愪緵鐨勫瘑鐮佽鍔犲瘑(浣跨敤PASSWORD( )鍑芥暟)锛屽湪杩炴帴杩囩▼涓娇鐢ㄥ姞瀵嗙殑瀵嗙爜妫鏌ュ瘑鐮佹槸鍚︽纭(鍔犲瘑鍚庣殑瀵嗙爜鏈氳繃杩炴帴鍗冲彲瀹炵幇锛MySQL瑙掑害锛屽姞瀵嗙殑瀵嗙爜鏄疄闄呭瘑鐮侊紝鍥犳浣犱笉搴旇鍏跺畠浜鸿闂畠锛佺壒鍒槸锛岀粷瀵逛笉瑕佽闈炵鐞嗙敤鎴疯mysql鏁版嵁搴撲腑鐨勮〃锛

MySQL 5.1浣跨敤寮洪壌瀹氭柟娉(鏈鍏堝湪MySQL 4.1涓傜敤)鍦ㄥ墠闈㈢殑鐗堟湰涓湪杩炴帴杩涚▼涓殑瀵嗙爜淇濇姢杈冨ソ銆傚嵆浣TCP/IP鍖呰鎴彇鎴mysql鏁版嵁搴 琚崟鑾蜂篃寰堝畨鍏ㄣ5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥涓缁嗚璁轰簡瀵嗙爜鍔犲瘑銆

涓嬮潰鐨勪緥瀛愭樉绀哄嚭鍚勭user琛ㄤ腑HostUser鍊肩殑缁勫悎濡備綍搴旂敤浜庡埌鏉ョ殑杩炴帴锛

Host

User

琚潯鐩尮閰嶇殑杩炴帴

'thomas.loc.gov'

'fred'

fred, thomas.loc.gov 杩炴帴

'thomas.loc.gov'

''

浠讳綍鐢ㄦ埛, thomas.loc.gov杩炴帴

'%'

'fred'

fred, 浠庝换浣曚富鏈鸿繛鎺

'%'

''

浠讳綍鐢ㄦ埛, 浠庝换浣曚富鏈鸿繛鎺

'%.loc.gov'

'fred'

fred, 浠庡湪loc.gov鍩熺殑浠讳綍涓绘満杩炴帴

'x.y.%'

'fred'

fred, x.y.netx.y.com,x.y.edu绛夎仈鎺ャ傦紙杩欐垨璁告棤鐢級

'144.155.166.177'

'fred'

fred, 浠庢湁144.155.166.177 IP鍦板潃鐨勪富鏈鸿繛鎺

'144.155.166.%'

'fred'

fred, 144.155.166 C绫诲瓙缃戠殑浠讳綍涓绘満杩炴帴

鍒版潵鐨勮繛鎺ヤ腑鐨勫鎴风鍚嶅拰鐢ㄦ埛鍚嶅彲鑳戒笌user琛ㄤ腑鐨勫琛屽尮閰嶃備緥濡傦紝鐢fredthomas.loc.gov鐨勮繛鎺ュ尮閰嶅涓潯鐩涓婃墍杩般

濡傛灉鏈夊涓尮閰嶏紝鏈嶅姟鍣ㄥ繀椤婚夋嫨浣跨敤鍝釜鏉$洰銆傛寜鐓т笅杩版柟娉曡В鍐抽棶棰橈細

l        鏈嶅姟鍣ㄥ湪鍚姩鏃惰鍏user琛ㄥ悗杩涜鎺掑簭銆

l        鐒跺悗褰撶敤鎴疯瘯鍥捐繛鎺ユ椂锛屼互鎺掑簭鐨勯『搴忔祻瑙堟潯鐩

l        鏈嶅姟鍣ㄤ娇鐢ㄤ笌瀹㈡埛绔拰鐢ㄦ埛鍚嶅尮閰嶇殑绗竴琛屻

user琛ㄦ帓搴忓伐浣滃涓嬶紝鍋囧畾user琛ㄧ湅璧锋潵鍍忚繖鏍凤細

+-----------+----------+-
| Host      | User     | 
+-----------+----------+-
| %         | root     | 
| %         | jeffrey  | 
| localhost | root     | 
| localhost |          | 
+-----------+----------+-

褰撴湇鍔″櫒璇诲彇琛ㄦ椂锛屽畠棣栧厛浠ユ渶鍏蜂綋鐨Host鍊兼帓搴忋備富鏈哄悕鍜IP鍙锋槸鏈鍏蜂綋鐨勩'%'鎰忓懗鐫鈥滀换浣曚富鏈衡濆苟涓旀槸鏈涓嶇壒瀹氱殑銆傛湁鐩稿悓Host鍊肩殑鏉$洰棣栧厛浠ユ渶鍏蜂綋鐨User鍊兼帓搴(User鍊兼剰鍛崇潃鈥滀换浣曠敤鎴封濆苟涓旀槸鏈涓嶇壒瀹氱殑)銆傛渶缁堟帓搴忕殑user琛ㄧ湅璧锋潵鍍忚繖鏍凤細

+-----------+----------+-
| Host      | User     | 
+-----------+----------+-
| localhost | root     |  ...
| localhost |          |  ...
| %         | jeffrey  |  ...
| %         | root     |  ...
+-----------+----------+-

褰撳鎴风璇曞浘杩炴帴鏃讹紝鏈嶅姟鍣ㄦ祻瑙堟帓搴忕殑鏉$洰骞朵娇鐢ㄦ壘鍒扮殑绗竴鍖归厤銆傚浜庣敱jeffreylocalhost鐨勮繛鎺ワ紝琛ㄥ唴鏈変袱涓潯鐩尮閰嶏細HostUser鍊间负'localhost'''鐨勬潯鐩紝鍜屽间负'%''jeffrey'鐨勬潯鐩'localhost'鏉$洰棣栧厛鍖归厤锛屾湇鍔″櫒鍙互浣跨敤銆

杩樻湁涓涓緥瀛愩傚亣瀹user琛ㄧ湅璧锋潵鍍忚繖鏍凤細

+----------------+----------+-
| Host           | User     | 
+----------------+----------+-
| %              | jeffrey  | 
| thomas.loc.gov |          | 
+----------------+----------+-

鎺掑簭鍚庣殑琛ㄧ湅璧锋潵鍍忚繖鏍凤細

+----------------+----------+-
| Host           | User     | 
+----------------+----------+-
| thomas.loc.gov |          | 
| %              | jeffrey  | 
+----------------+----------+-

jeffreythomas.loc.gov鐨勮繛鎺ヤ笌绗竴琛屽尮閰嶏紝鑰岀敱jeffreywhitehouse.gov鐨勮繛鎺ヨ绗簩涓尮閰嶃

鏅亶鐨勮瑙f槸璁や负锛屽缁欏畾鐨勭敤鎴峰悕锛屽綋鏈嶅姟鍣ㄨ瘯鍥惧杩炴帴瀵绘壘鍖归厤鏃讹紝鏄庣‘鍛藉悕閭d釜鐢ㄦ埛鐨勬墍鏈夋潯鐩皢棣栧厛琚娇鐢ㄣ傝繖鏄庢樉涓嶇鍚堜簨瀹炪傚厛鍓嶇殑渚嬪瓙璇存槑浜嗚繖鐐癸紝鍦ㄩ偅閲岀敱jeffreythomas.loc.gov鐨勮繛鎺ユ病琚寘鍚'jeffrey'浣滀负User鍒楀肩殑琛屽尮閰嶏紝浣嗘槸鐢辨病鏈夌敤鎴峰悕鐨勯鐩尮閰嶏紒缁撴灉鏄紝jeffrey琚壌瀹氫负鍖垮悕鐢ㄦ埛锛屽嵆浣夸粬杩炴帴鏃舵寚瀹氫簡鐢ㄦ埛鍚嶃

濡傛灉浣犺兘澶熻繛鎺ユ湇鍔″櫒锛屼絾浣犵殑鏉冮檺涓嶆槸浣犳湡鏈涚殑锛屼綘鍙兘琚壌瀹氫负鍏跺畠璐︽埛銆傝鎯虫壘鍑烘湇鍔″櫒鐢ㄦ潵閴村畾浣犵殑璐︽埛锛屼娇鐢CURRENT_USER()鍑芥暟銆傚畠杩斿洖user_name@host_name鏍煎紡鐨勫硷紝璇存槑UserHost 鍊煎尮閰user琛ㄨ褰曘傚亣瀹jeffrey杩炴帴骞跺彂鍑轰笅闈㈢殑鏌ヨ锛

mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| @localhost     |
+----------------+

杩欏効鏄剧ず鐨勭粨鏋滆鏄user琛ㄨ鏈夌┖鐨User鍒楀笺傛崲鍙ヨ瘽璇达紝鏈嶅姟鍣ㄥ皢jeffrey瑙嗕负鍖垮悕鐢ㄦ埛銆

璇婃柇閴村畾闂鐨勫彟涓涓柟娉曟槸鎵撳嵃鍑user琛ㄥ苟涓旀墜鍔ㄦ帓搴忓畠鐪嬬湅绗竴涓尮閰嶅湪鍝効杩涜銆傚張瑙12.9.3鑺傦紝鈥滀俊鎭嚱鏁扳

5.7.6. 璁块棶鎺у埗, 闃舵2锛氳姹傛牳瀹

涓鏃︿綘寤虹珛浜嗚繛鎺ワ紝鏈嶅姟鍣ㄨ繘鍏ヨ闂帶鍒剁殑闃舵2銆傚鍦ㄦ杩炴帴涓婅繘鏉ョ殑姣忎釜璇锋眰锛屾湇鍔″櫒妫鏌ヤ綘鎯虫墽琛屼粈涔堟搷浣滐紝鐒跺悗妫鏌ユ槸鍚︽湁瓒冲鐨勬潈闄愭潵鎵ц瀹冦傝繖姝f槸鍦ㄦ巿鏉冭〃涓殑鏉冮檺鍒楀彂鎸ヤ綔鐢ㄧ殑鍦版柟銆傝繖浜涙潈闄愬彲浠ユ潵鑷userdbhosttables_privcolumns_priv琛ㄣ傦紙浣犱細鍙戠幇鍙傝5.7.2鑺傦紝鈥滄潈闄愮郴缁熷伐浣滃師鐞嗏寰堟湁甯姪锛屽畠鍒楀嚭浜嗘瘡涓 鎺堟潈琛ㄤ腑鍛堢幇鐨勫垪銆傦級

user琛ㄥ湪鍏ㄥ眬鍩虹涓婃巿浜堣祴浜堜綘鐨勬潈闄愶紝璇ユ潈闄愪笉绠″綋鍓嶇殑鏁版嵁搴撴槸浠涔堝潎閫傜敤銆備緥濡傦紝濡傛灉user琛ㄦ巿浜堜綘DELETE鏉冮檺锛 浣犲彲浠ュ垹闄ゅ湪鏈嶅姟鍣ㄤ富鏈轰笂浠庝换浣曟暟鎹簱鍒犻櫎琛岋紒鎹㈠彞璇濊锛user琛ㄦ潈闄愭槸瓒呯骇鐢ㄦ埛鏉冮檺銆傚彧鎶user琛ㄧ殑鏉冮檺鎺堜簣瓒呯骇鐢ㄦ埛濡傛湇鍔″櫒鎴栨暟鎹簱涓荤鏄槑鏅虹殑銆傚鍏朵粬鐢ㄦ埛锛屼綘搴旇鎶婂湪user琛ㄤ腑鐨勬潈闄愯鎴'N'骞朵笖浠呭湪鐗瑰畾鏁版嵁搴撶殑鍩虹涓婃巿鏉冦備綘鍙互涓虹壒瀹氱殑鏁版嵁搴撱佽〃鎴栧垪鎺堟潈銆

dbhost琛ㄦ巿浜堟暟鎹簱鐗瑰畾鐨勬潈闄愩傚湪杩欎簺琛ㄤ腑鐨勮寖鍥村垪鐨勫煎彲浠ラ噰鐢ㄤ互涓嬫柟寮忥細

  • 閫氶厤绗﹀瓧绗%_鍙敤浜庝袱涓〃鐨HostDb鍒椼傚畠浠笌鐢LIKE鎿嶄綔绗︽墽琛岀殑妯″紡鍖归厤鎿嶄綔鍏锋湁鐩稿悓鐨勫惈涔夈傚鏋滄巿鏉冩椂浣犳兂浣跨敤鏌愪釜瀛楃锛屽繀椤讳娇鐢ㄥ弽鏂滅幇寮曠敤銆備緥濡傦紝瑕佹兂鍦ㄦ暟鎹簱鍚嶄腑鍖呮嫭涓嬪垝绾(_)锛屽湪GRANT璇彞涓敤\_鏉ユ寚瀹
  • db琛ㄧ殑'%'Host鍊兼剰鍛崇潃鈥滀换浣曚富鏈衡濓紝鍦db琛ㄤ腑绌Host鍊兼剰鍛崇潃鈥滃杩涗竴姝ョ殑淇℃伅鍜ㄨhost琛ㄢ濓紙鏈妭鍚庨潰灏嗘弿杩扮殑涓涓繃绋嬶級銆
  • host琛ㄧ殑'%'鎴栫┖Host鍊兼剰鍛崇潃鈥滀换浣曚富鏈衡濄
  • 鍦ㄤ袱涓〃涓殑'%'鎴栫┖Db鍊兼剰鍛崇潃鈥滀换浣曟暟鎹簱鈥濄
  • 鍦ㄤ袱涓〃涓殑绌User鍊煎尮閰嶅尶鍚嶇敤鎴枫

dbhost琛ㄥ湪鏈嶅姟鍣ㄥ惎鍔ㄦ椂琚鍙栧苟鎺掑簭(鍚屾椂瀹冭user)db琛ㄥ湪HostDbUser鑼冨洿鍒椾笂鎺掑簭锛屽苟涓host琛ㄥ湪HostDb鑼冨洿鍒椾笂鎺掑簭銆傚浜user琛紝棣栧厛鏍规嵁鏈鍏蜂綋鐨勫兼渶鍚庢牴鎹渶涓嶅叿浣撶殑鍊兼帓搴忥紝骞朵笖褰撴湇鍔″櫒瀵绘壘鍖归厤鏉$洰鏃讹紝瀹冧娇鐢ㄥ畠鎵惧埌鐨勭涓鍖归厤銆

tables_privcolumns_priv琛ㄦ巿浜堣〃鍜屽垪鐗瑰畾鐨勬潈闄愩傝繖浜涜〃鐨勮寖鍥村垪鐨勫煎彲浠ュ涓嬭鎸囧畾锛

  • 閫氶厤绗%_鍙敤鍦ㄤ娇鐢ㄥ湪涓や釜琛ㄧ殑Host鍒椼
  • 鍦ㄤ袱涓〃涓殑'%'鎴栫┖Host鎰忓懗鐫鈥滀换浣曚富鏈衡濄
  • 鍦ㄤ袱涓〃涓殑DbTable_nameColumn_name鍒椾笉鑳藉寘鍚氶厤绗︽垨绌恒

tables_privcolumns_priv琛ㄦ牴鎹HostDbUser鍒楄鎺掑簭銆傝繖绫讳技浜db琛ㄧ殑鎺掑簭锛屽洜涓哄彧鏈Host鍒楀彲浠ュ寘鍚氶厤绗︼紝鎺掑簭鏇寸畝鍗曘

璇锋眰璇佸疄杩涚▼鍦ㄤ笅闈㈡弿杩般傦紙濡傛灉浣犵啛鎮夎闂鏌ョ殑婧愮爜锛屼綘浼氭敞鎰忓埌杩欓噷鐨勬弿杩颁笌鍦ㄤ唬鐮佷娇鐢ㄧ殑绠楁硶鐣ユ湁涓嶅悓銆傛弿杩扮瓑浠蜂簬浠g爜瀹為檯鍋氱殑涓滆タ锛涗笉鍚屽鍙槸浣胯В閲婃洿绠鍗曘傦級

瀵归渶瑕佺鐞嗘潈闄愮殑璇锋眰(SHUTDOWNRELOAD绛夌瓑)锛屾湇鍔″櫒浠呮鏌user琛ㄦ潯鐩紝鍥犱负閭f槸鍞竴鎸囧畾绠$悊鏉冮檺鐨勮〃銆傚鏋滆璁稿彲璇锋眰鐨勬搷浣滐紝璁块棶琚巿鏉冿紝鍚﹀垯鎷掔粷銆備緥濡傦紝濡傛灉浣犳兂瑕佹墽琛mysqladmin shutdown锛屼絾鏄敱浜user琛ㄨ娌℃湁涓轰綘鎺堜簣HUTDOWN鏉冮檺锛岀敋鑷充笉鐢ㄦ鏌dbhost琛ㄥ氨鎷掔粷浣犵殑璁块棶銆傦紙鍥犱负瀹冧滑涓嶅寘鍚hutdown_priv琛屽垪锛屾病鏈夎繖鏍峰仛鐨勫繀瑕併傦級

瀵规暟鎹簱鏈夊叧鐨勮姹(INSERTUPDATE绛夌瓑)锛屾湇鍔″櫒棣栧厛閫氳繃鏌ユ壘user琛ㄨ鏉ユ鏌ョ敤鎴风殑鍏ㄥ眬(瓒呯骇鐢ㄦ埛)鏉冮檺銆傚鏋滆鍏佽璇锋眰鐨勬搷浣滐紝璁块棶琚巿鏉冦傚鏋滃湪user琛ㄤ腑鍏ㄥ眬鏉冮檺涓嶅锛屾湇鍔″櫒閫氳繃妫鏌dbhost琛ㄧ‘瀹氱壒瀹氱殑鐢ㄦ埛鏁版嵁搴撴潈闄愶細

  1. 鏈嶅姟鍣ㄥ湪db琛ㄧ殑HostDbUser鍒椾笂鏌ユ壘鍖归厤銆HostUser瀵瑰簲杩炴帴鐢ㄦ埛鐨勪富鏈哄悕鍜MySQL鐢ㄦ埛鍚嶃Db鍒楀搴旂敤鎴锋兂瑕佽闂殑鏁版嵁搴撱傚鏋滄病鏈HostUser鐨勮锛岃闂鎷掔粷銆
  2. 濡傛灉db琛ㄤ腑鏈夊尮閰嶇殑琛岃屼笖瀹冪殑Host鍒椾笉鏄┖鐨勶紝璇ヨ瀹氫箟鐢ㄦ埛鐨勬暟鎹簱鐗瑰畾鐨勬潈闄愩
  3. 濡傛灉鍖归厤鐨db琛ㄧ殑琛岀殑Host鍒楁槸绌虹殑锛屽畠琛ㄧずhost琛ㄥ垪涓捐鍏佽璁块棶鏁版嵁搴撶殑涓绘満銆傚湪杩欑鎯呭喌涓嬶紝鍦host琛ㄤ腑浣滆繘涓姝ユ煡鎵句互鍙戠幇HostDb鍒椾笂鐨勫尮閰嶃傚鏋滄病鏈host琛ㄨ鍖归厤锛岃闂鎷掔粷銆傚鏋滄湁鍖归厤锛岀敤鎴锋暟鎹簱鐗瑰畾鐨勬潈闄愪互鍦dbhost琛ㄧ殑琛岀殑鏉冮檺锛屽嵆鍦ㄤ袱涓閮芥槸'Y'鐨勬潈闄愮殑浜ら泦(鑰屼笉鏄骞堕泦锛)璁$畻銆傦紙杩欐牱浣犲彲浠ユ巿浜堝湪db琛ㄨ涓殑涓鑸潈闄愶紝鐒跺悗鐢host琛ㄨ鎸変富鏈轰富鏈轰负鍩虹鏈夐夋嫨鍦伴檺鍒跺畠浠傦級

鍦ㄧ‘瀹氫簡鐢dbhost琛ㄨ鎺堜簣鐨勬暟鎹簱鐗瑰畾鐨勬潈闄愬悗锛屾湇鍔″櫒鎶婁粬浠姞鍒扮敱user琛ㄦ巿浜堢殑鍏ㄥ眬鏉冮檺涓傚鏋滅粨鏋滃厑璁歌姹傜殑鎿嶄綔锛岃闂鎺堟潈銆傚惁鍒欙紝鏈嶅姟鍣ㄦ鏌ュ湪tables_privcolumns_priv琛ㄤ腑鐨勭敤鎴风殑琛ㄥ拰鍒楁潈闄愬苟鎶婂畠浠姞鍒扮敤鎴锋潈闄愪腑銆傚熀浜庢缁撴灉鍏佽鎴栨嫆缁濊闂

鐢ㄥ竷灏旀湳璇〃绀猴紝鍓嶉潰鍏充簬鐢ㄦ埛鏉冮檺濡備綍璁$畻鐨勬弿杩板彲浠ヨ繖鏍锋荤粨锛

global privileges
OR (database privileges AND host privileges)
OR table privileges
OR column privileges

瀹冨彲鑳戒笉鏄庢樉锛屼负浠涔堝憿锛屽鏋滃叏灞user琛岀殑鏉冮檺鏈鍒濆彂鐜板璇锋眰鐨勬搷浣滀笉澶燂紝鏈嶅姟鍣ㄤ互鍚庢妸杩欎簺鏉冮檺鍔犲埌鏁版嵁搴撱佽〃骞跺垪鐨勭壒瀹氭潈闄愩傚師鍥犳槸璇锋眰鍙兘瑕佹眰瓒呰繃涓绉嶇被鍨嬬殑鏉冮檺銆備緥濡傦紝濡傛灉浣犳墽琛INSERT INTO ... SELECT璇彞锛屼綘灏遍渶瑕INSERTSELECT鏉冮檺銆備綘鐨勬潈闄愬繀椤绘槸user琛ㄨ鎺堜簣涓涓潈闄愯db琛ㄨ鎺堜簣鍙︿竴涓潈闄愩傚湪杩欑鎯呭喌涓嬶紝浣犳湁蹇呰鐨勬潈闄愭墽琛岃姹傦紝浣嗘槸鏈嶅姟鍣ㄤ笉鑳借嚜宸辨妸涓や釜琛ㄥ尯鍒紑鏉ワ紱涓や釜琛屾巿浜堢殑鏉冮檺蹇呴』缁勫悎璧锋潵銆

host琛ㄤ笉鍙GRANTREVOKE璇彞鐨勫奖鍝嶏紝鍥犳鍦ㄥぇ澶氭暟MySQL瀹夎涓病鏈変娇鐢ㄣ傚鏋滀綘鐩存帴淇敼瀹冿紝浣犲彲浠ョ敤浜庢煇绉嶄笓闂ㄧ洰鐨勶紝渚嬪鐢ㄦ潵缁存姢瀹夊叏鏈嶅姟鍣ㄥ垪琛ㄣ備緥濡傦紝鍦TcXhost琛ㄥ寘鍚湪鏈湴缃戠粶涓婃墍鏈夌殑鏈哄櫒鐨勮〃銆傝繖浜涜〃琚巿浜堟墍鏈夌殑鏉冮檺銆

浣犱篃鍙互浣跨敤host琛ㄦ寚瀹瀹夊叏鐨勪富鏈恒傚亣瀹氫綘鏈変竴鍙版満鍣public.your.domain锛屽畠浣嶄簬浣犺涓轰笉瀹夊叏鐨勫叕鍏卞尯鍩燂紝浣犲彲浠ョ敤涓嬪垪鐨host琛ㄦ潯鐩厑璁搁櫎浜嗛偅鍙版満鍣ㄥ鐨勭綉缁滀笂鎵鏈変富鏈虹殑璁块棶锛

+--------------------+----+-
| Host               | Db | ...
+--------------------+----+-
| public.your.domain | %  | ... (all privileges set to 'N')
| %.your.domain      | %  | ... (all privileges set to 'Y')
+--------------------+----+-

褰撶劧锛屼竴瀹氳娴嬭瘯鎺堟潈琛ㄤ腑鐨勮(渚嬪锛屼娇鐢SHOW GRANTSmysqlaccess)锛岀‘淇濅綘鐨勮闂潈闄愬疄闄呮寜浣犳湡鏈涚殑鏂瑰紡琚缃

5.7.7. 鏉冮檺鏇存敼浣曟椂鐢熸晥

mysqld鍚姩鏃讹紝鎵鏈夋巿鏉冭〃鐨勫唴瀹硅璇昏繘鍐呭瓨骞朵笖浠庢鏃剁敓鏁堛

褰撴湇鍔″櫒娉ㄦ剰鍒版巿鏉冭〃琚敼鍙樹簡鏃讹紝鐜板瓨鐨勫鎴风杩炴帴鏈夊涓嬪奖鍝嶏細

  • 琛ㄥ拰鍒楁潈闄愬湪瀹㈡埛绔殑涓嬩竴娆¤姹傛椂鐢熸晥銆
  • 鏁版嵁搴撴潈闄愭敼鍙樺湪涓嬩竴涓USE db_name鍛戒护鐢熸晥銆

         鍏ㄥ眬鏉冮檺鐨勬敼鍙樺拰瀵嗙爜鏀瑰彉鍦ㄤ笅涓娆″鎴风杩炴帴鏃剁敓鏁堛

濡傛灉鐢GRANTREVOKESET PASSWORD瀵规巿鏉冭〃杩涜淇敼锛屾湇鍔″櫒浼氭敞鎰忓埌骞剁珛鍗抽噸鏂板皢鎺堟潈琛ㄨ浇鍏ュ唴瀛樸

濡傛灉浣犳墜鍔ㄥ湴淇敼鎺堟潈琛(浣跨敤INSERTUPDATEDELETE绛夌瓑)锛屼綘搴旇鎵цmysqladmin flush-privilegesmysqladmin reload鍛婅瘔鏈嶅姟鍣ㄥ啀瑁呰浇鎺堟潈琛紝鍚﹀垯浣犵殑鏇存敼灏涓嶄細鐢熸晥锛岄櫎闈炰綘閲嶅惎鏈嶅姟鍣ㄣ

濡傛灉浣犵洿鎺ユ洿鏀逛簡鎺堟潈琛ㄤ絾蹇樿閲嶈浇锛岄噸鍚湇鍔″櫒鍚庝綘鐨勬洿鏀规柟鐢熸晥銆傝繖鏍峰彲鑳借浣犺糠鎯戜负浠涔堜綘鐨勬洿鏀规病鏈変粈涔堝彉鍖栵紒

5.7.8. 鎷掔粷璁块棶閿欒鐨勫師鍥

褰撲綘璇曠潃鑱旀帴MySQL鏈嶅姟鍣ㄦ椂锛屽鏋滅鍒伴棶棰橈紝涓嬮潰鍚勯」鍙互甯姪浣犵籂姝i棶棰橈細

         纭繚鏈嶅姟鍣ㄥ湪杩愯銆傚鏋滄湇鍔″櫒娌℃湁杩愯锛屽垯浣犱笉鑳借繛鎺ユ湇鍔″櫒銆傚鏋滀綘瑙嗗浘杩炴帴鏈嶅姟鍣ㄥ苟鐪嬪埌涓嬭堪娑堟伅锛屽彲鑳芥槸鏈嶅姟鍣ㄦ病鏈夎繍琛岋細

                shell> mysql
                ERROR 2003: Can't connect to MySQL server on 'host_name' (111)
                shell> mysql
                ERROR 2002: Can't connect to local MySQL server through socket
                '/tmp/mysql.sock' (111)

涔熷彲鑳芥湇鍔″櫒姝e湪杩愯锛屼絾浣犲彲鑳戒娇鐢ㄤ笌鏈嶅姟鍣ㄤ笂渚﹀惉鐨勪笉涓鏍风殑TCP/IP绔彛銆佸懡鍚嶇閬撴垨Unix濂楁帴瀛楁枃浠躲備綘鍙互璋冪敤瀹㈡埛绔▼搴忥紝鎸囧畾绔彛閫夐」鏉ユ寚绀烘纭殑绔彛鎴栧鎺ュ瓧閫夐」鏉ユ寚绀烘纭殑鍛藉悕绠¢亾鎴Unix濂楁帴瀛楁枃浠躲傝鎵惧嚭濂楁帴瀛楁枃浠剁殑鍦扮偣锛屽簲锛

shell> netstat -ln | grep mysql
  • 蹇呴』姝g‘璁剧疆鎺堟潈琛紝浠ヤ究鏈嶅姟鍣ㄥ彲浠ヤ娇鐢ㄥ畠浠繘琛岃闂帶鍒躲傚浜庢煇浜涘垎鍙戠増绫诲瀷(渚嬪Windows涓殑浜岃繘鍒跺垎鍙戠増鎴Linux涓殑RPM鍒嗗彂鐗),瀹夎杩囩▼鍒濆鍖栧寘鍚 鎺堟潈琛ㄧ殑mysql鏁版嵁搴撱傚鏋滃垎鍙戠増娌℃湁杩欐牱鍋氾紝浣犲繀椤昏繍琛mysql_install_db鑴氭湰鏉ユ墜鍔ㄥ垵濮嬪寲鎺堟潈琛ㄣ傝缁嗗唴瀹瑰弬瑙2.9.2鑺傦紝鈥淯nix涓嬪畨瑁呭悗鐨勮繃绋嬧

纭畾鏄惁瑕佸垵濮嬪寲鎺堟潈琛ㄧ殑涓涓柟娉曟槸瀵绘壘鏁版嵁鐩綍涓嬬殑mysql鐩綍鏁版嵁鐩綍鍚嶉氬父涓datavar锛屼綅浜MySQL瀹夎鐩綍涓銆傚簲淇濊瘉MySQL鏁版嵁搴撶洰褰曟湁鏂囦欢user.MYD銆傚惁鍒欙紝鎵цmysql_install_db鑴氭湰銆傝繍琛屽苟閲嶅惎鏈嶅姟鍣ㄥ悗锛屾墽琛岃鍛戒护鏉ユ祴璇曞垵濮嬫潈闄愶細

shell> mysql -u root test

鏈嶅姟鍣ㄥ簲璇ヨ浣犳棤璇湴杩炴帴銆

  • 鍦ㄦ柊鐨勫畨瑁呬互鍚庯紝浣犲簲璇ヨ繛鎺ユ湇鍔″櫒骞朵笖璁剧疆浣犵殑鐢ㄦ埛鍙婂叾璁块棶璁稿彲锛
                shell> mysql -u root mysql

鏈嶅姟鍣ㄥ簲璇ヨ浣犺繛鎺ワ紝鍥犱负MySQL root鐢ㄦ埛鍒濆鏃舵病鏈夊瘑鐮併傞偅涔熸槸瀹夊叏椋庨櫓锛屽綋浣犳鍦ㄨ缃叾浠MySQL鐢ㄦ埛鏃讹紝涔熷簲璁惧畾root瀵嗙爜鏄竴浠堕噸瑕佺殑浜嬭銆傚叧浜庤缃垵濮嬪瘑鐮佺殑璇存槑锛屽弬瑙2.9.3鑺傦紝鈥滀娇鍒濆MySQL璐︽埛瀹夊叏鈥

  • 濡傛灉浣犲皢涓涓幇瀛樼殑MySQL瀹夎鍗囩骇鍒拌緝鏂扮殑鐗堟湰锛岃繍琛屼簡mysql_fix_privilege_tables鑴氭湰鍚楋紵濡傛灉娌℃湁锛岃繍琛屽畠銆傚鍔犳柊鍔熻兘鍚庯紝鎺堟潈琛ㄧ殑缁撴瀯鍙兘浼氭敼鍙橈紝鍥犳鏇存柊鍚庡簲纭繚琛ㄧ殑缁撴瀯闅忎箣鏇存柊銆傜浉鍏宠鏄庡弬瑙2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥

         濡傛灉瀹㈡埛绔▼搴忚瘯鍥捐繛鎺ユ椂鏀跺埌浠ヤ笅閿欒淇℃伅锛岃鏄庢湇鍔″櫒闇瑕佹柊鏍煎紡鐨勫瘑鐮侊紝鑰屽鎴风涓嶈兘鐢熸垚锛

                shell> mysql
                Client does not support authentication protocol requested
                by server; consider upgrading MySQL client

鍏充簬濡備綍澶勭悊鐨勮缁嗕俊鎭紝鍙傝5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥A.2.3鑺傦紝鈥滃鎴风涓嶆敮鎸侀壌瀹氬崗璁

  • 濡傛灉浣犱綔涓root璇曡瘯杩炴帴骞朵笖寰楀埌杩欎釜閿欒锛岃繖鎰忓懗鐫锛屼綘娌℃湁琛屽湪user琛ㄤ腑鐨User鍒楀间负'root'骞朵笖mysqld涓嶈兘涓轰綘鐨勫鎴风瑙f瀽涓绘満鍚嶏細
  • Access denied for user ''@'unknown' to database mysql

鍦ㄨ繖绉嶆儏鍐典笅锛屼綘蹇呴』鐢--skip-grant-tables閫夐」閲嶅惎鏈嶅姟鍣ㄥ苟涓旂紪杈/etc/hosts\windows\hosts鏂囦欢涓轰綘鐨勪富鏈哄鍔犺銆

  • 濡傛灉浣犱粠3.22.11浠ュ墠鐨勭増鏈洿鏂扮幇瀛樼殑MySQL瀹夎鍒3.22.11鐗堟垨浠ュ悗鐗堟湰锛屼綘杩愯浜mysql_fix_privilege_tables鑴氭湰鍚楋紵濡傛灉娌℃湁锛岃繍琛屽畠銆傚湪GRANT璇彞鍙樺緱鑳藉伐浣滄椂锛屾巿鏉冭〃鐨勭粨鏋勭敤MySQL 3.22.11淇敼 銆

         璁颁綇瀹㈡埛绔▼搴忎娇鐢ㄩ夐」鏂囦欢鎴栫幆澧冨彉閲忎腑鎸囧畾鐨勮繛鎺ュ弬鏁般傚鏋滃鎴风绋嬪簭鍙戦佷笉姝g‘鐨勯粯璁よ繛鎺ュ弬鏁帮紝鑰屼綘娌℃湁鍦ㄥ懡浠よ涓寚瀹氾紝妫鏌ョ幆澧冨彉閲忓拰閫傜敤鐨勯夐」鏂囦欢銆備緥濡傦紝褰撲綘涓嶇敤浠讳綍閫夐」杩愯瀹㈡埛绔▼搴忥紝寰楀埌Access denied閿欒锛岀‘淇濅綘娌℃湁鍦ㄩ夐」鏂囦欢涓寚瀹氭棫瀵嗙爜锛

浣犲彲浠ラ氳繃浣跨敤--no-defaults閫夐」璋冪敤瀹㈡埛绔▼搴忔潵绂佺敤閫夐」鏂囦欢銆備緥濡傦細

shell> mysqladmin --no-defaults -u root version

瀹㈡埛绔娇鐢ㄧ殑閫夐」鏂囦欢瑙4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥銆傜幆澧冨彉閲忓垪浜闄勫綍F锛鐜鍙橀噺

         濡傛灉閬囧埌涓嬭堪閿欒锛岃鏄root瀵嗙爜閿欒锛

                shell> mysqladmin -u root -pxxxx ver
                Access denied for user 'root'@'localhost' (using password: YES)

濡傛灉浣犳湭鎸囧畾瀵嗙爜鏃跺嚭鐜板墠闈㈢殑閿欒锛岃鏄庢煇涓夐」鏂囦欢涓殑瀵嗙爜涓嶆纭傝瘯璇曞墠闈㈡墍璇寸殑--no-defaults閫夐」銆

鍏充簬瀵嗙爜鏇存敼鐨勪俊鎭弬瑙5.8.5鑺傦紝鈥滆缃处鎴峰瘑鐮佲

濡傛灉浣犱涪澶辨垨蹇樿root瀵嗙爜锛屼綘鍙互鐢--skip-grant-tables閲嶅惎 mysqld鏉ユ洿鏀瑰瘑鐮併傚弬瑙A.4.1鑺傦紝鈥滃浣曞浣嶆牴鐢ㄦ埛瀵嗙爜鈥.

         濡傛灉浣犱娇鐢SET PASSWORDINSERTUPDATE鏇存敼瀵嗙爜锛屼綘蹇呴』浣跨敤  PASSWORD()鍑芥暟鍔犲瘑瀵嗙爜銆傚鏋滀綘涓嶄娇鐢PASSWORD()鍑芥暟锛屽瘑鐮佷笉宸ヤ綔銆備緥濡傦紝涓嬮潰鐨勮鍙ヨ缃瘑鐮侊紝浣嗘病鑳藉姞瀵嗭紝鍥犳鐢ㄦ埛鍚庨潰涓嶈兘杩炴帴锛

                mysql> SET PASSWORD FOR 'abe'@'host_name' = 'eagle';

鐩稿弽锛屽簲杩欐牱璁剧疆瀵嗙爜锛

mysql> SET PASSWORD FOR 'abe'@'host_name' = PASSWORD('eagle');

褰撲綘浣跨敤GRANTCREATE USER璇彞鎴mysqladmin password鍛戒护鎸囧畾瀵嗙爜鏃讹紝涓嶉渶瑕PASSWORD()鍑芥暟锛屽畠浠細鑷姩浣跨敤PASSWORD()鏉ュ姞瀵嗗瘑鐮併傚弬瑙5.8.5鑺傦紝鈥滆缃处鎴峰瘑鐮佲13.5.1.1鑺傦紝鈥淐REATE USER璇硶鈥

         localhost鏄綘鏈湴涓绘満鍚嶇殑涓涓悓涔夎瘝锛屽苟涓斾篃鏄鏋滀綘涓嶆槑纭湴鎸囧畾涓绘満鑰屽鎴风灏濊瘯杩炴帴鐨勯粯璁や富鏈恒

瑕佹兂鍦ㄨ繖绉嶇郴缁熶笂閬垮厤璇ラ棶棰橈紝浣犲彲浠ヤ娇鐢--host=127.0.0.1閫夐」鏉ユ槑纭懡鍚嶆湇鍔″櫒涓绘満銆傝繖鏍峰皢閫氳繃TCP/IP鍗忚鏉ヨ繛鎺ユ湰鍦mysqld鏈嶅姟鍣銆備綘杩樺彲浠ユ寚瀹--host閫夐」浣跨敤TCP/IP锛屼娇鐢ㄥ疄闄呯殑鏈満涓绘満鍚嶃傚湪杩欑鎯呭喌涓嬶紝涓绘満鍚嶅繀椤绘寚瀹氫负鏈嶅姟鍣ㄤ富鏈轰笂鐨user琛ㄨ锛屽嵆浣夸綘鍦ㄦ湇鍔″櫒涓婅繍琛屽鎴风绋嬪簭銆

         褰撳皾璇曠敤mysql -u user_name涓庢暟鎹簱杩炴帴鏃讹紝濡傛灉浣犲緱鍒颁竴涓Access denied閿欒锛屽彲鑳戒細閬囧埌涓user琛ㄦ湁鍏崇殑闂锛岄氳繃鎵цmysql -u root mysql骞朵笖鎵ц涓嬮潰鐨SQL璇彞杩涜妫鏌ワ細

                mysql> SELECT * FROM user;

缁撴灉搴旇鍖呭惈涓涓湁HostUser鍒楃殑琛屽尮閰嶄綘鐨勮绠楁満涓绘満鍚嶅拰浣犵殑MySQL鐢ㄦ埛鍚嶃

  • Access denied閿欒娑堟伅灏嗗憡璇変綘锛屼綘姝e湪鐢ㄥ摢涓敤鎴峰皾璇曠櫥褰曪紝浣犳鍦ㄨ瘯鍥捐繛鎺ュ摢涓富鏈猴紝鏄惁浣跨敤浜嗗瘑鐮併傞氬父锛屼綘搴旇鍦user琛ㄤ腑鏈変竴琛岋紝姝g‘鍦板尮閰嶅湪閿欒娑堟伅缁欏嚭鐨勪富鏈哄悕鍜岀敤鎴峰悕銆備緥濡傦紝濡傛灉閬囧埌鍖呭惈using password: NO鐨勯敊璇俊鎭紝璇存槑浣犵櫥褰曟椂娌℃湁瀵嗙爜銆

         濡傛灉褰撲綘璇曠潃浠庝竴涓笉鏄MySQL鏈嶅姟鍣ㄦ鍦ㄨ繍琛岀殑涓绘満涓婅繛鎺ユ椂锛岄亣鍒颁笅鍒楅敊璇紝閭d箞鍦user琛ㄤ腑娌℃湁鍖归厤閭e彴涓绘満鐨勮锛

                Host ... is not allowed to connect to this MySQL server

鍙互閫氳繃缁勫悎浣犳鍦ㄨ瘯鍥捐繛鎺ョ殑鐢ㄦ埛/涓绘満鍚嶈缃竴涓处鎴锋潵淇瀹冦傚鏋滀綘涓嶇煡閬撴杩炴帴鐨勬満鍣ㄧ殑IP鍙锋垨涓绘満鍚嶏紝搴旇鎶婁竴涓'%'琛屼綔涓Host鍒楀兼斁鍦user琛ㄤ腑銆傚湪璇曞浘浠庡鎴风鍣ㄨ繛鎺ヤ互鍚庯紝閫氳繃SELECT USER()鏌ヨ鏄剧ず浣犲浣曠湡姝h繘琛岃繛鎺ャ傦紙鐒跺悗鐢ㄥ湪鏃ュ織鏂囦欢涓婇潰鏄剧ず鍑虹殑瀹為檯鐨勪富鏈哄悕浠f浛user琛ㄤ腑鐨'%'琛屻傚惁鍒欙紝浣犲皢寰楀埌涓涓笉瀹夊叏鐨勭郴缁燂紝鍥犱负瀹冨厑璁镐粠浠讳綍涓绘満涓婁互浠讳綍鐢ㄦ埛鍚嶈繛鎺ャ傦級

Linux涓紝鍙戠敓璇ラ敊璇殑鍙︿竴涓師鍥犲彲鑳芥槸浣犳浣跨敤浜庝綘鎵浣跨敤鐗堟湰鐨glibc搴撲笉鍚岀増鏈殑搴撶紪璇戠殑浜岃繘鍒MySQL鐗堟湰銆傚湪杩欑鎯呭喌涓嬶紝浣犲簲鍗囩骇鎿嶄綔绯荤粺鎴glibc锛屾垨涓嬭浇MySQL鐗堟湰鐨勬簮鐮佸垎鍙戠増骞惰嚜宸辩紪璇戙傛簮鐮RPM涓鑸緢瀹规槗缂栬瘧骞跺畨瑁咃紝鍥犳涓嶆槸澶ч棶棰樸

         濡傛灉浣犺繛鎺ユ椂鎸囧畾涓绘満鍚嶏紝浣嗗緱鍒伴敊璇秷鎭富鏈哄悕鏈樉绀烘垨涓IP鍙凤紝琛ㄧず褰MySQL鏈嶅姟鍣ㄥ皢IP鍙疯В鏋愪负瀹㈡埛绔潵鍚嶆椂閬囧埌閿欒锛

                shell> mysqladmin -u root -pxxxx -h some-hostname ver
                Access denied for user 'root'@'' (using password: YES)

杩欒〃绀DNS闂銆傝鎯充慨澶嶏紝鎵цmysqladmin flush-hosts鏉ラ噸璁惧唴閮 DNS涓绘満鍚嶇紦瀛樸傚弬瑙7.5.6鑺傦紝鈥淢ySQL濡備綍浣跨敤DNS鈥

涓浜涘父鐢ㄧ殑瑙e喅鏂规鍖呮嫭锛

o        璇曡瘯鎵惧嚭DNS鏈嶅姟鍣ㄧ殑閿欒骞朵慨澶嶃

o        MySQL鎺堟潈琛ㄤ腑鎸囧畾IP鍙疯屼笉鏄富鏈哄悕銆

o        /etc/hosts涓斁鍏ュ鎴风鍚嶃

o        --skip-name-resolve閫夐」鍚姩mysqld

o        --skip-host-cache閫夐」鍚姩mysqld

o        Unix涓紝濡傛灉浣犲湪鍚屼竴鍙版満鍣ㄤ笂杩愯鏈嶅姟鍣ㄥ拰瀹㈡埛绔紝杩炴帴鍒localhost銆傝繛鎺ュ埌鐨localhostUnix杩炴帴浣跨敤Unix濂楁帴瀛楁枃浠惰屼笉鏄TCP/IP

o        Windows涓紝浣犲湪鍚屼竴鍙版満鍣ㄤ笂杩愯鏈嶅姟鍣ㄥ拰瀹㈡埛绔苟涓旀湇鍔″櫒鏀寔鍛藉悕绠¢亾杩炴帴锛岃繛鎺ヤ富鏈哄悕(鍛ㄦ湡)銆傝繛鎺ヤ娇鐢ㄥ懡鍚嶇閬撹屼笉鏄TCP/IP

  • 濡傛灉mysql -u root test宸ヤ綔浣嗘槸mysql -h your_hostname -u root test瀵艰嚧Access deniedyour_hostname鏄湰鍦版満鐨勫疄闄呬富鏈哄悕锛岄偅涔堝湪user琛ㄤ腑鍙兘娌℃湁浣犵殑涓绘満鐨勬纭悕瀛椼傝繖閲岀殑涓涓櫘閬嶇殑闂鏄湪user琛ㄨ涓殑Host鍊兼寚瀹氫竴涓敮涓鐨勪富鏈哄悕锛屼絾鏄綘绯荤粺鐨勫悕瀛楄В鏋愪緥绋嬭繑鍥炰竴涓畬鍏ㄦ瑙勭殑鍩熷悕(鎴栫浉鍙)銆備緥濡傦紝濡傛灉浣犲湪user琛ㄤ腑鏈変竴涓富鏈烘槸'tcx'鐨勮锛屼絾鏄綘鐨DNS鍛婅瘔MySQL浣犵殑涓绘満鍚嶆槸'tcx.subnet.se'锛岃灏嗕笉宸ヤ綔銆傚皾璇曟妸涓涓鍔犲埌user琛ㄤ腑锛屽畠鍖呭惈浣犱富鏈虹殑IP鍙蜂綔涓Host鍒楃殑鍊笺傦紙鍙﹀锛屼綘鍙互鎶婁竴涓鍔犲埌user琛ㄤ腑锛屽畠鏈夊寘鍚竴涓氶厤绗﹀'tcx.%'Host鍊笺傜劧鑰岋紝浣跨敤浠%缁撳熬鐨勪富鏈哄悕鏄涓嶅畨鍏ㄧ殑骞朵笖鎺ㄨ崘锛侊級
  • 濡傛灉mysql -u user_name test宸ヤ綔浣嗘槸mysql -u user_name other_db_name涓嶅伐浣滐紝浣犳病鏈変负缁欏畾鐨勭敤鎴锋巿浜other_db_name鏁版嵁搴撶殑璁块棶鏉冮檺銆
  • 褰撳湪鏈嶅姟鍣ㄤ笂鎵цmysql -u user_name鏃讹紝瀹冨伐浣滐紝浣嗘槸鍦ㄥ叾瀹冭繙绋嬪鎴风涓婃墽mysql -h host_name -u user_name鏃讹紝瀹冨嵈涓嶅伐浣滐紝浣犳病鏈変负缁欏畾鐨勭敤鎴锋巿浜堜粠杩滅▼涓绘満璁块棶鏈嶅姟鍣ㄧ殑鏉冮檺銆
  • 濡傛灉浣犱笉鑳藉紕鏄庣櫧浣犱负浠涔堝緱鍒Access denied锛屼粠user琛ㄤ腑鍒犻櫎鎵鏈Host鍖呭惈閫氶厤绗﹀肩殑琛(鍖呭惈%_鐨勬潯鐩)銆備竴涓緢鏅亶鐨勯敊璇槸鐢Host='%'User='some_user'鎻掑叆涓涓柊琛岋紝璁や负杩欏皢鍏佽浣犳寚瀹localhost浠庡悓涓鍙版満鍣ㄨ繘琛岃繛鎺ャ傚畠涓嶅伐浣滅殑鍘熷洜鏄 榛樿鏉冮檺鍖呮嫭涓涓湁Host='localhost'User=''鐨勮锛屽洜涓洪偅涓鐨Host'localhost''%'鏇村叿浣擄紝褰撲粠localhost杩炴帴鏃讹紝瀹冪敤浜庢寚鍚戞柊琛岋紒姝g‘鐨勬楠ゆ槸鎻掑叆Host='localhost'User='some_user'鐨勭2涓锛屾垨鍒犻櫎Host='localhost'User=''琛屻傚垹闄ゆ潯鐩悗锛岃浣忕敤FLUSH PRIVILEGES璇彞閲嶈浇鎺堟潈琛ㄣ

         濡傛灉浣犲緱鍒颁笅鍒楅敊璇紝鍙互涓dbhost琛ㄦ湁鍏筹細

                Access to database denied

濡傛灉浠db琛ㄤ腑閫夋嫨浜嗗湪Host鍒楁湁绌哄肩殑鏉$洰锛屼繚璇佸湪host琛ㄤ腑鏈変竴涓垨澶氫釜鐩稿簲鐨勬潯鐩紝鎸囧畾db琛ㄤ腑鐨勬潯鐩傜敤鍝簺涓绘満銆

         濡傛灉浣犺兘澶熻繛鎺MySQL鏈嶅姟鍣紝浣嗗鏋滃湪浣跨敤鍛戒护SELECT ... INTO OUTFILELOAD DATA INFILE璇彞鏃讹紝浣犲緱鍒Access denied閿欒锛屽湪user琛ㄤ腑鐨勬潯鐩彲鑳芥病鏈夊惎鐢FILE鏉冮檺銆

         濡傛灉浣犵洿鎺ユ洿鏀规巿鏉冭〃(渚嬪锛屼娇鐢INSERTUPDATEDELETE璇彞)骞朵笖浣犵殑鏇存敼濂藉儚琚拷鐣ヤ簡锛岃浣忎綘蹇呴』鎵цFLUSH PRIVILEGES璇彞鎴mysqladmin flush-privileges鍛戒护璁╂湇鍔″櫒鏉ラ噸璇绘巿鏉冭〃銆傚惁鍒欙紝鐩村埌鏈嶅姟鍣ㄤ笅娆¢噸鍚紝浣犵殑鏇存敼鏂规湁鏁堛傝浣忕敤UPDATE鍛戒护鏇存敼root瀵嗙爜鍚庯紝鍦ㄦ竻绌烘潈闄愬墠锛屼綘涓嶉渶瑕佹寚瀹氭柊瀵嗙爜锛屽洜涓烘湇鍔″櫒杩樹笉鐭ラ亾浣犲凡缁忔洿鏀逛簡瀵嗙爜锛

         濡傛灉浣犵殑鏉冮檺浼间箮鍦ㄤ竴涓細璇濊繃绋嬩腑鏀瑰彉浜嗭紝鍙兘鏄竴涓秴绾х敤鎴锋敼鍙樹簡浠栦滑銆傚啀娆¤鍏ユ巿鏉冭〃浼氬奖鍝嶆柊瀹㈡埛绔繛鎺ワ紝浣嗘槸瀹冧篃褰卞搷鐜板瓨鐨勮繛鎺ワ紝濡5.7.7鑺傦紝鈥滄潈闄愭洿鏀逛綍鏃剁敓鏁堚灏忚妭鎵杩般

         濡傛灉浣犳湁PerlPythonODBC绋嬪簭鐨勫瓨鍙栭棶棰橈紝璇曠潃鐢mysql -u user_name db_namemysql -u user_name -pyour_pass db_name涓庢湇鍔″櫒杩炴帴銆傚鏋滀綘鑳界敤mysql瀹㈡埛绔繘琛岃繛鎺ワ紝杩欐槸绋嬪簭鐨勪竴涓棶棰樿屼笉鏄闂潈闄愮殑闂銆傦紙娉ㄦ剰鍦-p鍜屽瘑鐮佷箣闂存病鏈夌┖鏍硷紱涔熷彲浠ヤ娇鐢--password=your_pass璇硶鎸囧畾瀵嗙爜銆傚鏋滀娇鐢-p閫夐」MySQL鎻愮ず浣犺緭鍏ュ瘑鐮併傦級

         涓轰簡娴嬭瘯锛岀敤--skip-grant-tables閫夐」鍚姩mysqld瀹堟姢杩涚▼锛岀劧鍚庝綘鍙互鏀瑰彉MySQL鎺堟潈琛ㄥ苟涓斾娇鐢mysqlaccess鑴氭湰妫鏌ヤ綘鐨勪慨鏀规槸鍚︽湁濡傛湡鐨勬晥鏋溿傚綋浣犲浣犵殑鏀瑰彉婊℃剰鏃讹紝鎵цmysqladmin flush-privileges鍛婅瘔mysqld鏈嶅姟鍣ㄥ紑濮嬩娇鐢ㄦ柊鐨 鎺堟潈琛ㄣ傦紙鍐嶆瑁呭叆鎺堟潈琛ㄨ鐩栦簡--skip-grant-tables閫夐」銆傝繖鍏佽浣犲憡璇夋湇鍔″櫒寮濮嬩娇鐢ㄦ巿鏉冭〃锛岃屼笉鐢ㄥ仠鎺夊苟閲嶅惎瀹冿級銆

         濡傛灉浠讳綍鍏跺畠浜嬫儏澶辫触锛岀敤璋冭瘯閫夐」(渚嬪锛--debug=d,general,query)鍚姩mysqld鏈嶅姟鍣ㄣ傝繖灏嗘墦鍗版湁鍏冲皾璇曡繛鎺ョ殑涓绘満鍜岀敤鎴蜂俊鎭紝鍜屽彂鍑虹殑姣忎釜鍛戒护鐨勪俊鎭傝鍙傝E.1.2鑺傦紝鈥滃垱寤鸿窡韪枃浠垛

         濡傛灉浣犳湁浠讳綍涓MySQL鎺堟潈琛ㄧ殑鍏跺畠闂锛岃屼笖瑙夊緱浣犲繀椤诲皢杩欎釜闂鍙戦佸埌閭欢琛紝涓瀹氳鎻愪緵涓涓MySQL鎺堟潈琛ㄧ殑鍊惧掑壇鏈(dump)銆備綘鍙敤mysqldump mysql鍛戒护澶嶅埗鏁版嵁搴撹〃銆傝薄骞虫椂涓鏍凤紝鐢mysqlbug鑴氭湰閭瘎浣犵殑闂銆傚弬瑙1.7.1.3鑺傦紝鈥滃浣曢氭姤缂洪櫡鍜岄棶棰樷銆傚湪涓浜涙儏鍐典笅鍙互鐢--skip-grant-tables閲嶅惎mysqld浠ヤ究鑳借繍琛mysqldump


 

5.7.9. MySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊

MySQL鐢ㄦ埛璐︽埛鍒椾簬mysql鏁版嵁搴撲腑鐨user琛ㄥ唴銆傛瘡涓MySQL璐︽埛鎸囧畾涓涓瘑鐮侊紝灏界淇濆瓨鍦userPassword鍒楃殑瀵嗙爜涓嶆槸鏄庢枃锛屼絾鍝堝笇鍊兼槸浠庤〃涓殑璁板綍璁$畻鐨勩傜敤PASSWORD()鍑芥暟鏉ヨ绠楀瘑鐮佺殑鍝堝笇鍊笺

MySQL鍦ㄥ鎴风/鏈嶅姟鍣ㄩ氫俊鐨勪袱涓樁娈典娇鐢ㄥ瘑鐮侊細

         濡傛灉瀹㈡埛绔瘯鍥捐繛鎺ユ湇鍔″櫒锛屾湁涓涓垵濮嬮壌瀹氭楠わ紝瀹㈡埛蹇呴』鎻愪緵涓涓瘑鐮侊紝骞朵笖蹇呴』涓庡鎴锋兂瑕佷娇鐢ㄧ殑璐︽埛鍦user琛ㄤ繚瀛樼殑鍝堝笇鍊煎尮閰嶃

         瀹㈡埛绔繛鎺ュ悗锛屽畠鍙互(濡傛灉鏈夊厖鍒嗙殑鏉冮檺) 璁剧疆鎴栨洿鏀user琛ㄥ唴鎵鍒楃殑璐︽埛鐨勫瘑鐮佸搱甯屽煎笺傚鎴风鍙互閫氳繃PASSWORD()鍑芥暟鏉ョ敓鎴愬瘑鐮佸搱甯屽硷紝鎴栦娇鐢GRANTSET PASSWORD璇彞銆

鎹㈠彞璇濊锛屽綋瀹㈡埛绔娆¤瘯鍥捐繛鎺ユ椂锛屾湇鍔″櫒浣跨敤鍝堝笇鍊艰繘琛岄壌瀹氥傚鏋滆繛鎺ョ殑瀹㈡埛绔皟鐢PASSWORD()鍑芥暟鎴栦娇鐢GRANTSET璇彞鏉ヨ缃垨鏇存敼瀵嗙爜锛屽垯鏈嶅姟鍣浜х敓鍝堝笇鍊笺

MySQL 4.1涓瘑鐮佸搱甯岀畻娉曞凡缁忔洿鏂帮紝鎻愪緵浜嗘洿濂界殑瀹夊叏鎬у苟闄嶄綆浜嗗瘑鐮佽鎴彇鐨勯闄┿備絾鏄紝璇ユ柊鏈哄埗鍙兘鍦MySQL 4.1(鍜屾洿鏂扮増鏈殑)鏈嶅姟鍣ㄥ拰瀹㈡埛绔腑浣跨敤锛屼細浜х敓涓浜涘吋瀹规ч棶棰樸4.1鎴栨柊瀹㈡埛绔彲浠ヨ繛鎺4.1涔嬪墠鐨勬湇鍔″櫒锛屽洜涓哄鎴风鍙互鍚屾椂鐞嗚В鏃х殑鍜屾柊鐨勫瘑鐮佸搱甯屾満鍒躲備絾鏄紝4.1涔嬪墠鐨勫鎴风璇曞浘杩炴帴4.1鐗堟垨鏇存柊鐗堢殑鏈嶅姟鍣ㄦ椂浼氶亣鍒板洶闅俱備緥濡傦紝3.23mysql瀹㈡埛绔瘯鍥捐繛鎺5.1鏈嶅姟鍣ㄦ椂浼氬け璐ュ苟鍑虹幇涓嬮潰鐨勯敊璇秷鎭細

shell> mysql -h localhost -u root
Client does not support authentication protocol requested
by server; consider upgrading MySQL client

鍑虹幇璇ラ棶棰樼殑鍙︿竴涓櫘閫氫緥瀛愭槸鍦ㄥ崌绾у埌MySQL 4.1鎴栨洿鏂扮増鍚庯紝璇曞浘浣跨敤鏃х増鏈殑PHP mysql鎵╁睍鍚嶃(鍙傝25.3.1鑺傦紝鈥滀娇鐢∕ySQL鍜孭HP鐨勫父瑙侀棶棰樷

涓嬮潰璁ㄨ浜嗘柊銆佹棫瀵嗙爜鏈哄埗涔嬮棿鐨勫樊鍒紝浠ュ強濡傛灉浣犲崌绾т簡鏈嶅姟鍣ㄤ絾闇瑕佷负4.1鐗堜互鍓嶇殑瀹㈡埛绔繚鎸佸悜鍚庡吋瀹规ц鎬庢牱鍋氥A.2.3鑺傦紝鈥滃鎴风涓嶆敮鎸侀壌瀹氬崗璁涓湁鏇磋缁嗙殑淇℃伅銆傝淇℃伅灏MySQL鏁版嵁搴撲粠4.0鐗堟湰鎴栨洿浣庣増鍗囩骇鍒4.1鐗堟垨鏇撮珮鐗堢殑PHP缂栫▼浜哄憳鐗瑰埆閲嶈銆

閲婏細璇ヨ璁哄姣斾簡4.1鐗堢殑琛屼负鍜4.1鍓嶇殑琛屼负锛岃繖鍎挎弿杩扮殑4.1涓殑琛屼负瀹為檯涓婁粠4.1.1寮濮嬨MySQL 4.1.0鏄竴涓滄棫鈥濈殑鍙戝竷锛屽洜涓哄畠鐨勫疄鏂芥満鍒朵笌4.1.1鐗堝拰鏇存柊鐗堜腑鐨勭◢鏈変笉鍚屻傚湪MySQL 5.0 鍙傝冩墜鍐屼腑璇︾粏鎻忚堪浜4.1.0鍜屾渶鏂扮増涔嬮棿鐨勫樊鍒

MySQL 4.1涔嬪墠,PASSWORD()鍑芥暟璁$畻鐨勫瘑鐮佸搱甯屽兼湁16涓瓧鑺傞暱銆傚簲涓猴細

mysql> SELECT PASSWORD('mypass');
+--------------------+
| PASSWORD('mypass') |
+--------------------+
| 6f8c114b58f2ce9e   |
+--------------------+

MySQL 4.1涔嬪墠锛user琛ㄧ殑Password(淇濆瓨浜嗗搱甯屽)涔熸槸16瀛楄妭闀裤

MySQL 4.1,宸茬粡瀵PASSWORD()鍑芥暟杩涜浜嗕慨鏀癸紝鍙互鐢熸垚41瀛楄妭鐨勫搱甯屽硷細

mysql> SELECT PASSWORD('mypass');
+-------------------------------------------+
| PASSWORD('mypass')                        |
+-------------------------------------------+
| *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 |
+-------------------------------------------+

鍚屾牱锛user琛ㄧ殑Password鍒楀繀椤绘湁41瀛楄妭闀挎潵淇濆瓨杩欎簺鍊硷細

         濡傛灉浣犳柊瀹夎MySQL 5.1, Password鍒楄嚜鍔ㄤ负41瀛楄妭闀裤

         MySQL 4.1(4.1.14.1绯诲垪鐨勬洿鏂扮増)鍗囩骇鍒MySQL 5.1锛屽簲涓嶄細鍑虹幇鐩稿叧闂锛屽洜涓轰袱涓増鏈娇鐢ㄧ浉鍚岀殑瀵嗙爜鍝堝笇鏈哄埗銆傚鏋滀綘鎯宠灏嗘洿鏃╃増鏈殑MySQL鍗囩骇鍒MySQL5.1,浣犲簲鍏堝崌绾у埌4.1锛岀劧鍚庡皢4.1鍗囩骇鍒5.1

鍔犲鐨Password鍒楀彲浠ュ悓鏃朵繚瀛樻柊銆佹棫鏍煎紡鐨勫瘑鐮佸搱甯屽笺傚彲浠ユ湁涓ょ鏂瑰紡纭畾浠讳綍缁欏畾鏍煎紡鐨勫瘑鐮佸搱甯屽硷細

         鏄庢樉鐨勪笉鍚屼箣澶勬槸闀垮害(16瀛楄妭鍜41瀛楄妭)

         2涓笉鍚屼箣澶勬槸鏂版牸寮忕殑瀵嗙爜鍝堝笇鍊奸兘浠モ*鈥欏瓧绗﹀紑澶达紝鑰屾棫鏍煎紡鐨勫瘑鐮佺粷瀵逛笉鏄

 闀垮瘑鐮佸搱甯屽煎叿鏈夋洿濂界殑鍔犲瘑灞炴э紝骞朵笖瀹㈡埛绔牴鎹暱鍝堝笇鍊艰繘琛岄壌瀹氭瘮鏃х殑鐭搱甯屽兼洿鍔犲畨鍏ㄣ

鐭瘑鐮佸搱甯屽煎拰闀垮瘑鐮佸搱甯屽间箣闂寸殑涓嶅悓涔嬪涓庢湇鍔″櫒濡備綍浣跨敤瀵嗙爜杩涜閴村畾浠ュ強濡備綍涓烘墽琛屽瘑鐮佹洿鏀规搷浣滅殑杩炴帴鐨勫鎴风鐢熸垚瀵嗙爜鍝堝笇鍊奸兘鏈夊叧銆

鏈嶅姟鍣ㄤ娇鐢ㄥ瘑鐮佸搱甯屽艰繘琛岄壌瀹氱殑鏂瑰紡鍙Password鍒楃殑瀹藉害褰卞搷锛

         濡傛灉鍒楄緝鐭紝鍙敤鐭搱甯岄壌瀹氥

         濡傛灉鍒楄緝闀匡紝鍙互鏈夌煭鎴栭暱鍝堝笇鍊硷紝骞朵笖鏈嶅姟鍣ㄥ彲浠ヤ娇鐢ㄤ换浣曚竴绉嶆牸寮忥細

o        4.1涔嬪墠鐨勫鎴风鍙互杩炴帴锛屽畠浠彧鍙互浣跨敤鏃х殑鍝堝笇鏈哄埗锛屽畠浠彲浠ュ彧閴村畾鏈夌煭鍝堝笇鐨勮处鎴枫

o        4.1鍙婁互鍚庣増鏈殑瀹㈡埛绔彲浠ラ壌瀹氭湁鐭搱甯屾垨闀垮搱甯岀殑璐︽埛銆

瀵逛簬鐭搱甯岃处鎴风殑閴村畾杩囩▼锛4.1鍜屼互鍚庣増鏈殑瀹㈡埛绔瘮涓烘棫鐗堟湰鐨勫鎴风瀹為檯瑕佸畨鍏ㄥ緱澶氥備粠瀹夊叏鎬ц搴︼紝浠庢渶浣庡畨鍏ㄥ埌鏈瀹夊叏鐨勬搴︿负锛

         4.1涔嬪墠鐨勫鎴风鐢ㄧ煭瀵嗙爜鍝堝笇鍊艰繘琛岄壌瀹

         4.1鎴栦互鍚庣増鏈殑瀹㈡埛绔敤鐭瘑鐮佸搱甯屽艰繘琛岄壌瀹

         4.1鎴栦互鍚庣増鏈殑瀹㈡埛绔敤闀垮瘑鐮佸搱甯屽艰繘琛岄壌瀹

鏈嶅姟鍣ㄤ负杩炴帴鐨勫鎴风鐢熸垚瀵嗙爜鍝堝笇鍊肩殑鏂瑰紡鍙Password鍒楀搴﹀拰--old-passwords閫夐」鐨勫奖鍝嶃4.1鎴栨洿鏂扮増鏈殑鏈嶅姟鍣ㄥ彧鏈夋弧瓒虫煇涓潯浠舵墠鐢熸垚闀垮搱甯岋細Password鍒楀繀椤昏冻澶熷浠ュ绾抽暱鍝堝笇鍊煎苟涓旀湭缁欏畾--old-passwords閫夐」銆傝繖浜涙潯浠堕傚悎锛

         Password鍒楀繀椤昏冻澶熷浠ュ绾抽暱鍝堝笇(41瀛楄妭)鍊笺傚鏋滃垪娌℃湁鏇存柊锛屼粛鐒朵负4.1涔嬪墠鐨16瀛楄妭瀹斤紝褰撳鎴风浣跨敤PASSWORD()GRANTSET PASSWORD鎵ц瀵嗙爜鏇存敼鎿嶄綔鏃讹紝鏈嶅姟鍣ㄦ敞鎰忓埌闀垮搱甯屼笉閫傚悎锛屽彧鐢熸垚鐭搱甯屻傚鏋滀綘宸茬粡鍗囩骇鍒4.1浣嗚繕娌℃湁杩愯 mysql_fix_privilege_tables鑴氭湰鏉ユ墿瀹Password鍒楁椂浼氬嚭鐜拌繖绉嶈涓恒

         濡傛灉Password鍒楄冻澶熷锛屽垯鍙互淇濆瓨鐭垨闀垮瘑鐮佸搱甯屽笺傚湪杩欑鎯呭喌涓嬶紝PASSWORD()GRANTSET PASSWORD鐢熸垚闀垮搱甯岋紝闄ら潪 鐢--old-passwords閫夐」鍚姩鏈嶅姟鍣ㄣ傝閫夐」寮哄埗鏈嶅姟鍣ㄧ敓鎴愮煭瀵嗙爜鍝堝笇鍊笺

--old-passwords閫夐」鐨勭洰鐨勬槸褰撴湇鍔″櫒鐢熸垚闀垮瘑鐮佸搱甯屽兼椂锛屽厑璁镐綘缁存寔鍚4.1涔嬪墠鐨勫鎴风鐨勫悜鍚庡吋瀹规с傝閫夐」涓嶅奖鍝嶉壌瀹(4.1鍜屼互鍚庣増鏈殑瀹㈡埛绔粛鐒跺彲浠ヤ娇鐢ㄦ湁闀垮瘑鐮佸搱甯屽肩殑璐︽埛)锛屼絾瀹冮槻姝㈠湪瀵嗙爜鏇存敼鎿嶄綔涓湪user琛ㄤ腑鍒涘缓闀垮瘑鐮佸搱甯屽笺傚湪杩欑鎯呭喌涓嬶紝璇ヨ处鎴蜂笉鑳藉啀鐢ㄤ簬4.1涔嬪墠鐨勫鎴风銆傛病鏈--old-passwords閫夐」锛屽彲鑳戒細鍑虹幇涓嬮潰鐨勪笉鏈熸湜鐨勬儏鍐碉細

         鏃у鎴风杩炴帴鏈夌煭瀵嗙爜鍝堝笇鍊肩殑璐︽埛銆

         瀹㈡埛鏇存敼鑷繁鐨勫瘑鐮併傛病鏈--old-passwords锛屽彲浠ヤ负璇ヨ处鎴风敓鎴愰暱瀵嗙爜鍝堝笇鍊笺

         涓嬫鏃у鎴疯瘯鍥捐繛鎺ヨ处鎴锋椂涓嶈兘杩炴帴涓婏紝鍥犱负璐︽埛鏈夐暱瀵嗙爜鍝堝笇鍊硷紝闇瑕佹柊鐨勫搱甯屾満鍒惰繘琛岄壌瀹氥(涓鏃﹁处鎴user琛ㄤ腑涓洪暱瀵嗙爜鍝堝笇鍊硷紝鍙湁4.1鍜屼互鍚庣増鏈殑瀹㈡埛绔彲浠ラ壌瀹氬畠锛屽洜涓4.1涔嬪墠鐨勫鎴风涓嶇悊瑙i暱鍝堝笇锛

璇ュ満鏅鏄庯紝濡傛灉浣犲繀椤绘敮鎸佹棫鐨4.1涔嬪墠鐨勫鎴风锛屼笉浣跨敤--old-passwords閫夐」杩愯4.1鎴栨洿鏂扮増鏈殑鏈嶅姟鍣ㄥ緢鍗遍櫓銆傜敤--old-passwords杩愯鏈嶅姟鍣紝瀵嗙爜鏇存敼鎿嶄綔涓嶄細鐢熸垚闀垮瘑鐮佸搱甯屽硷紝杩欐牱鏃у鎴风涔熷彲浠ヨ闂处鎴枫(杩欎簺瀹㈡埛绔笉鑳芥剰澶栧湴鍥犳洿鏀逛簡瀵嗙爜灏嗚嚜宸遍攣鍑哄幓锛屽苟鐣欎笅闀垮瘑鐮佸搱甯屽硷級

--old-passwords閫夐」鐨勪笉鍒╀箣澶勬槸浣犲垱寤烘垨鏇存敼鐨勫瘑鐮佷娇鐢ㄧ煭鍝堝笇锛岀敋鑷冲浜4.1瀹㈡埛绔篃濡傛銆傝繖鏍凤紝浣犱涪澶变簡闀垮瘑鐮佸搱甯屽兼彁渚涚殑瀹夊叏鎬с傚鏋滀綘鎯宠鍒涘缓鏈夐暱鍝堝笇鐨勮处鎴(渚嬪锛屼负4.1瀹㈡埛绔)锛屼綘蹇呴』涓嶄娇鐢--old-passwords鏉ヨ繍琛屾湇鍔″櫒銆

涓嬮潰鐨勫満鏅彲鐢ㄤ簬杩愯4.1鎴栦互鍚庣殑鏈嶅姟鍣紝鍖呮嫭MySQL 5.1

鍦烘櫙1user琛ㄤ腑鐨勭煭Password鍒楋細

         鍙湁鐭搱甯屽彲浠ヤ繚瀛樺埌Password鍒椼

         鏈嶅姟鍣ㄥ彧浣跨敤鐭搱甯岃繘琛屽鎴风閴村畾銆

         瀵逛簬杩炴帴鐨勫鎴风锛岃皟鐢PASSWORD()GRANTSET PASSWORD鐨勫瘑鐮佸搱甯岀敓鎴愭搷浣滀笓浣跨敤鐭搱甯屻傚璐︽埛鐨勪换浣曟洿鏀瑰潎浼氱敓鎴愮煭瀵嗙爜鍝堝笇鍊笺

          --old-passwords閫夐」鍙互浣跨敤浣嗘槸澶氫綑锛屽洜涓Password鍒楄緝鐭紝鏈嶅姟鍣ㄥ彧鐢熸垚鐭瘑鐮佸搱甯屽笺

鍦烘櫙2Password鍒楋紱娌℃湁鐢--old-passwords閫夐」鍚姩鏈嶅姟鍣細

         鐭垨闀垮搱甯屽彲浠ヤ繚瀛樺埌Password鍒椼

         4.1鍜屼互鍚庣増鏈殑瀹㈡埛绔(鍖呮嫭5.1瀹㈡埛绔)鍙互閴村畾鏈夌煭鎴栭暱鍝堝笇鐨勮处鎴枫

         4.1涔嬪墠鐨勫鎴风鍙兘閴村畾鏈夌煭鍝堝笇鐨勮处鎴枫

         瀵逛簬杩炴帴鐨勫鎴风锛岃皟鐢PASSWORD()GRANTSET PASSWORD鐨勫瘑鐮佸搱甯岀敓鎴愭搷浣滀笓浣跨敤鐭搱甯屻傚璐︽埛鐨勪换浣曟洿鏀瑰潎浼氱敓鎴愮煭瀵嗙爜鍝堝笇鍊笺

濡傚墠闈㈡墍绀猴紝璇ュ満鏅殑鍗遍櫓鎬у湪浜4.1涔嬪墠鐨勫鎴风鍙兘涓嶈兘璁块棶鏈夌煭瀵嗙爜鍝堝笇鍊肩殑璐︽埛銆傞氳繃PASSWORD()GRANTSET PASSWORDA瀵硅繖浜涜处鎴峰瘑鐮佺殑鏇存敼浼氫骇鐢熼暱鐨勫瘑鐮佸搱甯屽笺備粠璇ョ偣鐪嬶紝4.1涔嬪墠鐨勫鎴风鍗囩骇鍒4.1涔嬪墠涓嶈兘閴村畾璇ヨ处鎴枫

瑕佸鐞嗚闂锛屽彲浠ョ敤鐗规畩鏂规硶鏇存敼瀵嗙爜銆備緥濡傦紝涓鑸儏鍐典綘鍙互浣跨敤SET PASSWORD鎸夌収涓嬮潰鐨勬柟娉曟洿鏀硅处鎴峰瘑鐮侊細

mysql> SET PASSWORD FOR 'some_user'@'some_host' = PASSWORD('mypass');

瑕佹兂鏇存敼瀵嗙爜浣嗗垱寤虹煭鍝堝笇锛屼娇鐢OLD_PASSWORD()鍑芥暟锛

mysql> SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('mypass');

褰撲綘鎯虫槑鏄剧敓鎴愮煭鍝堝笇鏃OLD_PASSWORD()寰堟湁鐢ㄣ

鍦烘櫙3Password鍒楋紱鐢--old-passwords閫夐」鍚姩4.1鎴栨柊鐗堟湰鐨勬湇鍔″櫒锛

         鐭垨闀垮搱甯屽彲浠ヤ繚瀛樺埌Password鍒椼

         4.1鍜屼互鍚庣増鏈殑瀹㈡埛绔彲浠ラ壌瀹氭湁鐭垨闀垮搱甯岀殑璐︽埛(璇锋敞鎰忓彧鏈変笉浣跨敤--old-passwords閫夐」鍚姩鏈嶅姟鍣紝鏂瑰彲浠ュ垱寤洪暱鍝堝笇)

         4.1涔嬪墠鐨勫鎴风鍙彲浠ラ壌瀹氱煭鍝堝笇璐︽埛銆

         瀵逛簬杩炴帴鐨勫鎴风锛岃皟鐢PASSWORD()GRANTSET PASSWORD鐨勫瘑鐮佸搱甯岀敓鎴愭搷浣滀笓浣跨敤鐭搱甯屻傚璐︽埛鐨勪换浣曟洿鏀瑰潎浼氱敓鎴愮煭瀵嗙爜鍝堝笇鍊笺

鍦ㄨ鍦烘櫙涓紝浣犱笉鑳藉垱寤洪暱瀵嗙爜鍝堝笇鍊肩殑璐︽埛锛屽洜涓--old-passwords閫夐」闃叉鐢熸垚闀垮搱甯屻傚苟涓旓紝濡傛灉浣犲湪浣跨敤--old-passwords閫夐」鍓嶅垱寤洪暱鍝堝笇璐︽埛锛屽綋--old-passwords鏈夋椂鏇存敼璐︽埛瀵嗙爜锛岀粨鏋滀細浣胯处鎴风殑瀵嗙爜涓虹煭瀵嗙爜锛屽畨鍏ㄦц緝闀垮搱甯岃闄嶄綆銆

杩欎簺鍦烘櫙鐨勪笉鍒╀箣澶勫彲浠ユ鎷负锛

鍦ㄥ満鏅1,浣犱笉鑳藉埄鐢ㄩ暱鍝堝笇鎻愪緵鏇村畨鍏ㄧ殑閴村畾銆

鍦ㄥ満鏅2, 濡傛灉浣犳病鏈夋樉寮忎娇鐢OLD_PASSWORD()鏉ユ洿鏀瑰瘑鐮侊紝鍒4.1涔嬪墠鐨勫鎴风涓嶈兘鍐嶈闂煭鍝堝笇璐︽埛銆

鍦ㄥ満鏅3,--old-passwords闃叉鐭搱甯岃处鎴蜂笉鍙闂紝浣嗗瘑鐮佹洿鏀规搷浣滀娇璐︽埛鐨勯暱鍝堝笇杞崲涓虹煭鍝堝笇锛屽綋--old-passwords鏈夋晥鏃朵笉鑳藉皢瀹冩敼鍥為暱鍝堝笇銆

5.7.9.1. 鏇存敼搴旂敤绋嬪簭瀵嗙爜鍝堝笇鍊肩殑鍚箟

鍗囩骇鍒MySQL4.1鎴栨洿鏂扮増鏈悗锛屼娇鐢PASSWORD()涓鸿嚜宸辩殑鐩殑鐢熸垚瀵嗙爜鐨勫簲鐢ㄧ▼搴忎細鍑虹幇鍏煎鎬ч棶棰樸傚簲鐢ㄧ▼搴忓疄闄呬笉搴旇繖鏍峰仛锛屽洜涓PASSWORD()鍙簲鐢ㄦ潵绠$悊MySQL璐︽埛鐨勫瘑鐮併備絾涓浜涘簲鐢ㄧ▼搴忎娇鐢PASSWORD()鐢ㄤ簬鑷繁鐨勭洰鐨勩

濡傛灉浣犱粠MySQL 4.1涔嬪墠鐨勭増鏈崌绾у埌4.1鎴栦互鍚庣増鏈紝骞跺湪鐢熸垚闀垮瘑鐮佸搱甯屽肩殑鏉′欢涓嬭繍琛屾湇鍔″櫒锛屽簲鐢ㄧ▼搴忎娇鐢PASSWORD()鐮磋В鑷繁鐨勫瘑鐮併傝繖绉嶆儏鍐典笅鎺ㄨ崘鐨勬柟娉曟槸淇敼搴旂敤绋嬪簭锛屼娇鐢ㄥ叾瀹冨嚱鏁帮紝渚嬪SHA1()MD5()锛屾潵浜х敓鍝堝笇鍊笺傚鏋滀笉琛岋紝浣犲彲浠ヤ娇鐢OLD_PASSWORD()鍑芥暟锛岃鍑芥暟鐢ㄦ潵鎻愪緵鏃ф牸寮忕殑鐭搱甯屻備絾鏄紝璇锋敞鎰OLD_PASSWORD()鍙兘鏈変竴澶╀笉鍐嶈鏀寔銆

濡傛灉鏈嶅姟鍣ㄨ繍琛屽湪鐢熸垚鐭搱甯岀殑鏉′欢涓嬶紝鍙互浣跨敤 OLD_PASSWORD()浣嗕笌PASSWORD()绛夊悓銆

MySQL鏁版嵁搴撲粠4.0鎴栨洿浣庣増鏈Щ妞嶅埌4.1鎴栨洿楂樼増鏈殑PHP缂栫▼浜哄憳搴斿弬闃鏃у鎴风

5.8. MySQL鐢ㄦ埛璐︽埛绠$悊

鏈妭鎻忚堪濡備綍涓MySQL鏈嶅姟鍣ㄧ殑瀹㈡埛绔缃处鎴枫傝璁轰簡涓嬮潰鐨勪富棰橈細

         MySQL浣跨敤鐨勮处鎴峰悕鍜屽瘑鐮佺殑鍚箟锛屼互鍙婂浣曟瘮杈冧綘鐨勬搷浣滅郴缁熸墍浣跨敤鐨勮处鎴峰悕鍜屽瘑鐮

         濡備綍璁剧疆鏂拌处鎴峰苟绉婚櫎宸叉湁璐︽埛

         濡備綍鏇存敼瀵嗙爜

         瀹夊叏浣跨敤瀵嗙爜鎸囧

         濡備綍浣跨敤瀹夊叏SSL杩炴帴

5.8.1. MySQL鐢ㄦ埛鍚嶅拰瀵嗙爜

鐢ㄧ敤鎴峰悕鍜屽鎴风鎴栦富鏈哄畾涔MySQL璐︽埛锛岀敤鎴峰彲浠ユ牴鎹繖浜涘悕绉版潵杩炴帴鏈嶅姟鍣ㄣ傝处鎴蜂篃鏈夊瘑鐮併MySQL鍜屾搷浣滅郴缁熶娇鐢ㄧ敤鎴峰悕鍜屽瘑鐮佺殑鏂瑰紡鏈夊嚑澶勫尯鍒細

         MySQL鐢ㄤ簬閴村畾鐩殑鐢ㄦ埛鍚嶄笌WindowsUnix浣跨敤鐨勭敤鎴峰悕(鐧诲綍鍚)娌℃湁鍏崇郴銆傚湪Unix涓紝澶у鏁MySQL瀹㈡埛绔粯璁よ瘯鍥句娇鐢ㄥ綋鍓Unix鐨勭敤鎴峰悕浣滀负MySQL鐢ㄦ埛鍚嶆潵鐧诲綍锛屼絾杩欐牱鍙槸涓轰簡鏂逛究銆 榛樿鍊煎彲浠ュ緢瀹规槗琚鐩栵紝鍥犱负瀹㈡埛绔▼搴忓厑璁哥敤-u--user閫夐」鏉ユ寚瀹氱敤鎴峰悕銆傚洜涓鸿繖琛ㄧず浠讳綍浜哄彲浠ヨ瘯鍥句娇鐢ㄤ换浣曠敤鎴峰悕鏉ヨ繛鎺ユ湇鍔″櫒锛岄櫎闈炴墍鏈MySQL璐︽埛鏈夊瘑鐮侊紝鍚﹀垯浣犱笉鑳戒娇鏁版嵁搴撲繚鎸佸畨鍏ㄣ傞氳繃涓烘病鏈夊瘑鐮佺殑璐︽埛鎸囧畾鐢ㄦ埛鍚嶏紝浠讳綍浜鸿兘澶熸垚鍔熻繛鎺ユ湇鍔″櫒銆

         MySQL鐢ㄦ埛鍚嶆渶澶у杈16瀛楃闀裤傝繖鏍峰彲浠ラ檺鍒MySQL鏈嶅姟鍣ㄥ拰瀹㈡埛绔箣闂寸殑纭紪鐮侊紝骞朵笖闃叉閫氳繃淇敼mysql鏁版嵁搴撲腑琛ㄧ殑瀹氫箟鏉ュ伔绐冨瘑鐮併

:搴旂粷瀵逛笉瑕佷互浠讳綍鏂瑰紡淇敼mysql鏁版嵁搴撲腑鐨勪换浣曡〃锛屽彧鑳借繍琛MySQL鍒嗗彂涓笓涓烘鐩殑鎻愪緵鐨勮剼鏈傚皢MySQL绯荤粺琛ㄩ噸鏂板畾涔変负鍏跺畠鏂瑰紡浼氬鑷存湭瀹氫箟鐨(鍜屼笉鏀寔鐨!)琛屼负

鎿嶄綔绯荤粺鐢ㄦ埛鍚嶄笌MySQL鐢ㄦ埛鍚嶅畬鍏ㄤ笉鐩稿叧锛岀敋鑷虫渶澶ч暱搴﹀彲鑳戒笉鍚屻備緥濡傦紝 Unix鐢ㄦ埛鍚嶉檺鍒朵负8涓瓧绗︺

         MySQL瀵嗙爜涓庣櫥褰曞埌浣犵殑鎿嶄綔绯荤粺鐨勫瘑鐮佹病鏈夊叧绯汇備笉闇瑕佸皢浣犵敤鏉ョ櫥褰WindowsUnix鏈哄櫒鐨勫瘑鐮佸拰浣犵敤鏉ヨ闂鏈哄櫒涓婄殑MySQL鏈嶅姟鍣ㄧ殑瀵嗙爜鍏宠仈璧锋潵銆

         MySQL鐨勫姞瀵嗗瘑鐮佷娇鐢ㄨ嚜宸辩殑绠楁硶銆傝鍔犲瘑绠楁硶涓嶅悓浜Unix鐧诲綍杩囩▼浣跨敤鐨勭畻娉曘MySQL瀵嗙爜鍔犲瘑涓PASSWORD()SQL鍑芥暟鐨勬柟娉曠浉鍚屻Unix瀵嗙爜鍔犲瘑涓ENCRYPT()SQL鍑芥暟鐨勬柟娉曠浉鍚屻PASSWORD()ENCRYPT()鍑芥暟鐨勬弿杩板弬瑙12.9.2鑺傦紝鈥滃姞瀵嗗嚱鏁扳銆備粠鐗堟湰4.1 璧凤紝MySQL浣跨敤鏇村己鐨勯壌瀹氭柟娉曪紝鍚屼互鍓嶇殑鐗堟湰鐩告瘮鍙互鍦ㄨ繛鎺ヨ繃绋嬩腑鎻愪緵鏇村ソ鐨勫瘑鐮佷繚鎶ゃ傚嵆浣TCP/IP鍖呰鎴彇鎴mysql鏁版嵁搴撹鎹曡幏涔熷緢瀹夊叏銆(鍦ㄥ墠闈㈢殑鐗堟湰涓紝鍗充娇瀵嗙爜浠ュ姞瀵嗗舰寮忎繚瀛樺埌user琛ㄤ腑锛屼粛鍙互閫氳繃鍔犲瘑瀵嗙爜鍊兼潵杩炴帴MySQL鏈嶅姟鍣級

褰撳畨瑁MySQL鏃讹紝鎺堟潈琛ㄨ杞芥椂鏈変竴绯诲垪鍒濅娇璐︽埛銆傝繖浜涜处鎴风殑鍚嶇О鍜岃闂潈闄愯2.9.3鑺傦紝鈥滀娇鍒濆MySQL璐︽埛瀹夊叏鈥锛屽叾涓繕璁ㄨ浜嗗浣曟湭杩欎簺璐︽埛璧嬩簣瀵嗙爜銆傚洜姝わ紝浣犱竴鑸簲浣跨敤GRANTREVOKE璇彞鏉ヨ缃佷慨鏀瑰拰绉婚櫎MySQL璐︽埛銆傚弬瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥

褰撶敤鍛戒护琛屽鎴风杩炴帴MySQL鏈嶅姟鍣ㄦ椂锛屼綘搴斾负鎯宠浣跨敤鐨勮处鎴锋寚瀹氱敤鎴峰悕鍜屽瘑鐮侊細

shell> mysql --user=monty --password=guess db_name

濡傛灉浣犳兂鐢ㄨ緝鐭殑閫夐」锛屽懡浠ゅ簲涓猴細

shell> mysql -u monty -pguess db_name

-p閫夐」鍜屽悗闈㈢殑瀵嗙爜鍊间箣闂寸粷瀵逛笉鑳芥湁绌烘牸銆傚弬瑙5.7.4鑺傦紝鈥滀笌MySQL鏈嶅姟鍣ㄨ繛鎺モ

鍓嶉潰鐨勫懡浠ゅ寘鎷懡浠よ涓殑瀵嗙爜鍊硷紝浼氬緢鍗遍櫓銆傚弬瑙5.8.6鑺傦紝鈥滀娇浣犵殑瀵嗙爜瀹夊叏鈥銆傝鎯抽伩鍏嶏紝鎸囧畾--password-p閫夐」鍚庨潰涓嶈窡浠讳綍瀵嗙爜鍊硷細

shell> mysql --user=monty --password db_name
shell> mysql -u monty -p db_name

鐒跺悗瀹㈡埛绔▼搴忚緭鍑烘彁绀虹骞剁瓑寰呬綘杈撳叆瀵嗙爜銆(鍦ㄨ繖浜涚ず渚嬩腑锛db_name骞朵笉涓哄瘑鐮侊紝鍥犱负鐢ㄧ┖鏍煎皢瀹冨悓鍓嶉潰鐨勫瘑鐮侀」闅旂寮浜嗭級

鍦ㄤ竴浜涚郴缁熶腑锛MySQL鐢ㄦ潵鎻愮ず杈撳叆瀵嗙爜鐨勫簱璋冪敤鑷姩灏嗗瘑鐮侀檺鍒跺埌8涓瓧绗︺傝繖鏄郴缁熷簱鐨勯棶棰橈紝鑰屼笉鏄MySQL鐨勯棶棰樸MySQL鏈韩骞朵笉闄愬埗瀵嗙爜鐨勯暱搴︺傝瑙e喅璇ラ棶棰橈紝灏MySQL瀵嗙爜鏀逛负8涓瓧绗﹀拰鏇村皯瀛楃鐨勫硷紝鎴栧皢瀵嗙爜鏀惧叆閫夐」鏂囦欢涓

5.8.2. 鍚慚ySQL澧炲姞鏂扮敤鎴疯处鎴

鍙互鐢ㄤ袱绉嶆柟寮忓垱寤MySQL璐︽埛锛

         浣跨敤GRANT璇彞

         鐩存帴鎿嶄綔MySQL鎺堟潈琛

鏈濂界殑鏂规硶鏄娇鐢GRANT璇彞锛屽洜涓鸿繖鏍锋洿绮剧‘锛岄敊璇皯銆備粠MySQL 3.22.11璧锋彁渚涗簡GRANT锛涘叾璇硶瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥

鍒涘缓璐︽埛鐨勫叾瀹冩柟娉曟槸浣跨敤MySQL璐︽埛绠$悊鍔熻兘鐨勭涓夋柟绋嬪簭銆phpMyAdmin鍗虫槸涓涓▼搴忋

涓嬮潰鐨勭ず渚嬭鏄庡浣曚娇鐢MySQL瀹㈡埛绔▼搴忔潵璁剧疆鏂扮敤鎴枫傚亣瀹氭寜鐓2.9.3鑺傦紝鈥滀娇鍒濆MySQL璐︽埛瀹夊叏鈥鎻忚堪鐨 榛樿鍊兼潵璁剧疆鏉冮檺銆傝繖璇存槑涓轰簡鏇存敼锛屼綘蹇呴』浠MySQL root鐢ㄦ埛杩炴帴MySQL鏈嶅姟鍣紝骞朵笖root璐︽埛蹇呴』鏈mysql鏁版嵁搴撶殑INSERT鏉冮檺鍜RELOAD绠$悊鏉冮檺銆

棣栧厛锛屼娇鐢MySQL绋嬪簭浠MySQL root鐢ㄦ埛鏉ヨ繛鎺ユ湇鍔″櫒锛

shell> MySQL --user=root MySQL

濡傛灉浣犱负root璐︽埛鎸囧畾浜嗗瘑鐮侊紝杩橀渶瑕佷负璇MySQL鍛戒护鍜屾湰鑺備腑鐨勫叾瀹冨懡浠ゆ彁渚--password-p閫夐」銆

root杩炴帴鍒版湇鍔″櫒涓婂悗锛屽彲浠ユ坊鍔犳柊璐︽埛銆備笅闈㈢殑璇彞浣跨敤GRANT鏉ヨ缃洓涓柊璐︽埛锛

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';

GRANT璇彞鍒涘缓鐨勮处鎴锋湁涓嬮潰鐨勫睘鎬э細

         鍏朵腑涓や釜璐︽埛鏈夌浉鍚岀殑鐢ㄦ埛鍚monty鍜屽瘑鐮some_pass銆備袱涓处鎴峰潎涓鸿秴绾х敤鎴疯处鎴凤紝鍏锋湁瀹屽叏鐨勬潈闄愬彲浠ュ仛浠讳綍浜嬫儏銆備竴涓处鎴 ('monty'@'localhost')鍙敤浜庝粠鏈満杩炴帴鏃躲傚彟涓涓处鎴('monty'@'%')鍙敤浜庝粠鍏跺畠涓绘満杩炴帴銆傝娉ㄦ剰monty鐨勪袱涓处鎴峰繀椤昏兘浠庝换浣曚富鏈轰互monty杩炴帴銆傛病鏈localhost璐︽埛锛屽綋monty浠庢湰鏈鸿繛鎺ユ椂锛mysql_install_db鍒涘缓鐨localhost鐨勫尶鍚嶇敤鎴疯处鎴峰皢鍗犲厛銆傜粨鏋滄槸锛monty灏嗚瑙嗕负鍖垮悕鐢ㄦ埛銆傚師鍥犳槸鍖垮悕鐢ㄦ埛璐︽埛鐨Host鍒楀兼瘮'monty'@'%'璐︽埛鏇村叿浣擄紝杩欐牱鍦user琛ㄦ帓搴忛『搴忎腑鎺掑湪鍓嶉潰銆(user琛ㄦ帓搴忕殑璁ㄨ鍙傝5.7.5鑺傦紝鈥滆闂帶鍒, 闃舵1锛氳繛鎺ユ牳瀹炩

         涓涓处鎴锋湁鐢ㄦ埛鍚admin锛屾病鏈夊瘑鐮併傝璐︽埛鍙敤浜庝粠鏈満杩炴帴銆傛巿浜堜簡RELOADPROCESS绠$悊鏉冮檺銆傝繖浜涙潈闄愬厑璁admin鐢ㄦ埛鎵цmysqladmin reloadmysqladmin refreshmysqladmin flush-xxx鍛戒护锛屼互鍙mysqladmin processlist銆傛湭鎺堜簣璁块棶鏁版嵁搴撶殑鏉冮檺銆備綘鍙互閫氳繃GRANT璇彞娣诲姞姝ょ被鏉冮檺銆

         涓涓处鎴锋湁鐢ㄦ埛鍚dummy锛屾病鏈夊瘑鐮併傝璐︽埛鍙敤浜庝粠鏈満杩炴帴銆傛湭鎺堜簣鏉冮檺銆傞氳繃GRANT璇彞涓殑USAGE鏉冮檺锛屼綘鍙互鍒涘缓璐︽埛鑰屼笉鎺堜簣浠讳綍鏉冮檺銆傚畠鍙互灏嗘墍鏈夊叏灞鏉冮檺璁句负'N'銆傚亣瀹氫綘灏嗗湪浠ュ悗灏嗗叿浣撴潈闄愭巿浜堣璐︽埛銆

闄や簡GRANT锛屼綘鍙互鐩存帴鐢INSERT璇彞鍒涘缓鐩稿悓鐨勮处鎴凤紝鐒跺悗浣跨敤FLUSH PRIVILEGES鍛婅瘔鏈嶅姟鍣ㄩ噸杞芥巿鏉冭〃锛

shell> mysql --user=root mysql
mysql> INSERT INTO user
    ->     VALUES('localhost','monty',PASSWORD('some_pass'),
    ->     'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO user
    ->     VALUES('%','monty',PASSWORD('some_pass'),
    ->     'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO user SET Host='localhost',User='admin',
    ->     Reload_priv='Y', Process_priv='Y';
mysql> INSERT INTO user (Host,User,Password)
    ->     VALUES('localhost','dummy','');
mysql> FLUSH PRIVILEGES;

褰撲綘鐢INSERT鍒涘缓璐︽埛鏃朵娇鐢FLUSH PRIVILEGES鐨勫師鍥犳槸鍛婅瘔鏈嶅姟鍣ㄩ噸璇绘巿鏉冭〃銆傚惁鍒欙紝鍙湁閲嶅惎鏈嶅姟鍣ㄥ悗鏇存敼鏂逛細琚敞鎰忓埌銆備娇鐢 GRANT锛屽垯涓嶉渶瑕佷娇鐢FLUSH PRIVILEGES

INSERT浣跨敤PASSWORD()鍑芥暟鏄负浜嗗姞瀵嗗瘑鐮併GRANT璇彞涓轰綘鍔犲瘑瀵嗙爜锛屽洜姝や笉闇瑕PASSWORD()

'Y'鍊煎惎鐢ㄨ处鎴锋潈闄愩傚浜admin璐︽埛锛岃繕鍙互浣跨敤鏇村姞鍙鐨INSERT鎵╁厖鐨勮娉曪紙浣跨敤SET锛夈

鍦ㄤ负dummy璐︽埛鐨INSERT璇彞涓紝鍙湁user琛ㄤ腑鐨HostUserPassword鍒楄褰曚负鎸囧畾鐨勫笺傛病鏈変竴涓潈闄愬垪涓烘樉寮忚缃紝鍥犳MySQL灏嗗畠浠潎鎸囧畾涓 榛樿鍊'N'銆傝繖鏍风瓑鍚屼簬GRANT USAGE鐨勬搷浣溿

璇锋敞鎰忚璁剧疆瓒呯骇鐢ㄦ埛璐︽埛锛屽彧闇瑕佸垱寤轰竴涓潈闄愬垪璁剧疆涓'Y'user琛ㄦ潯鐩user琛ㄦ潈闄愪负鍏ㄥ眬鏉冮檺锛屽洜姝ゅ叾瀹 鎺堟潈琛ㄤ笉鍐嶉渶瑕佹潯鐩

涓嬮潰鐨勪緥瀛愬垱寤3涓处鎴凤紝鍏佽瀹冧滑璁块棶涓撶敤鏁版嵁搴撱傛瘡涓处鎴风殑鐢ㄦ埛鍚嶄负custom锛屽瘑鐮佷负obscure

瑕佹兂鐢GRANT鍒涘缓璐︽埛锛屼娇鐢ㄤ笅闈㈢殑璇彞锛

shell> MySQL --user=root MySQL
shell> mysql --user=root mysql
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    ->     ON bankaccount.*
    ->     TO 'custom'@'localhost'
    ->     IDENTIFIED BY 'obscure';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    ->     ON expenses.*
    ->     TO 'custom'@'whitehouse.gov'
    ->     IDENTIFIED BY 'obscure';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    ->     ON customer.*
    ->     TO 'custom'@'server.domain'
    ->     IDENTIFIED BY 'obscure';

3涓处鎴峰彲浠ョ敤浜庯細

         1涓处鎴峰彲浠ヨ闂bankaccount鏁版嵁搴擄紝浣嗗彧鑳戒粠鏈満璁块棶銆

         2涓处鎴峰彲浠ヨ闂expenses鏁版嵁搴擄紝浣嗗彧鑳戒粠涓绘満whitehouse.gov璁块棶銆

         3涓处鎴峰彲浠ヨ闂customer鏁版嵁搴擄紝浣嗗彧鑳戒粠涓绘満server.domain璁块棶銆

瑕佹兂涓嶇敤GRANT璁剧疆custom璐︽埛锛屼娇鐢INSERT璇彞鐩存帴淇敼 鎺堟潈琛細

shell> mysql --user=root mysql
mysql> INSERT INTO user (Host,User,Password)
    ->     VALUES('localhost','custom',PASSWORD('obscure'));
mysql> INSERT INTO user (Host,User,Password)
    ->     VALUES('whitehouse.gov','custom',PASSWORD('obscure'));
mysql> INSERT INTO user (Host,User,Password)
    ->     VALUES('server.domain','custom',PASSWORD('obscure'));
mysql> INSERT INTO db
    ->     (Host,Db,User,Select_priv,Insert_priv,
    ->     Update_priv,Delete_priv,Create_priv,Drop_priv)
    ->     VALUES('localhost','bankaccount','custom',
    ->     'Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db
    ->     (Host,Db,User,Select_priv,Insert_priv,
    ->     Update_priv,Delete_priv,Create_priv,Drop_priv)
    ->     VALUES('whitehouse.gov','expenses','custom',
    ->     'Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db
    ->     (Host,Db,User,Select_priv,Insert_priv,
    ->     Update_priv,Delete_priv,Create_priv,Drop_priv)
    ->     VALUES('server.domain','customer','custom',
    ->     'Y','Y','Y','Y','Y','Y');
mysql> FLUSH PRIVILEGES;
 

3INSERT璇彞鍦user琛ㄤ腑鍔犲叆鏉$洰锛屽厑璁哥敤鎴custom浠庡悇绉嶄富鏈虹敤缁欏畾鐨勫瘑鐮佽繘琛岃繛鎺ワ紝浣嗕笉鎺堜簣鍏ㄥ眬鏉冮檺(鎵鏈夋潈闄愯缃负 榛樿鍊'N')銆傚悗闈3INSERT璇彞鍦user琛ㄤ腑鍔犲叆鏉$洰锛屼负custom鎺堜簣bankaccountexpensescustomer鏁版嵁搴撴潈闄愶紝浣嗗彧鑳戒粠鍚堥傜殑涓绘満璁块棶銆閫氬父鑻ョ洿鎺ヤ慨鏀 鎺堟潈琛紝鍒欏簲鍛婅瘔鏈嶅姟鍣ㄧ敤FLUSH PRIVILEGES閲嶈浇鎺堟潈琛紝浣挎潈闄愭洿鏀圭敓鏁堛

濡傛灉浣犳兂瑕佽鏌愪釜鐢ㄦ埛浠庣粰瀹氬煙鐨勬墍鏈夋満鍣ㄨ闂(渚嬪锛mydomain.com)锛屼綘鍙互鍦ㄨ处鎴峰悕鐨勪富鏈洪儴鍒嗕娇鐢ㄥ惈鈥%鈥欓氶厤绗︾殑GRANT璇彞锛

mysql> GRANT ...
    ->     ON *.*
    ->     TO 'myname'@'%.mydomain.com'
    ->     IDENTIFIED BY 'mypass';

瑕佹兂閫氳繃鐩存帴淇敼鎺堟潈琛ㄦ潵瀹炵幇锛

mysql> INSERT INTO user (Host,User,Password,...)
    ->     VALUES('%.mydomain.com','myname',PASSWORD('mypass'),...);

mysql> FLUSH PRIVILEGES;

5.8.3. 浠嶮ySQL鍒犻櫎鐢ㄦ埛璐︽埛

瑕佹兂绉婚櫎璐︽埛锛屽簲浣跨敤DROP USER璇彞锛岃鍙傝13.5.1.2鑺傦紝鈥淒ROP USER璇硶鈥

5.8.4. 闄愬埗璐︽埛璧勬簮

闄愬埗MySQL鏈嶅姟鍣ㄨ祫婧愪娇鐢ㄧ殑涓涓柟娉曟槸灏max_user_connections绯荤粺鍙橀噺璁剧疆涓洪潪闆跺笺備絾鏄紝璇ユ柟娉曚弗鏍奸檺浜庡叏灞锛屼笉鍏佽绠$悊鍏蜂綋璐︽埛銆傚苟涓旓紝瀹冨彧闄愬埗浣跨敤鍗曚竴璐︽埛鍚屾椂杩炴帴鐨勬暟閲忥紝鑰屼笉鏄鎴风杩炴帴鍚庣殑鎿嶄綔銆傝澶MySQL绠$悊鍛樺涓ょ绫诲瀷鐨勬帶鍒跺潎鎰熷叴瓒o紝鐗瑰埆鏄Internet鏈嶅姟鎻愪緵鑰呫

MySQL 5.1,浣犲彲浠ヤ负鍏蜂綋璐︽埛闄愬埗涓嬮潰鐨勬湇鍔″櫒璧勬簮锛

         璐︽埛姣忓皬鏃跺彲浠ュ彂鍑虹殑鏌ヨ鏁

         璐︽埛姣忓皬鏃跺彲浠ュ彂鍑虹殑鏇存柊鏁

         璐︽埛姣忓皬鏃跺彲浠ヨ繛鎺ユ湇鍔″櫒鐨勬鏁

瀹㈡埛绔彲浠ユ墽琛岀殑璇彞鏍规嵁鏌ヨ闄愬埗鏉ヨ鏁般傚彧鏈変慨鏀规暟鎹簱鎴栬〃鐨勮鍙ユ牴鎹洿鏂伴檺鍒舵潵璁版暟銆

杩樺彲浠ラ檺鍒舵瘡涓处鎴风殑鍚屾椂杩炴帴鏈嶅姟鍣ㄧ殑杩炴帴鏁般

鏈枃涓殑璐︽埛涓user琛ㄤ腑鐨勫崟涓褰曘傛牴鎹UserHost鍒楀煎敮涓璇嗗埆姣忎釜璐︽埛銆

鍋氫负浣跨敤璇ョ壒鎬х殑鍏堝喅鏉′欢锛mysql鏁版嵁搴撶殑user琛ㄥ繀椤诲寘鍚祫婧愮浉鍏崇殑鍒椼傝祫婧愰檺鍒朵繚瀛樺湪max_questionsmax_updatesmax_connectionsmax_user_connections鍒楀唴銆傚鏋user琛ㄦ病鏈夎繖浜涘垪锛屽繀椤诲瀹冭繘琛屽崌绾э紱鍙傝2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥

瑕佹兂鐢GRANT璇彞璁剧疆璧勬簮闄愬埗锛屼娇WITH瀛愬彞鏉ュ懡鍚嶆瘡涓闄愬埗鐨勮祫婧愬拰鏍规嵁姣忓皬鏃惰鏁扮殑闄愬埗鍊笺備緥濡傦紝瑕佹兂鍙互闄愬埗鏂瑰紡鍒涘缓鍙互璁块棶customer鏁版嵁搴撶殑鏂拌处鎴凤紝鎵ц璇ヨ鍙ワ細

mysql> GRANT ALL ON customer.* TO 'francis'@'localhost'
    ->     IDENTIFIED BY 'frank'
    ->     WITH MAX_QUERIES_PER_HOUR 20
    ->          MAX_UPDATES_PER_HOUR 10
    ->          MAX_CONNECTIONS_PER_HOUR 5
    ->          MAX_USER_CONNECTIONS 2;

闄愬埗绫诲瀷涓嶉渶瑕佸叏閮ㄥ湪WITH瀛愬彞涓懡鍚嶏紝浣嗗凡缁忓懡鍚嶇殑鍙互鎸変换浣曢『搴忋傛瘡涓瘡灏忔椂闄愬埗鍊煎潎搴斾负鏁存暟锛屼唬琛ㄦ瘡灏忔椂鐨勮鏁般傚鏋GRANT璇彞娌℃湁WITH瀛愬彞锛屽垯姣忎釜闄愬埗鍊艰缃负 榛樿鍊奸浂(鍗虫病鏈夐檺鍒)銆傚浜MAX_USER_CONNECTIONS锛岄檺鍒朵负鏁存暟锛岃〃绀鸿处鎴蜂竴娆″彲浠ュ悓鏃惰繛鎺ョ殑鏈澶ц繛鎺ユ暟銆傚鏋滈檺鍒惰缃负 榛樿鍊奸浂锛屽垯鏍规嵁MAX_USER_CONNECTIONS绯荤粺鍙橀噺纭畾璇ヨ处鎴峰彲浠ュ悓鏃惰繛鎺ョ殑鏁伴噺銆

瑕佹兂璁剧疆鎴栨洿鏀瑰凡鏈夎处鎴风殑闄愬埗锛屽湪鍏ㄥ眬绾у埆浣跨敤GRANT USAGE璇彞(*.*)銆備笅闈㈢殑璇彞鍙互灏francis鐨勬煡璇㈤檺鍒舵洿鏀逛负100

mysql> GRANT USAGE ON *.* TO 'francis'@'localhost'
    ->     WITH MAX_QUERIES_PER_HOUR 100;

璇ヨ鍙ユ病鏈夋敼鍙樿处鎴风殑宸叉湁鏉冮檺锛屽彧淇敼浜嗘寚瀹氱殑闄愬埗鍊笺

瑕佹兂鍙栨秷宸叉湁闄愬埗锛屽皢璇ュ艰缃负闆躲備緥濡傦紝瑕佹兂鍙栨秷francis姣忓皬鏃跺彲浠ヨ繛鎺ョ殑娆℃暟鐨勯檺鍒讹紝浣跨敤璇ヨ鍙ワ細

mysql> GRANT USAGE ON *.* TO 'francis'@'localhost'
    ->     WITH MAX_CONNECTIONS_PER_HOUR 0;

褰撹处鎴蜂娇鐢ㄨ祫婧愭椂濡傛灉鏈夐潪闆堕檺鍒讹紝鍒欏璧勬簮浣跨敤杩涜璁版暟銆

鏈嶅姟鍣ㄨ繍琛屾椂锛屽畠缁熻姣忎釜璐︽埛浣跨敤璧勬簮鐨勬鏁般傚鏋滆处鎴峰湪鏈鍚庝竴涓皬鏃剁殑杩炴帴娆℃暟杈惧埌闄愬埗锛岃璐︽埛鐨勮繘涓姝ョ殑杩炴帴琚嫆缁濄傜被浼煎湴锛屽鏋滆处鎴疯揪鍒版煡璇㈡垨鏇存柊娆℃暟鐨勯檺鍒讹紝杩涗竴姝ョ殑鏌ヨ鎴栨洿鏂拌鎷掔粷銆傚湪杩欑鎯呭喌涓嬶紝浼氱粰鍑虹浉鍏抽敊璇秷鎭

鏍规嵁姣忎釜璐︽埛杩涜璧勬簮璁$畻锛岃屼笉鏄牴鎹瘡涓鎴风銆備緥濡傦紝濡傛灉浣犵殑璐︽埛鐨勬煡璇㈤檺鍒朵负50,浣犱笉鑳介氳繃涓や釜瀹㈡埛绔悓鏃惰繛鎺ユ湇鍔″櫒灏嗛檺鍒跺鍔犲埌100銆備袱涓繛鎺ョ殑鏌ヨ琚绠楀埌涓璧枫

鍙互涓烘墍鏈夎处鎴蜂粠鍏ㄥ眬閲嶈褰撳墠鐨勬瘡灏忔椂璧勬簮浣跨敤璁版暟锛屾垨鍗曠嫭閲嶈缁欏畾鐨勮处鎴凤細

         瑕佹兂灏嗘墍鏈夎处鎴峰綋鍓嶇殑璁版暟閲嶈涓洪浂锛屽彲浠ユ墽琛FLUSH USER_RESOURCES璇彞銆傝繕鍙互閫氳繃閲嶈浇鎺堟潈琛ㄦ潵閲嶈璁版暟(渚嬪锛屼娇鐢FLUSH PRIVILEGES璇彞鎴mysqladmin reload鍛戒护)

         灏嗗叿浣撹处鎴风殑闄愬埗閲嶆柊鎺堜簣浠讳綍鍊硷紝鍙互灏嗗畠璁剧疆涓洪浂銆傝鎯冲疄鐜帮紝鎸夌収鍓嶉潰鎵杩颁娇鐢GRANT USAGE锛屽苟灏嗛檺鍒跺兼寚瀹氫负璇ヨ处鎴峰綋鍓嶇殑闄愬埗鍊笺

璁℃暟鍣ㄩ噸璁句笉褰卞搷MAX_USER_CONNECTIONS闄愬埗銆

褰撴湇鍔″櫒鍚姩鏃舵墍鏈夎鏁颁粠闆跺紑濮嬨

5.8.5. 璁剧疆璐︽埛瀵嗙爜

  • 鍙互鐢mysqladmin鍛戒护鍦ㄥ懡浠よ鎸囧畾瀵嗙爜锛
    shell> mysqladmin -u user_name -h host_name password "newpwd"

    璇ュ懡浠ら噸璁惧瘑鐮佺殑璐︽埛涓user琛ㄥ唴鍖归厤User鍒楃殑user_nameHost浣犲彂璧疯繛鎺ョ殑瀹㈡埛绔殑璁板綍銆

    涓鸿处鎴疯祴浜堝瘑鐮佺殑鍙︿竴绉嶆柟娉曟槸鎵цSET PASSWORD璇彞锛

    mysql> SET PASSWORD FOR 'jeffrey'@'%' = PASSWORD('biscuit');

    鍙湁root绛夊彲浠ユ洿鏂mysql鏁版嵁搴撶殑鐢ㄦ埛鍙互鏇存敼鍏跺畠鐢ㄦ埛鐨勫瘑鐮併傚鏋滀綘娌℃湁浠ュ尶鍚嶇敤鎴疯繛鎺ワ紝鐪佺暐FOR瀛愬彞渚垮彲浠ユ洿鏀硅嚜宸辩殑瀵嗙爜锛

    mysql> SET PASSWORD = PASSWORD('biscuit');

    浣犺繕鍙互鍦ㄥ叏灞绾у埆浣跨敤GRANT USAGE璇彞(*.*)鏉ユ寚瀹氭煇涓处鎴风殑瀵嗙爜鑰屼笉褰卞搷璐︽埛褰撳墠鐨勬潈闄愶細

    mysql> GRANT USAGE ON *.* TO 'jeffrey'@'%' IDENTIFIED BY 'biscuit';

    涓鑸儏鍐典笅鏈濂戒娇鐢ㄤ笂杩版柟娉曟潵鎸囧畾瀵嗙爜锛屼綘杩樺彲浠ョ洿鎺ヤ慨鏀user琛細

             瑕佹兂鍦ㄥ垱寤烘柊璐︽埛鏃跺缓绔嬪瘑鐮侊紝鍦Password鍒楁彁渚涗竴涓硷細

                    shell> mysql -u root mysql
                    mysql> INSERT INTO user (Host,User,Password)
                         -> VALUES('%','jeffrey',PASSWORD('biscuit'));
                    mysql> FLUSH PRIVILEGES;
                     

             瑕佹兂鏇存敼宸叉湁璐︽埛鐨勫瘑鐮侊紝浣跨敤UPDATE鏉ヨ缃Password鍒楀硷細

                    shell> mysql -u root mysql
                     mysql> UPDATE user SET Password = PASSWORD('bagel')
                           -> WHERE Host = '%' AND User = 'francis';
                    mysql> FLUSH PRIVILEGES;

    褰撲綘浣跨敤SET PASSWORDINSERTUPDATE鎸囧畾璐︽埛鐨勫瘑鐮佹椂锛屽繀椤荤敤PASSWORD()鍑芥暟瀵瑰畠杩涜鍔犲瘑銆(鍞竴鐨勭壒渚嬫槸濡傛灉瀵嗙爜涓虹┖锛屼綘涓嶉渶瑕佷娇鐢PASSWORD())銆傞渶瑕佷娇鐢PASSWORD()鏄洜涓user琛ㄤ互鍔犲瘑鏂瑰紡淇濆瓨瀵嗙爜锛岃屼笉鏄槑鏂囥傚鏋滀綘蹇樿浜嗭紝浣犲彲鑳戒細璞¤繖鏍疯缃瘑鐮侊細

    shell> mysql -u root mysql
    mysql> INSERT INTO user (Host,User,Password)
        -> VALUES('%','jeffrey','biscuit');
    mysql> FLUSH PRIVILEGES;
     

    缁撴灉鏄瘑鐮'biscuit'淇濆瓨鍒user琛ㄥ悗娌℃湁鍔犲瘑銆傚綋jeffrey浣跨敤璇ュ瘑鐮佽繛鎺ユ湇鍔″櫒鏃讹紝鍊艰鍔犲瘑骞跺悓淇濆瓨鍦user琛ㄤ腑鐨勮繘琛屾瘮杈冦備絾鏄紝淇濆瓨鐨勫间负瀛楃涓'biscuit'锛屽洜姝ゆ瘮杈冨皢澶辫触锛屾湇鍔″櫒鎷掔粷杩炴帴锛

    shell> mysql -u jeffrey -pbiscuit test
    Access denied

    濡傛灉浣犱娇鐢GRANT ... IDENTIFIED BY璇彞鎴mysqladmin password鍛戒护璁剧疆瀵嗙爜锛屽畠浠潎浼氬姞瀵嗗瘑鐮併傚湪杩欑鎯呭喌涓嬶紝涓嶉渶瑕佷娇鐢 PASSWORD()鍑芥暟銆

    閲婏細PASSWORD()鍔犲瘑涓嶅悓浜Unix瀵嗙爜鍔犲瘑銆傚弬瑙5.8.1鑺傦紝鈥淢ySQL鐢ㄦ埛鍚嶅拰瀵嗙爜鈥

5.8.6. 浣夸綘鐨勫瘑鐮佸畨鍏

鍦ㄧ鐞嗙骇鍒紝浣犲喅涓嶈兘灏mysql.user琛ㄧ殑璁块棶鏉冮檺鎺堜簣浠讳綍闈炵鐞嗚处鎴枫

褰撲綘杩愯瀹㈡埛绔▼搴忚繛鎺MySQL鏈嶅姟鍣ㄦ椂锛屼互涓绉嶆毚闇茬殑鍙鍏朵粬鐢ㄦ埛鍙戠幇鐨勬柟寮忔寚瀹氫綘鐨勫瘑鐮佹槸涓嶅Ε褰撶殑銆傚綋浣犺繍琛屽鎴风绋嬪簭鏃讹紝浣犲彲浠ヤ娇鐢ㄤ笅鍒楁柟娉曟寚瀹氫綘鐨勫瘑鐮侊紝杩樻湁姣忎釜鏂规硶鐨勯闄╄瘎浼帮細

         浣跨敤涓涓湪鍛戒护琛屼笂-pyour_pass--password=your_pass鐨勯夐」銆備緥濡傦細

                shell> mysql -u francis -pfrank db_name

杩欏緢鏂逛究浣嗘槸涓嶅畨鍏紝鍥犱负浣犵殑瀵嗙爜瀵圭郴缁熺姸鎬佺▼搴(渚嬪ps)鍙樺緱鍙锛屽畠鍙互琚叾浠栫殑鐢ㄦ埛璋冪敤鏉ユ樉绀哄懡浠よ銆備竴鑸MySQL瀹㈡埛鍦ㄤ粬浠殑鍒濆鍖栭『搴忔湡闂寸敤闆惰鐩栧懡浠よ鍙傛暟锛屼絾鏄粛鐒舵湁涓涓煭鏆傞棿闅旀椂闂村唴鍙傛暟鍊煎彲瑙佺殑銆

         浣跨敤涓涓-p--password閫夐」(娌℃湁鎸囧畾瀵嗙爜)銆傚湪杩欑鎯呭喌涓嬶紝瀹㈡埛绔▼搴忚姹傛潵鑷粓绔殑瀵嗙爜锛

                shell> mysql -u francis -p db_name
                Enter password: ********

 *瀛楃鎸囩ず杈撳叆瀵嗙爜鐨勫湴鏂广傝緭鍏ュ瘑鐮佹椂瀵嗙爜鐪嬩笉瑙併

鍥犱负瀹冨鍏朵粬鐢ㄦ埛涓嶅彲瑙侊紝涓庡湪鍛戒护琛屼笂鎸囧畾瀹冪浉姣旓紝杩欐牱杩涘叆浣犵殑瀵嗙爜鏇村畨鍏ㄣ傜劧鑰岋紝杩欎釜杈撳叆涓涓瘑鐮佺殑鏂规硶浠呬粎涓轰綘浜や簰寮忚繍琛岀▼搴忔槸鍚堥傜殑銆傚鏋滀綘鎯宠浠庨潪浜や簰寮忚繍琛岀殑涓涓剼鏈皟鐢ㄤ竴涓鎴风锛屽氨娌℃湁浠庣粓绔緭鍏ュ叆瀵嗙爜鐨勬満浼氥傚湪鏌愪簺绯荤粺涓紝浣犵敋鑷充細鍙戠幇鑴氭湰鐨勭涓琛岃锛堥敊璇湴锛夎骞惰В閲婁负浣犵殑瀵嗙爜锛

         鍦ㄤ竴涓厤缃枃浠朵腑瀛樺偍浣犵殑瀵嗙爜銆備緥濡傦紝鍦Unix涓紝浣犲彲鍦ㄤ富鐩綍鐨.my.cnf鏂囦欢涓殑[client]鑺傚垪鍑轰綘鐨勫瘑鐮侊細

                [client]
                password=your_pass

濡傛灉浣犲湪.my.cnf閲岄潰瀛樺偍瀵嗙爜锛岄櫎浜嗕綘鏈汉鍏跺畠浜轰笉鑳借闂鏂囦欢銆備繚璇佹枃浠剁殑璁块棶妯″紡鏄400600渚嬪锛

shell> chmod 600 .my.cnf

鍏充簬閫夐」鏂囦欢鐨勮缁嗚璁哄弬瑙4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥

         浣犲彲鍦MYSQL_PWD鐜鍙橀噺涓瓨鍌ㄥ瘑鐮併備絾鏄繖绉嶆寚瀹MySQL瀵嗙爜鐨勬柟娉曟槸鏋佷笉瀹夊叏鐨勶紝涓嶅簲璇ヤ娇鐢ㄣps鐨勬煇浜涚増鏈寘鎷樉绀鸿繍琛岃繘绋嬬殑鐜鐨勯夐」锛涘鏋滀綘璁惧畾MYSQL_PWD锛屼綘鐨勫瘑鐮佸皢琚繍琛ps鐨勬墍鏈変汉鐪嬭锛岀敋鑷冲湪娌℃湁杩欐牱涓涓増鏈殑ps鐨勭郴缁熶笂锛屾病鏈夊叾瀹冩柟娉曡瀵熷埌杩涚▼鐜鐨勫亣璁炬槸涓嶆槑鏅虹殑銆傚弬瑙闄勫綍F锛鐜鍙橀噺

鎬讳箣锛屾渶瀹夊叏鐨勬柟娉曟槸璁╁鎴风绋嬪簭鎻愮ず杈撳叆瀵嗙爜鎴栧湪閫傚綋淇濇姢鐨勯夐」鏂囦欢涓寚瀹氬瘑鐮併

5.8.7. 浣跨敤瀹夊叏杩炴帴

MySQL鏀寔MySQL瀹㈡埛绔拰鏈嶅姟鍣ㄤ箣闂寸殑瀹夊叏(鍔犲瘑鐨)杩炴帴鎵浣跨敤鐨勫畨鍏ㄥ鎺ュ瓧灞(SSL)鍗忚銆傛湰鑺傝璁哄浣曚娇鐢SSL杩炴帴銆傝繕鎻忚堪浜嗗湪Windows涓缃SSH鐨勬柟娉曘

MySQL鐨勬爣鍑嗛厤缃惧悜浜庡敖鍙兘蹇紝鍥犳榛樿鎯呭喌涓嶄娇鐢ㄥ姞瀵嗚繛鎺ャ備娇鐢ㄨ鍗忚浼氫娇瀹㈡埛绔/鏈嶅姟鍣ㄥ崗璁參寰楀銆傚鏁版嵁杩涜鍔犲瘑闈炲父鑰CPU锛岄渶瑕佽绠楁満澶氬仛璁稿宸ヤ綔锛屼細寤惰繜MySQL鐨勫叾瀹冧换鍔°傚浜庨渶瑕侀氳繃鍔犲瘑杩炴帴鎻愪緵瀹夊叏鐨勫簲鐢ㄧ▼搴忥紝鍙互淇濊瘉棰濆鐨勮绠椼

MySQL鍏佽鍦ㄨ繛鎺ュ墠鍚敤鍔犲瘑銆備綘鍙互鏍规嵁鍏蜂綋搴旂敤绋嬪簭鐨勯渶姹傞夋嫨鏅氭湭鍔犲瘑杩炴帴鎴栧畨鍏ㄥ姞瀵SSL杩炴帴銆

5.8.7.1. SSL鍩烘湰姒傚康

瑕佹兂鐞嗚ВMySQL濡備綍浣跨敤SSL锛岄渶瑕佽В閲婁竴浜涘熀鏈SSLX509姒傚康銆傜啛鎮夌殑浜轰滑鍙互璺宠繃璇ラ儴鍒嗐

榛樿鎯呭喌涓嬶紝MySQL鍦ㄥ鎴风鍜屾湇鍔″櫒涔嬮棿浣跨敤鏈姞瀵嗙殑杩炴帴銆傝繖璇存槑鍙互璁块棶缃戠粶鐨勯儴鍒嗕汉鍙互鐪嬪埌浣犵殑閫氫俊锛屽苟鐪嬪埌鍙戦佸拰鎺ユ敹鐨勬暟鎹備粬浠敋鑷冲彲浠ユ洿鏀瑰湪瀹㈡埛绔拰鏈嶅姟鍣ㄤ箣闂翠紶閫掔殑鏁版嵁銆傝鎯虫彁楂樺畨鍏ㄦэ紝褰撹皟鐢ㄥ鎴风绋嬪簭鏃讹紝浣犲彲浠ラ氳繃--compress閫夐」鍘嬬缉瀹㈡埛绔/鏈嶅姟鍣ㄤ箣闂寸殑閫氫俊銆備絾鏄紝杩欐牱骞朵笉鑳介樆鎸′綇椤藉浐鐨勬敾鍑昏呫

褰撲綘闇瑕佷互瀹夊叏鏂瑰紡鍦ㄧ綉缁滀腑浼犻掍俊鎭椂锛屾湭鍔犲瘑鐨勮繛鎺ユ槸涓嶅彲鎺ュ彈鐨勩傚姞瀵嗘槸浣夸换浣曟暟鎹笉鍙鐨勬柟娉曘備簨瀹炰笂锛屼粖澶╃殑璁稿鎯緥闇瑕佸姞瀵嗙畻娉曟彁渚涙洿鍔犲畨鍏ㄧ殑瑕佺礌銆傚畠浠簲鑳芥姷鎶楀悇绉嶅凡鐭ョ殑鏀诲嚮锛屼緥濡傛洿鏀瑰姞瀵嗘秷鎭殑椤哄簭鎴栦袱娆¢噸鏀炬暟鎹

SSL鏄竴绉嶄娇鐢ㄤ笉鍚岀殑鍔犲瘑绠楁硶纭繚浠庡叕鐢ㄧ綉鎺ユ敹鍒扮殑鏁版嵁鏄彲淇$殑鍗忚銆傚畠鍏锋湁妫娴嬫暟鎹洿鏀广佷涪澶辨垨閲嶆斁鐨勬満鍒躲SSL杩樺寘鎷娇鐢 X509鏍囧噯鎻愪緵韬唤璁よ瘉鐨勭畻娉曘

浣跨敤X509锛屽彲浠ヨ瘑鍒Internet涓婄殑鏌愪簺浜恒傞氬父鐢ㄤ簬鐢靛瓙鍟嗗姟搴旂敤绋嬪簭涓傛寜鐓у熀鏈蹇碉紝搴旀湁鏌愮绉颁箣涓衡璁よ瘉鏈烘瀯(CA)鐨勬満鏋勶紝鍙互鍚戣姹傝呭垎鍙戠數瀛愯瘉涔︺傝瘉涔︿緷璧栭潪瀵圭О鍔犲瘑绠楁硶锛屾湁涓や釜鍔犲瘑瀵嗛挜(鍏叡瀵嗛挜鍜岀浜哄瘑閽)銆傝璇佹寔鏈夎呭彲浠ュ悜鍏跺畠鏂瑰嚭绀鸿瘉涔︽潵璇佹槑韬唤銆傝瘉涔﹀寘鎷寔鏈夎呯殑鍏叡瀵嗛挜銆傚彧鑳戒娇鐢ㄥ搴旂殑绉佷汉瀵嗛挜瀵瑰惈璇ュ叕鍏卞瘑閽ョ殑鍔犲瘑鏁版嵁杩涜瑙e瘑锛岀浜哄瘑閽ョ敱璇佷功鎸佹湁鑰呮嫢鏈夈

濡傛灉浣犻渶瑕佸叧浜SSLX509銆佹垨鍔犲瘑鐨勮缁嗕俊鎭紝浣跨敤Internet鎼滅储寮曟搸鏉ユ悳绱綘鎰熷叴瓒g殑鍏抽敭瀛椼

5.8.7.2. 闇姹(OpenSSL)

瑕佹兂鍦MySQL鏈嶅姟鍣ㄥ拰瀹㈡埛绔▼搴忎箣闂翠娇鐢SSL杩炴帴锛岀郴缁熷繀椤昏兘澶熸敮鎸OpenSSL銆傚鏋滅敤鏀寔鍐呭祵寮yaSSLMySQL鐗堟湰锛屼笉瑕佽璇ヨ妭锛屼絾搴旈槄璇5.8.7.3鑺傦紝鈥滀娇鐢▂aSSL鈥

瑕佹兂鑾峰緱瀹夊叏鐨MySQL杩炴帴锛屽繀椤伙細

1.    瀹夎OpenSSL搴撱傛垜浠凡缁忔祴璇曚簡甯OpenSSL 0.9.6MySQL銆傚鏋滀綘闇瑕OpenSSL锛岃璁块棶http://www.openssl.org

2.    閰嶇疆MySQL锛岀敤--with-vio--with-openssl閫夐」杩愯configure鑴氭湰銆

3.    纭繚鍗囩骇浜嗘巿鏉冭〃锛屼娇mysql.user琛ㄥ唴鍖呭惈SSL鐩稿叧鍒椼傚鏋 鎺堟潈琛ㄦ槸浠MySQL 4.0.0涔嬪墠鐨勭増鏈崌绾э紝杩欏緢閲嶈銆傚崌绾ц繃绋嬭2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥

4.    瑕佹兂妫鏌ユ槸鍚﹁繍琛岀殑mysqld鏈嶅姟鍣鏀寔OpenSSL锛屽簲妫鏌have_openssl绯荤粺鍙橀噺鐨勫硷細

5.            mysql> SHOW VARIABLES LIKE 'have_openssl';
6.            +---------------+-------+
7.            | Variable_name | Value |
8.            +---------------+-------+
9.            | have_openssl  | YES   |
10.        +---------------+-------+

濡傛灉鍊间负YES锛屾湇鍔″櫒鏀寔OpenSSL杩炴帴銆

5.8.7.3. 浣跨敤yaSSL

浣跨敤MySQL鐨勫唴宓屽紡yaSSL鏀寔锛屽彲浠ュ緢瀹规槗鍦颁娇鐢ㄥ畨鍏ㄨ繛鎺ャ備笉闇瑕佸畨瑁OpenSSL鍜屾墽琛5.8.7.2鑺傦紝鈥滈渶姹(OpenSSL)鈥涓殑姝ラ銆傚苟涓旓紝MySQLyaSSL浣跨敤鐩稿悓鐨勮鍙ā鍨嬨

褰撳墠锛屽湪浠ヤ笅骞冲彴涓婃敮鎸yaSSL

         Linux/x86-64 Red Hat Enterprise 3.0

         Linux RHAS21 Itanium-2锛屽甫gcc锛岄潤鎬侀摼鎺

         Linux Itanium-2锛屽甫gcc

         Windows

褰撲粠婧愮爜鏋勫缓MySQL鏃跺鏋滀綘鎯宠鍚敤yaSSL锛屽簲杩欐牱閰嶇疆MySQL

./configure --with-yassl=yes

瑕佹兂鍚姩MySQL鏈嶅姟鍣ㄦ敮鎸yaSSL锛屼娇鐢ㄦ敮鎸OpenSSL鐨勭浉鍚岀殑閫夐」锛屽苟璇嗗埆寤虹珛瀹夊叏杩炴帴闇瑕佺殑璇佷功锛

shell> mysqld --ssl-ca=cacert.pem \
       --ssl-cert=server-cert.pem \
       --ssl-key=server-key.pem

         --ssl-ca璇嗗埆璁よ瘉鏈烘瀯璇佷功銆

         --ssl-cert璇嗗埆鏈嶅姟鍣ㄨ瘉涔︺

         --ssl-key璇嗗埆瀹㈡埛璇佷功銆

瑕佹兂鐢yaSSL鏀寔寤虹珛涓MySQL鏈嶅姟鍣ㄧ殑瀹夊叏杩炴帴锛屽簲杩欐牱鍚姩瀹㈡埛绔細

shell> mysql --ssl-ca=cacert.pem \
       --ssl-cert=server-cert.pem \
       --ssl-key=server-key.pem

鎹㈠彞璇濊锛岄夐」涓庢湇鍔″櫒鐨勭浉鍚岋紝骞朵笖璁よ瘉鏈烘瀯璇佷功蹇呴』鐩稿悓銆

瑕佹兂浠庡簲鐢ㄧ▼搴忓缓绔嬪畨鍏ㄨ繛鎺ワ紝璋冪敤mysql_real_connect()涔嬪墠锛屽簲浣跨敤mysql_ssl_set()API鍑芥暟鏉ヨ缃浉搴旇璇侀夐」銆傚弬瑙25.2.3.64鑺傦紝鈥渕ysql_ssl_set()鈥

5.8.7.4. 涓篗ySQL璁剧疆SSL璇佷功

涓嬮潰鏄竴涓负MySQ璁剧疆SSL璇佷功鐨勪緥瀛愶細
DIR=`pwd`/openssl
PRIV=$DIR/private
 
mkdir $DIR $PRIV $DIR/newcerts
cp /usr/share/ssl/openssl.cnf $DIR
replace ./demoCA $DIR -- $DIR/openssl.cnf
 
# Create necessary files: $database, $serial and $new_certs_dir
# directory (optional)
 
touch $DIR/index.txt
echo "01" > $DIR/serial
 
#
# Generation of Certificate Authority(CA)
#
 
openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem \
    -config $DIR/openssl.cnf
 
# Sample output:
# Using configuration from /home/monty/openssl/openssl.cnf
# Generating a 1024 bit RSA private key
# ................++++++
# .........++++++
# writing new private key to '/home/monty/openssl/private/cakey.pem'
# Enter PEM pass phrase:
# Verifying password - Enter PEM pass phrase:
# -----
# You are about to be asked to enter information that will be
# incorporated into your certificate request.
# What you are about to enter is what is called a Distinguished Name
# or a DN.
# There are quite a few fields but you can leave some blank
# For some fields there will be a default value,
# If you enter '.', the field will be left blank.
# -----
# Country Name (2 letter code) [AU]:FI
# State or Province Name (full name) [Some-State]:.
# Locality Name (eg, city) []:
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
# Organizational Unit Name (eg, section) []:
# Common Name (eg, YOUR name) []:MySQL admin
# Email Address []:
 
#
# Create server request and key
#
openssl req -new -keyout $DIR/server-key.pem -out \
    $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
 
# Sample output:
# Using configuration from /home/monty/openssl/openssl.cnf
# Generating a 1024 bit RSA private key
# ..++++++
# ..........++++++
# writing new private key to '/home/monty/openssl/server-key.pem'
# Enter PEM pass phrase:
# Verifying password - Enter PEM pass phrase:
# -----
# You are about to be asked to enter information that will be
# incorporated into your certificate request.
# What you are about to enter is what is called a Distinguished Name
# or a DN.
# There are quite a few fields but you can leave some blank
# For some fields there will be a default value,
# If you enter '.', the field will be left blank.
# -----
# Country Name (2 letter code) [AU]:FI
# State or Province Name (full name) [Some-State]:.
# Locality Name (eg, city) []:
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
# Organizational Unit Name (eg, section) []:
# Common Name (eg, YOUR name) []:MySQL server
# Email Address []:
#
# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:
# An optional company name []:
 
#
# Remove the passphrase from the key (optional)
#
 
openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
 
#
# Sign server cert
#
openssl ca  -policy policy_anything -out $DIR/server-cert.pem \
    -config $DIR/openssl.cnf -infiles $DIR/server-req.pem
 
# Sample output:
# Using configuration from /home/monty/openssl/openssl.cnf
# Enter PEM pass phrase:
# Check that the request matches the signature
# Signature ok
# The Subjects Distinguished Name is as follows
# countryName           :PRINTABLE:'FI'
# organizationName      :PRINTABLE:'MySQL AB'
# commonName            :PRINTABLE:'MySQL admin'
# Certificate is to be certified until Sep 13 14:22:46 2003 GMT
# (365 days)
# Sign the certificate? [y/n]:y
#
#
# 1 out of 1 certificate requests certified, commit? [y/n]y
# Write out database with 1 new entries
# Data Base Updated
 
#
# Create client request and key
#
openssl req -new -keyout $DIR/client-key.pem -out \
    $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
 
# Sample output:
# Using configuration from /home/monty/openssl/openssl.cnf
# Generating a 1024 bit RSA private key
# .....................................++++++
# .............................................++++++
# writing new private key to '/home/monty/openssl/client-key.pem'
# Enter PEM pass phrase:
# Verifying password - Enter PEM pass phrase:
# -----
# You are about to be asked to enter information that will be
# incorporated into your certificate request.
# What you are about to enter is what is called a Distinguished Name
# or a DN.
# There are quite a few fields but you can leave some blank
# For some fields there will be a default value,
# If you enter '.', the field will be left blank.
# -----
# Country Name (2 letter code) [AU]:FI
# State or Province Name (full name) [Some-State]:.
# Locality Name (eg, city) []:
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
# Organizational Unit Name (eg, section) []:
# Common Name (eg, YOUR name) []:MySQL user
# Email Address []:
#
# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:
# An optional company name []:
 
#
# Remove a passphrase from the key (optional)
#
openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
 
#
# Sign client cert
#
 
openssl ca  -policy policy_anything -out $DIR/client-cert.pem \
    -config $DIR/openssl.cnf -infiles $DIR/client-req.pem
 
# Sample output:
# Using configuration from /home/monty/openssl/openssl.cnf
# Enter PEM pass phrase:
# Check that the request matches the signature
# Signature ok
# The Subjects Distinguished Name is as follows
# countryName           :PRINTABLE:'FI'
# organizationName      :PRINTABLE:'MySQL AB'
# commonName            :PRINTABLE:'MySQL user'
# Certificate is to be certified until Sep 13 16:45:17 2003 GMT
# (365 days)
# Sign the certificate? [y/n]:y
#
#
# 1 out of 1 certificate requests certified, commit? [y/n]y
# Write out database with 1 new entries
# Data Base Updated
 
#
# Create a my.cnf file that you can use to test the certificates
#
 
cnf=""
cnf="$cnf [client]"
cnf="$cnf ssl-ca=$DIR/cacert.pem"
cnf="$cnf ssl-cert=$DIR/client-cert.pem"
cnf="$cnf ssl-key=$DIR/client-key.pem"
cnf="$cnf [mysqld]"
cnf="$cnf ssl-ca=$DIR/cacert.pem"
cnf="$cnf ssl-cert=$DIR/server-cert.pem"
cnf="$cnf ssl-key=$DIR/server-key.pem"
echo $cnf | replace " " '
' > $DIR/my.cnf

 

瑕佹兂娴嬭瘯SSL杩炴帴锛屾寜涓嬮潰鏂规硶鍚姩鏈嶅姟鍣紝鍏朵腑$DIR鏄ず渚my.cnf閫夐」鏂囦欢瀹夎鐨勮矾寰勫悕锛

shell> MySQLd --defaults-file=$DIR/my.cnf &

鐒跺悗浣跨敤鐩稿悓鐨勯夐」鏂囦欢璋冪敤瀹㈡埛绔▼搴忥細

shell> MySQL --defaults-file=$DIR/my.cnf

濡傛灉浣犳湁MySQL婧愮爜鍒嗗彂鐗堬紝杩樺彲浠ヤ慨鏀瑰墠闈㈢殑my.cnf鏂囦欢鏉ユ寚鍚SSL鐩綍涓殑绀鸿寖璇佷功鍜屽瘑閽ユ枃浠舵潵娴嬭瘯浣犵殑璁剧疆銆

5.8.7.5.聽SSL GRANT 閫夐」

MySQL鍙互妫鏌X509璇佷功鐨勫睘鎬у拰鍩轰簬鐢ㄦ埛鍚嶅拰瀵嗙爜鐨勯氱敤閴村畾鏂规硶銆傝鎯充负MySQL璐︽埛鎸囧畾SSL鐩稿叧閫夐」锛屼娇鐢GRANT璇彞鐨REQUIRE瀛愬彞銆傚弬瑙13.5.1.3鑺傦紝鈥淕RANT鍜孯EVOKE璇硶鈥

鏈夊绉嶅彲鑳芥潵闄愬埗涓涓处鎴风殑杩炴帴绫诲瀷锛

         濡傛灉璐︽埛娌℃湁SSLX509闇姹傦紝濡傛灉鐢ㄦ埛鍚嶅拰瀵嗙爜鍚堟硶锛屽厑璁告湭鍔犲瘑鐨勮繛鎺ャ備絾鏄紝濡傛灉瀹㈡埛鏈夋纭殑璇佷功鍜屽瘑閽ユ枃浠讹紝鍦ㄥ鎴烽夐」涓彲浠ヤ娇鐢ㄥ姞瀵嗚繛鎺ャ

         REQUIRE SSL閫夐」闄愬埗鏈嶅姟鍣ㄥ彧鍏佽璇ヨ处鎴风殑SSL鍔犲瘑杩炴帴銆傝娉ㄦ剰濡傛灉鏈ACL璁板綍鍏佽闈SSL杩炴帴锛岃閫夐」浼氳蹇界暐銆

                  mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
                     -> IDENTIFIED BY 'goodsecret' REQUIRE SSL;

         REQUIRE X509琛ㄧず瀹㈡埛蹇呴』鏈夊悎娉曡瘉涔︿絾纭垏鐨勮瘉涔︺佸垎鍙戣呭拰涓讳綋涓嶉噸瑕併傚敮涓鐨勯渶姹傛槸搴斿彲浠ヨ鏌愪釜CA璁よ瘉鏈烘瀯楠岃瘉瀹冪殑绛惧悕銆

                mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
                    -> IDENTIFIED BY 'goodsecret' REQUIRE X509;

         REQUIRE ISSUER 'issuer'闄愬埗杩炴帴浼佸浘锛屽嵆瀹㈡埛蹇呴』鍑虹ずCA 'issuer'绛惧彂鐨勫悎娉X509璇佷功銆傚鏋滃鎴峰嚭绀轰簡涓涓悎娉曡瘉涔︼紝浣嗘槸鏄敱涓嶅悓鐨勫垎鍙戣呯鍙戯紝鏈嶅姟鍣ㄦ嫆缁濊繛鎺ャ備娇鐢X509璇佷功琛ㄧず瑕佸姞瀵嗭紝鍥犳涓嶉渶瑕SSL閫夐」銆

                mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
                    -> IDENTIFIED BY 'goodsecret'
                    -> REQUIRE ISSUER '/C=FI/ST=Some-State/L=Helsinki/
                       O=MySQL Finland AB/CN=Tonu Samuel/Email=tonu@example.com';

璇锋敞鎰ISSUER鍊煎簲鍋氫负鍗曚竴瀛楃涓茶緭鍏ャ

         REQUIRE SUBJECT 'subject' 闄愬埗杩炴帴浼佸浘锛屽嵆瀹㈡埛蹇呴』鍑虹ず涓婚涓'subject'鐨勫悎娉X509璇佷功銆傚鏋滃鎴峰嚭绀轰簡涓涓悎娉曡瘉涔︼紝浣嗘槸鏈変笉鍚岀殑涓婚锛屾湇鍔″櫒鎷掔粷杩炴帴銆

                mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
                    -> IDENTIFIED BY 'goodsecret'
                    -> REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/
                       O=MySQL demo client certificate/
       CN=Tonu Samuel/Email=tonu@example.com';

璇锋敞鎰SUBJECT鍊煎簲鍋氫负鍗曚竴瀛楃涓茶緭鍏ャ

         REQUIRE CIPHER 'cipher'鐢ㄦ潵纭繚浣跨敤瓒冲寮虹殑瀵嗙爜鍜屽瘑閽ラ暱搴︺傚鏋滀娇鐢ㄦ棫鐨勭煭鍔犲瘑瀵嗛挜绠楁硶锛SSL鏈韩鍙兘寰堝急銆備娇鐢ㄨ閫夐」锛屾垜浠彲浠ョ储鍙栫‘鍒囩殑鍔犲瘑鏂规硶鏉ヨ繛鎺ャ

                mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
                    -> IDENTIFIED BY 'goodsecret'
    -> REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';

REQUIRE瀛愬彞涓紝鍙互缁撳悎浣跨敤SUBJECTISSUERCIPHER閫夐」锛

mysql> GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost'
    -> IDENTIFIED BY 'goodsecret'
    -> REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/
       O=MySQL demo client certificate/
       CN=Tonu Samuel/Email=tonu@example.com'
    -> AND ISSUER '/C=FI/ST=Some-State/L=Helsinki/
       O=MySQL Finland AB/CN=Tonu Samuel/Email=tonu@example.com'
    -> AND CIPHER 'EDH-RSA-DES-CBC3-SHA';

璇锋敞鎰SUBJECTISSUER鍊煎簲鍋氫负鍗曚竴瀛楃涓茶緭鍏ャ

MySQL 5.1,REQUIRE閫夐」涔嬮棿鍙互閫夌敤AND鍏抽敭瀛椼

閫夐」鐨勯『搴忎笉閲嶈锛屼絾浠讳綍閫夐」涓嶈兘鐢ㄤ袱娆°

5.8.7.6. SSL鍛戒护琛岄夐」

涓嬮潰鍒楀嚭浜嗚瀹SSL銆佽瘉涔︽枃浠跺拰瀵嗛挜鏂囦欢浣跨敤鐨勯夐」銆傚畠浠彲浠ヤ綅浜庡懡浠よ涓垨閫夐」鏂囦欢涓

         --ssl

瀵逛簬鏈嶅姟鍣紝璇ラ夐」瑙勫畾璇ユ湇鍔″櫒鍏佽SSL杩炴帴銆傚浜庡鎴风绋嬪簭锛屽畠鍏佽瀹㈡埛浣跨敤SSL杩炴帴鏈嶅姟鍣ㄣ傚崟鍗曡閫夐」涓嶈冻浠ヤ娇鐢SSL杩炴帴銆傝繕蹇呴』鎸囧畾--ssl-ca--ssl-cert--ssl-key閫夐」銆

閫氬父浠庡弽鍚戜娇鐢ㄨ閫夐」琛ㄧず涓嶅簲浣跨敤SSL銆傝鎯冲疄鐜帮紝灏嗛夐」鎸囧畾涓--skip-ssl--ssl=0

璇锋敞鎰忎娇鐢--ssl闇瑕SSL杩炴帴銆備緥濡傦紝濡傛灉缂栬瘧鐨勬湇鍔″櫒鎴栧鎴蜂笉鏀寔SSL锛屽垯浣跨敤鏅氱殑鏈姞瀵嗙殑杩炴帴銆

纭繚浣跨敤SSL杩炴帴鐨勫畨鍏ㄦ柟寮忔槸浣跨敤鍚REQUIRE SSL瀛愬彞鐨GRANT璇彞鍦ㄦ湇鍔″櫒涓婂垱寤轰竴涓处鎴枫傜劧鍚庝娇鐢ㄨ璐︽埛鏉ヨ繛鎺ユ湇鍔″櫒锛屾湇鍔″櫒鍜屽鎴风鍧囧簲鍚敤SSL鏀寔銆

         --ssl-ca=file_name

鍚彲淇SSL CA鐨勬竻鍗曠殑鏂囦欢鐨勮矾寰勩

         --ssl-capath=directory_name

鍖呭惈pem鏍煎紡鐨勫彲淇SSL CA璇佷功鐨勭洰褰曠殑璺緞銆

         --ssl-cert=file_name

SSL璇佷功鏂囦欢鍚嶏紝鐢ㄤ簬寤虹珛瀹夊叏杩炴帴銆

         --ssl-cipher=cipher_list

鍏佽鐨勭敤浜SSL鍔犲瘑鐨勫瘑鐮佺殑娓呭崟銆cipher_list鐨勬牸寮忎笌OpenSSL ciphers鍛戒护鐩稿悓銆

绀轰緥锛--ssl-cipher=ALL:-AES:-EXP

         --ssl-key=file_name

SSL瀵嗛挜鏂囦欢鍚嶏紝鐢ㄤ簬寤虹珛瀹夊叏杩炴帴銆

5.8.7.7. 鐢⊿SH浠ヨ繙绋嬫柟寮忎粠Windows杩炴帴鍒癕ySQL

鏈妭璇存槑濡備綍鐢SSH瀹夊叏杩炴帴鍒拌繙绋MySQL鏈嶅姟鍣(David Carlson <dcarlson@mplcommcom>)

1.    Windows涓绘満涓婂畨瑁SSH瀹㈡埛绔備綔涓虹敤鎴凤紝鎴戞墍鍙戠幇鐨勬渶濂界殑闈炲厤璐瑰鎴风鏉ヨ嚜http://www.vandyke.com/SecureCRT銆傚彟涓涓夊垯鏄http://www.f-secure.com/f-secure銆備綘杩樺彲浠ヤ粠http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/ Google鎵惧埌涓浜涘厤璐瑰鎴风銆

2.    鍚姩Windows SSH瀹㈡埛绔傝缃Host_Name = yourmysqlserver_URL_or_IP銆傝缃userid=your_userid浠ヤ究鐧诲綍鏈嶅姟鍣ㄣ傛userid鍊煎彲浠ヤ笌浣犵殑MySQL璐︽埛鐨勭敤鎴峰悕涓嶇浉鍚屻

3.    璁剧疆绔彛鏄犲皠銆傚彲浠ヨ繘琛岃繙绋嬫槧灏(璁剧疆local_port: 3306, remote_host: yourmysqlservername_or_ip, remote_port: 3306)鎴栨湰鍦版槧灏(璁剧疆port: 3306, host: localhost, remote port: 3306)

4.    杩涜淇濆瓨锛屽惁鍒欎笅娆¢渶瑕侀噸璁俱

5.    鍒氬垱寤虹殑SSH浼氳瘽鐧诲綍鏈嶅姟鍣ㄣ

6.    Windows鏈哄櫒涓婂惎鍔ㄧ浉搴ODBC搴旂敤绋嬪簭(渚嬪Access)

7.    Windows涓垱寤轰竴涓柊鐨勬枃浠舵寜鐓у父鐢ㄦ柟娉曢氳繃ODBC椹卞姩绋嬪簭閾炬帴MySQL锛屼笉鍚岀殑鏄涓MySQL鏈嶅姟鍣ㄨ緭鍏localhost锛岃屼笉鏄yourmysqlservername

浣犲簲鏈変娇鐢SSH鍔犲瘑鐨ODBC杩炴帴鍒MySQL

5.9. 澶囦唤涓庢仮澶

鏈妭璁ㄨ濡備綍杩涜鏁版嵁搴撳浠(瀹屽叏澶囦唤鍜屽閲忓浠)锛屼互鍙婂浣曟墽琛岃〃鐨勭淮鎶ゃ傛湰鑺傛弿杩扮殑SQL璇彞璇硶鍙傝绗5绔狅細鏁版嵁搴撶鐞銆傛澶勬彁渚涚殑澶у鏁颁俊鎭富瑕侀傚悎MyISAM琛ㄣInnoDB澶囦唤绋嬪簭鍙傝15.2.8鑺傦紝鈥淚nnoDB鏁版嵁搴撶殑澶囦唤鍜屾仮澶

5.9.1. 鏁版嵁搴撳浠

鍥犱负MySQL琛ㄤ繚瀛樹负鏂囦欢鏂瑰紡锛屽緢瀹规槗澶囦唤銆傝鎯充繚鎸佸浠界殑涓鑷存э紝瀵圭浉鍏宠〃鎵цLOCK TABLES鎿嶄綔锛岀劧鍚庡琛ㄦ墽琛FLUSH TABLES銆傚弬瑙13.4.5鑺傦紝鈥淟OCK TABLES鍜孶NLOCK TABLES璇硶鈥13.5.5.2鑺傦紝鈥淔LUSH璇硶鈥銆備綘鍙渶瑕佽閿佸畾锛涜繖鏍峰綋浣犲鍒舵暟鎹簱鐩綍涓殑鏂囦欢鏃讹紝鍏佽鍏跺畠瀹㈡埛缁х画鏌ヨ琛ㄣ傞渶瑕FLUSH TABLES璇彞鏉ョ‘淇濆紑濮嬪浠藉墠灏嗘墍鏈夋縺娲荤殑绱㈠紩椤靛啓鍏ョ‖鐩樸

濡傛灉浣犳兂瑕佽繘琛SQL绾у埆鐨勮〃澶囦唤锛屼綘鍙互浣跨敤SELECT INTO ...OUTFILEBACKUP TABLE銆傚浜SELECT INTO ...OUTFILE锛 杈撳嚭鐨勬枃浠朵笉鑳藉厛瀛樺湪銆傚浜BACKUP TABLE涔熷姝わ紝鍥犱负瑕嗙洊瀹屾暣鐨勬枃浠朵細鏈夊畨鍏ㄩ闄┿傚弬瑙13.2.7鑺傦紝鈥淪ELECT璇硶鈥13.5.2.2鑺傦紝鈥淏ACKUP TABLE璇硶鈥

澶囦唤鏁版嵁搴撶殑鍙︿竴涓妧鏈槸浣跨敤mysqldump绋嬪簭鎴mysqlhotcopy鑴氭湰銆傚弬瑙8.8鑺傦紝鈥渕ysqldump锛氭暟鎹簱澶囦唤绋嬪簭鈥8.9鑺傦紝鈥渕ysqlhotcopy锛氭暟鎹簱澶囦唤绋嬪簭鈥

1.    瀹屽叏澶囦唤鏁版嵁搴擄細

2.            shell> mysqldump --tab=/path/to/some/dir --opt db_name

鎴栵細

shell> mysqlhotcopy db_name /path/to/some/dir

鍙鏈嶅姟鍣ㄤ笉鍐嶈繘琛屾洿鏂帮紝杩樺彲浠ュ彧澶嶅埗鎵鏈夎〃鏂囦欢(*.frm*.MYD*.MYI鏂囦欢)mysqlhotcopy鑴氭湰浣跨敤璇ユ柟娉曘(浣嗚娉ㄦ剰濡傛灉鏁版嵁搴撳寘鍚InnoDB琛紝杩欎簺鏂规硶涓嶅伐浣溿InnoDB涓嶅皢琛ㄧ殑鍐呭淇濆瓨鍒版暟鎹簱鐩綍涓紝mysqlhotcopy鍙傚悎MyISAM琛級

3.    濡傛灉mysqld鍦ㄨ繍琛屽垯鍋滄锛岀劧鍚庣敤--log-bin[=file_name]閫夐」鏉ュ惎鍔ㄣ傚弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥銆備簩杩涘埗鏃ュ織鏂囦欢涓彁渚涗簡  鎵цmysqldump涔嬪悗瀵规暟鎹簱鐨勬洿鏀硅繘琛屽鍒舵墍闇瑕佺殑淇℃伅銆

瀵逛簬InnoDB琛紝鍙互杩涜鍦ㄧ嚎澶囦唤锛屼笉闇瑕佸琛ㄨ繘琛岄攣瀹氾紱鍙傝8.8鑺傦紝鈥渕ysqldump锛氭暟鎹簱澶囦唤绋嬪簭鈥

MySQL鏀寔澧為噺澶囦唤:闇瑕佺敤--log-bin閫夐」鏉ュ惎鍔ㄦ湇鍔″櫒浠ヤ究鍚敤浜岃繘鍒舵棩蹇楋紱鍙傝5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥銆傚綋鎯宠杩涜澧為噺澶囦唤鏃(鍖呭惈涓婁竴娆″畬鍏ㄥ浠芥垨澧為噺澶囦唤涔嬪悗鐨勬墍鏈夋洿鏀)锛屽簲浣跨敤FLUSH LOGS鍥炴粴浜岃繘鍒舵棩蹇椼傜劧鍚庯紝浣犻渶瑕佸皢浠庢渶鍚庣殑瀹屽叏鎴栧閲忓浠界殑鏌愪釜鏃跺埢鍒版渶鍚庢煇涓偣鐨勬墍鏈変簩杩涘埗鏃ュ織澶嶅埗鍒板浠戒綅缃傝繖浜涗簩杩涘埗鏃ュ織涓哄閲忓浠斤紱鎭㈠鏃讹紝鎸夌収涓嬮潰鐨勮В閲婂簲鐢ㄣ備笅娆¤繘琛屽畬鍏ㄥ浠芥椂锛岃繕搴斾娇鐢FLUSH LOGSmysqlhotcopy --flushlogs鍥炴粴浜岃繘鍒舵棩蹇椼傚弬瑙8.8鑺傦紝鈥渕ysqldump锛氭暟鎹簱澶囦唤绋嬪簭鈥8.9鑺傦紝鈥渕ysqlhotcopy锛氭暟鎹簱澶囦唤绋嬪簭鈥

濡傛灉MySQL鏈嶅姟鍣ㄤ负浠庡鍒舵湇鍔″櫒锛屽垯鏃犺閫夋嫨浠涔堝浠芥柟娉曪紝褰撳浠戒粠鏈烘暟鎹椂锛岃繕搴斿浠master.inforelay-log.info鏂囦欢銆傛仮澶嶄簡浠庢満鏁版嵁鍚庯紝闇瑕佽繖浜涙枃浠舵潵缁х画澶嶅埗銆傚鏋滀粠鏈烘墽琛屽鍒LOAD DATA INFILE鍛戒护锛屼綘搴旇繕澶囦唤鐢--slave-load-tmpdir閫夐」鎸囧畾鐨勭洰褰曚腑鐨SQL_LOAD-*鏂囦欢銆(濡傛灉鏈寚瀹氾紝璇ヤ綅缃粯璁や负tmpdir鍙橀噺鍊硷級浠庢満闇瑕佽繖浜涙枃浠舵潵缁х画澶嶅埗涓柇鐨LOAD DATA INFILE鎿嶄綔銆

濡傛灉蹇呴』鎭㈠MyISAM琛紝鍏堜娇鐢REPAIR TABLEmyisamchk -r鏉ユ仮澶嶃99.9%鐨勬儏鍐典笅璇ユ柟娉曞彲浠ュ伐浣溿傚鏋myisamchk澶辫触锛岃瘯璇曚笅闈㈢殑鏂规硶銆傝娉ㄦ剰鍙湁鐢--log-bin閫夐」鍚姩浜MySQL浠庤屽惎鐢ㄤ簩杩涘埗鏃ュ織瀹冩墠宸ヤ綔锛涘弬瑙5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥

1.    鎭㈠鍘mysqldump澶囦唤锛屾垨浜岃繘鍒跺浠姐

2.    鎵ц涓嬮潰鐨勫懡浠ら噸鏂版洿鏂颁簩杩涘埗鏃ュ織锛

3.            shell> mysqlbinlog hostname-bin.[0-9]* | mysql

鍦ㄦ煇浜涙儏鍐典笅锛屼綘鍙兘鍙兂瑕佷粠鏌愪釜浣嶇疆閲嶆柊杩愯鏌愪簺浜岃繘鍒舵棩蹇椼(閫氬父浣犳兂瑕佷粠鎭㈠澶囦唤鐨勬棩鏈熼噸鏂拌繍琛屾墍鏈変簩杩涘埗鏃ュ織锛屾煡璇笉姝g‘鏃朵緥澶)銆傚叧浜mysqlbinlog宸ュ叿鍜屽浣曚娇鐢ㄥ畠鐨勮缁嗕俊鎭弬瑙8.6鑺傦紝鈥渕ysqlbinlog锛氱敤浜庡鐞嗕簩杩涘埗鏃ュ織鏂囦欢鐨勫疄鐢ㄥ伐鍏封

杩樺彲浠ュ鍏蜂綋鏂囦欢杩涜閫夋嫨澶囦唤锛

         瑕佹兂澶嶅埗琛紝浣跨敤SELECT * INTO OUTFILE 'file_name' FROM tbl_name

         瑕佹兂閲嶈浇琛紝浣跨敤LOAD DATA INFILE 'file_name' REPLACE ...骞舵仮澶嶃傝閬垮厤澶嶅埗璁板綍锛岃〃蹇呴』鏈PRIMARY KEY鎴栦竴涓UNIQUE绱㈠紩銆傚綋鏂拌褰曞鍒跺敮涓閿肩殑鏃ц褰曟椂锛REPLACE鍏抽敭瀛楀彲浠ュ皢鏃ц褰曟浛鎹负鏂拌褰曘

濡傛灉澶囦唤鏃堕亣鍒版湇鍔″櫒鎬ц兘闂锛屽彲浠ユ湁甯姪鐨勪竴涓瓥鐣ユ槸鍦ㄤ粠鏈嶅姟鍣ㄨ屼笉鏄富鏈嶅姟鍣ㄤ笂寤虹珛澶嶅埗骞舵墽琛屽浠姐傚弬瑙6.1鑺傦紝鈥滃鍒朵粙缁嶁

濡傛灉浣跨敤Veritas鏂囦欢绯荤粺锛屽彲浠ヨ繖鏍峰浠斤細

1.    浠庡鎴风绋嬪簭鎵цFLUSH TABLES WITH READ LOCK

2.    浠庡彟涓涓shell鎵цmount vxfs snapshot

3.    浠庣涓涓鎴风鎵цUNLOCK TABLES

4.    浠庡揩鐓у鍒舵枃浠躲

5.    鍗歌浇蹇収銆

5.9.2. 绀轰緥鐢ㄥ浠戒笌鎭㈠绛栫暐

鏈妭璁ㄨ杩涜澶囦唤鐨勭▼搴忥紝鍦ㄥ嚭鐜板穿婧冨悗锛屽彲浠ユ仮澶嶆暟鎹細

         鎿嶄綔绯荤粺宕╂簝

         鐢垫簮鏁呴殰

         鏂囦欢绯荤粺宕╂簝

         纭欢闂(纭洏銆佹瘝鏉跨瓑绛)

璇ュ懡浠や笉鍖呮嫭mysqldumpmysql绋嬪簭鐨--userpassword绛夐夐」銆傚簲鍖呮嫭蹇呰鐨勯夐」璁MySQL鏈嶅姟鍣ㄥ厑璁镐綘杩炴帴瀹冦

鎴戜滑鍋囧畾鏁版嵁淇濆瓨鍦MySQLInnoDB瀛樺偍寮曟搸涓紝鏀寔浜嬪姟鍜岃嚜鍔ㄥ穿婧冩仮澶嶃傛垜浠亣瀹氬穿婧冩椂MySQL鏈嶅姟鍣ㄥ甫璐熻浇銆傚鏋滀笉甯﹁礋杞斤紝鍒欎笉闇瑕佹仮澶嶃

鍑虹幇鎿嶄綔绯荤粺宕╂簝鎴栫數婧愭晠闅滄椂锛屾垜浠彲浠ュ亣瀹氶噸鍚悗纭洏涓婄殑MySQL鏁版嵁浠嶅彲鐢ㄣ傜敱浜庡穿婧冿紝InnoDB鏁版嵁鏂囦欢涓殑鏁版嵁鍙兘涓嶅啀淇濇寔涓鑷存э紝浣InnoDB璇诲彇瀹冪殑鏃ュ織骞朵細鏌ュ埌鎸傝捣鐨勬彁浜ょ殑鍜屾湭鎻愪氦鐨勪簨鍔℃竻鍗曪紝瀹冧滑娌℃湁娓呯┖鍒版暟鎹枃浠朵腑銆InnoDB鑷姩鍗峰洖鏈彁浜ょ殑浜嬪姟锛屽苟娓呯┖鍒板畠鐨勬暟鎹枃浠朵腑銆傞氳繃MySQL閿欒鏃ュ織灏嗚鎭㈠杩囩▼鐩稿叧淇℃伅浼犺揪缁欑敤鎴枫備笅闈㈢殑渚嬪瓙涓烘棩蹇楁憳褰曪細

InnoDB: Database was not shut down normally.
InnoDB: Starting recovery from log files...
InnoDB: Starting log scan based on checkpoint at
InnoDB: log sequence number 0 13674004
InnoDB: Doing recovery: scanned up to log sequence number 0 13739520
InnoDB: Doing recovery: scanned up to log sequence number 0 13805056
InnoDB: Doing recovery: scanned up to log sequence number 0 13870592
InnoDB: Doing recovery: scanned up to log sequence number 0 13936128
...
InnoDB: Doing recovery: scanned up to log sequence number 0 20555264
InnoDB: Doing recovery: scanned up to log sequence number 0 20620800
InnoDB: Doing recovery: scanned up to log sequence number 0 20664692
InnoDB: 1 uncommitted transaction(s) which must be rolled back
InnoDB: Starting rollback of uncommitted transactions
InnoDB: Rolling back trx no 16745
InnoDB: Rolling back of trx no 16745 completed
InnoDB: Rollback of uncommitted transactions completed
InnoDB: Starting an apply batch of log records to the database...
InnoDB: Apply batch completed
InnoDB: Started
mysqld: ready for connections

濡傛灉鏂囦欢绯荤粺宕╂簝鎴栧嚭鐜扮‖浠堕棶棰橈紝鎴戜滑鍙互鍋囧畾閲嶅惎鍚庣‖鐩樹笂鐨MySQL鏁版嵁涓嶅彲鐢ㄣ傝繖璇存槑MySQL鏈兘鎴愬姛鍚姩锛屽洜涓轰竴浜涚‖鐩樻暟鎹潡涓嶅啀鍙銆傚湪杩欑鎯呭喌涓嬶紝闇瑕侀噸鏂版牸寮忓寲纭洏锛屽畨瑁呬竴涓柊鐨勶紝鎴栫籂姝i棶棰樸傜劧鍚庨渶瑕佷粠澶囦唤涓仮澶MySQL鏁版嵁锛岃繖璇存槑鎴戜滑蹇呴』鍏堝仛濂藉浠姐傝鎯崇‘淇濓紝搴斿強鏃惰繑鍥炲苟璁捐澶囦唤绛栫暐銆

5.9.2.1. 澶囦唤绛栫暐

鎴戜滑閮界煡閬撳繀椤绘寜璁″垝瀹氭湡杩涜澶囦唤銆傚彲浠ョ敤鍑犱釜宸ュ叿瀹屽叏澶囦唤(鍦ㄦ煇涓椂闂寸偣鐨勬暟鎹揩鐓)MySQL銆備緥濡傦紝InnoDB Hot BackupInnoDB鏁版嵁鏂囦欢鎻愪緵鍦ㄧ嚎闈炴暟鎹潡鐗╃悊澶囦唤锛mysqldump鎻愪緵鍦ㄧ嚎閫昏緫澶囦唤銆傝繖閲屼娇鐢mysqldump

鍋囧畾鎴戜滑鍦ㄦ槦鏈熸棩涓嬪崍1鐐硅繘琛屼簡澶囦唤锛屾鏃惰礋鑽疯緝浣庛備笅闈㈢殑鍛戒护鍙互瀹屽叏澶囦唤鎵鏈夋暟鎹簱涓殑鎵鏈InnoDB琛細

shell> mysqldump --single-transaction --all-databases > backup_sunday_1_PM.sql

杩欐槸鍦ㄧ嚎闈炲潡澶囦唤锛屼笉浼氬共鎵板琛ㄧ殑璇诲啓銆鎴戜滑浠ュ墠鍋囧畾鎴戜滑鐨勮〃涓InnoDB琛紝鍥犳--single-transaction浣跨敤涓鑷存у湴璇伙紝骞朵笖淇濊瘉mysqldump鎵鐪嬭鐨鏁版嵁涓嶄細鏇存敼銆(鍏跺畠瀹㈡埛绔InnoDB琛ㄨ繘琛岀殑鏇存敼涓嶄細琚mysqldump杩涚▼鐪嬭锛濡傛灉鎴戜滑杩樻湁鍏跺畠绫诲瀷鐨勮〃锛屾垜浠繀椤诲亣瀹氬湪澶囦唤杩囩▼涓畠浠笉浼氭洿鏀广備緥濡傦紝瀵逛簬mysql鏁版嵁搴撲腑鐨MyISAM锛屾垜浠繀椤诲亣瀹氬湪澶囦唤杩囩▼涓病鏈夊MySQL璐︽埛杩涜绠$悊鏇存敼銆

mysqldump鍛戒护浜х敓鐨.sql鏂囦欢鍖呭惈涓绯诲垪SQL INSERT璇彞锛屽彲浠ョ敤鏉ラ噸杞借浆鍌ㄧ殑琛ㄣ

闇瑕佽繘琛屽畬鍏ㄥ浠斤紝浣嗘湁鏃朵笉鏂逛究銆備細浜х敓澶х殑澶囦唤鏂囦欢骞堕渶瑕佽姳鏃堕棿鏉ョ敓鎴愩備粠鏌愪釜瑙掑害锛屽畬鍏ㄥ浠藉苟涓嶇悊鎯筹紝鍥犱负姣忎釜鎴愬姛鐨勫畬鍏ㄥ浠藉寘鎷墍鏈夋暟鎹紝鐢氳嚦鑷粠涓婁竴娆″畬鍏ㄥ浠戒互鏉ユ病鏈夋洿鏀圭殑閮ㄥ垎銆傚畬鎴愪簡鍒濅娇瀹屽叏澶囦唤鍚庯紝杩涜澧為噺澶囦唤浼氭洿鏈夋晥銆傝繖鏍峰浠芥枃浠惰灏忓緱澶氾紝澶囦唤鏃堕棿涔熻緝鐭備笉鍒╀箣澶勬槸锛屾仮澶嶆椂涓嶈兘鍙噸杞藉畬鍏ㄥ浠芥潵鎭㈠鏁版嵁銆傝繕蹇呴』瑕佺敤澧為噺澶囦唤鏉ユ仮澶嶅閲忔洿鏀广

瑕佹兂杩涜澧為噺澶囦唤锛屾垜浠渶瑕佷繚瀛樺閲忔洿鏀广傚簲浣跨敤--log-bin閫夐」鍚姩MySQL鏈嶅姟鍣紝浠ヤ究鏇存柊鏁版嵁鏃跺皢杩欎簺鏇存敼淇濆瓨鍒版枃浠朵腑銆傝閫夐」鍚敤浜岃繘鍒舵棩蹇楋紝鍥犳鏈嶅姟鍣ㄥ啓灏嗘瘡涓洿鏂版暟鎹殑SQL璇彞鍐欏叆MySQL浜岃繘鍒舵棩蹇椼傝鎴戜滑鐪嬬湅鐢--log-bin閫夐」鍚姩鐨勫凡缁忚繍琛屽鏃ョ殑MySQL鏈嶅姟鍣ㄧ殑鏁版嵁鐩綍銆傛垜浠壘鍒颁互涓MySQL浜岃繘鍒舵棩蹇楁枃浠讹細

-rw-rw---- 1 guilhem  guilhem   1277324 Nov 10 23:59 gbichot2-bin.000001
-rw-rw---- 1 guilhem  guilhem         4 Nov 10 23:59 gbichot2-bin.000002
-rw-rw---- 1 guilhem  guilhem        79 Nov 11 11:06 gbichot2-bin.000003
-rw-rw---- 1 guilhem  guilhem       508 Nov 11 11:08 gbichot2-bin.000004
-rw-rw---- 1 guilhem  guilhem 220047446 Nov 12 16:47 gbichot2-bin.000005
-rw-rw---- 1 guilhem  guilhem    998412 Nov 14 10:08 gbichot2-bin.000006
-rw-rw---- 1 guilhem  guilhem       361 Nov 14 10:07 gbichot2-bin.index

姣忔閲嶅惎锛MySQL鏈嶅姟鍣ㄧ敤搴忓垪涓殑涓嬩竴涓紪鍙峰垱寤轰竴涓柊鐨勪簩杩涘埗鏃ュ織鏂囦欢銆傚綋鏈嶅姟鍣ㄨ繍琛屾椂锛屼綘杩樺彲浠ラ氳繃鎵цFLUSH LOGS SQL璇彞鎴mysqladmin flush-logs鍛戒护锛屽憡璇夋湇鍔″櫒鍏抽棴褰撳墠鐨勪簩杩涘埗鏃ュ織鏂囦欢骞跺垱寤轰竴涓柊鏂囦欢銆mysqldump涔熸湁涓涓夐」鏉ユ竻绌烘棩蹇椼傛暟鎹洰褰曚腑鐨.index鏂囦欢鍖呭惈璇ョ洰褰曚笅鎵鏈MySQL浜岃繘鍒舵棩蹇楃殑娓呭崟銆傝鏂囦欢鐢ㄤ簬澶嶅埗銆

鎭㈠鏃MySQL浜岃繘鍒舵棩蹇楀緢閲嶈锛屽洜涓哄畠浠槸澧為噺澶囦唤銆傚鏋滆繘琛屽畬鍏ㄥ浠芥椂纭繚娓呯┖浜嗘棩蹇楋紝鍒欏悗闈㈠垱寤虹殑浜岃繘鍒舵棩蹇楁枃浠跺寘鍚簡澶囦唤鍚庣殑鎵鏈夋暟鎹洿鏀广傝鎴戜滑绋嶇◢淇敼鍓嶉潰鐨mysqldump鍛戒护锛岃瀹冨湪瀹屽叏澶囦唤鏃惰兘澶熸竻绌 MySQL浜岃繘鍒舵棩蹇楋紝浠ヤ究杞偍鏂囦欢鍖呭惈鍖呭惈鏂扮殑褰撳墠鐨勪簩杩涘埗鏃ュ織锛

shell> mysqldump --single-transaction --flush-logs --master-data=2
           --all-databases > backup_sunday_1_PM.sql

鎵ц璇ュ懡浠ゅ悗锛屾暟鎹洰褰曞垯鍖呭惈鏂扮殑浜岃繘鍒舵棩蹇楁枃浠讹紝gbichot2-bin.000007銆傜粨鏋.sql鏂囦欢鍖呭惈涓嬪垪琛岋細

-- Position to start replication or point-in-time 鎭㈠鏃y from
-- CHANGE MASTER TO MASTER_LOG_FILE='gbichot2-bin.000007',MASTER_LOG_POS=4;

鍥犱负mysqldump鍛戒护鍙互鎵ц瀹屽叏澶囦唤锛岃繖浜涜琛ㄧず涓や欢浜嬫儏锛

         .sql鏂囦欢鍖呭惈鎵鏈夊啓鍏gbichot2-bin.000007浜岃繘鍒舵棩蹇楁枃浠舵垨鏈鏂扮殑鏂囦欢涔嬪墠鐨勬洿鏀广

         澶囦唤鍚庢墍璁板綍鐨勬墍鏈夋暟鎹洿鏀逛笉鍑虹幇鍦.sql涓紝浣嗗嚭鐜板湪gbichot2-bin.000007浜岃繘鍒舵棩蹇楁枃浠舵垨鏈鏂扮殑鏂囦欢涓

鍦ㄦ槦鏈熶竴涓嬪崍1鐐癸紝鎴戜滑鍙互娓呯┖鏃ュ織寮濮嬫柊鐨勪簩杩涘埗鏃ュ織鏂囦欢鏉ュ垱寤哄閲忓浠姐備緥濡傦紝鎵цmysqladmin flush-logs鍛戒护鍒涘缓gbichot2-bin.000008銆傛槦鏈熸棩涓嬪崍1鐐圭殑瀹屽叏澶囦唤鍜屾槦鏈熶竴涓嬪崍1鐐逛箣闂寸殑鎵鏈夋洿鏀逛负鏂囦欢gbichot2-bin.000007銆傝澧為噺澶囦唤寰堥噸瑕侊紝鍥犳鏈濂藉皢瀹冨鍒跺埌瀹夊叏鐨勫湴鏂广(渚嬪锛屽浠藉埌纾佸甫鎴DVD涓婏紝鎴栧鍒跺埌鍙︿竴鍙版満鍣ㄤ笂锛鍦ㄦ槦鏈熶簩涓嬪崍1鐐癸紝鎵ц鍙︿竴涓mysqladmin flush-logs鍛戒护銆傛槦鏈熶竴涓嬪崍1鐐瑰拰鏄熸湡浜屼笅鍗1鐐逛箣闂寸殑鎵鏈夋墍鏈夋洿鏀逛负鏂囦欢gbichot2-bin.000008(涔熷簲澶嶅埗鍒版煇涓畨鍏ㄧ殑鍦版柟)

MySQL浜岃繘鍒舵棩蹇楀崰鎹‖鐩樼┖闂淬傝鎯抽噴鏀剧┖闂达紝搴旈殢鏃舵竻绌恒傛搷浣滄柟娉曟槸鍒犳帀涓嶅啀浣跨敤鐨勪簩杩涘埗鏃ュ織锛屼緥濡傝繘琛屽畬鍏ㄥ浠芥椂锛

shell> mysqldump --single-transaction --flush-logs --master-data=2
           --all-databases --delete-master-logs > backup_sunday_1_PM.sql

閲婏細濡傛灉浣犵殑鏈嶅姟鍣ㄤ负澶嶅埗涓绘湇鍔″櫒锛岀敤mysqldump --delete-master-logs鍒犳帀MySQL浜岃繘鍒舵棩蹇楀緢鍗遍櫓锛屽洜涓轰粠鏈嶅姟鍣ㄥ彲鑳借繕娌℃湁瀹屽叏澶勭悊璇ヤ簩杩涘埗鏃ュ織鐨勫唴瀹广

PURGE MASTER LOGS璇彞鐨勬弿杩颁腑瑙i噴浜嗕负浠涔堝湪鍒犳帀MySQL浜岃繘鍒舵棩蹇椾箣鍓嶅簲杩涜纭銆傚弬瑙13.6.1.1鑺傦紝鈥淧URGE MASTER LOGS璇硶鈥

5.9.2.2. 涓烘仮澶嶈繘琛屽浠

鐜板湪鍋囪鍦ㄦ槦鏈熶笁涓婂崍8鐐瑰嚭鐜颁簡鐏鹃毦鎬у穿婧冿紝闇瑕佷娇鐢ㄥ浠芥枃浠惰繘琛屾仮澶嶃傛仮澶嶆椂锛屾垜浠鍏堟仮澶嶆渶鍚庣殑瀹屽叏澶囦唤(浠庢槦鏈熸棩涓嬪崍1鐐瑰紑濮)銆傚畬鍏ㄥ浠芥枃浠舵槸涓绯诲垪SQL璇彞锛屽洜姝ゆ仮澶嶅畠寰堝鏄擄細

shell> mysql < backup_sunday_1_PM.sql

鍦ㄨ鐐癸紝鏁版嵁鎭㈠鍒版槦鏈熸棩涓嬪崍1鐐圭殑鐘舵併傝鎯虫仮澶嶄粠閭f椂璧风殑鏇存敼锛屾垜浠繀椤讳娇鐢ㄥ閲忓浠斤紝涔熷氨鏄紝gbichot2-bin.000007gbichot2-bin.000008浜岃繘鍒舵棩蹇楁枃浠躲傛牴鎹渶瑕佷粠澶囦唤澶勫彇杩囪繖浜涙枃浠讹紝鐒跺悗鎸変笅杩版柟寮忓鐞嗭細

shell> mysqlbinlog gbichot2-bin.000007 gbichot2-bin.000008 | mysql

鎴戜滑鐜板湪灏嗘暟鎹仮澶嶅埌鏄熸湡浜屼笅鍗1鐐圭殑鐘舵侊紝浣嗘槸浠庤鏃跺埢鍒板穿婧冧箣闂寸殑鏁版嵁浠嶇劧鏈変涪澶便傝鎯虫仮澶嶏紝鎴戜滑闇瑕MySQL鏈嶅姟鍣ㄥ皢MySQL浜岃繘鍒舵棩蹇椾繚瀛樺埌瀹夊叏鐨勪綅缃(RAID disks, SAN, ...)锛屽簲涓轰笌鏁版嵁鏂囦欢鐨勪繚瀛樹綅缃笉鍚岀殑鍦版柟锛屼繚璇佽繖浜涙棩蹇椾笉鍦ㄦ瘉鍧忕殑纭洏涓娿(涔熷氨鏄紝鎴戜滑鍙互鐢--log-bin閫夐」鍚姩鏈嶅姟鍣紝鎸囧畾涓涓叾瀹冪墿鐞嗚澶囦笂鐨勪笌鏁版嵁鐩綍涓嶅悓鐨勪綅缃傝繖鏍凤紝鍗充娇鍖呭惈璇ョ洰褰曠殑璁惧涓㈠け锛屾棩蹇椾篃涓嶄細涓㈠け锛濡傛灉鎴戜滑鎵ц浜嗚繖浜涙搷浣滐紝鎴戜滑鎵嬪ご涓婁細鏈gbichot2-bin.000009鏂囦欢锛屾垜浠彲浠ョ敤瀹冩潵鎭㈠澶ч儴鍒嗘渶鏂扮殑鏁版嵁鏇存敼锛岃屼笉浼氫涪澶卞埌宕╂簝鏃剁殑鏁版嵁銆

5.9.2.3. 澶囦唤绛栫暐鎽樿

鍑虹幇鎿嶄綔绯荤粺宕╂簝鎴栫數婧愭晠闅滄椂锛InnoDB鑷繁鍙互瀹屾垚鎵鏈夋暟鎹仮澶嶅伐浣溿備絾涓轰簡纭繚浣犲彲浠ョ潯濂借锛屽簲閬典粠涓嬮潰鐨勬寚瀵硷細

         涓瀹氱敤--log-bin鎴栫敋鑷--log-bin=log_name閫夐」杩愯MySQL鏈嶅姟鍣紝鍏朵腑鏃ュ織鏂囦欢鍚嶄綅浜庢煇涓畨鍏ㄥ獟浠嬩笂锛屼笉鍚屼簬鏁版嵁鐩綍鎵鍦ㄩ┍鍔ㄥ櫒銆傚鏋滀綘鏈夎繖鏍风殑瀹夊叏濯掍粙锛屾渶濂借繘琛岀‖鐩樿礋杞藉潎琛(杩欐牱鑳藉鎻愰珮鎬ц兘)

         瀹氭湡杩涜瀹屽叏澶囦唤锛屼娇鐢mysqldump鍛戒护杩涜鍦ㄧ嚎闈炲潡澶囦唤銆

         FLUSH LOGSmysqladmin flush-logs娓呯┖鏃ュ織杩涜瀹氭湡澧為噺澶囦唤銆

5.9.3. 鑷姩鎭㈠

濡傛灉MySQL鏈嶅姟鍣ㄥ惎鐢ㄤ簡浜岃繘鍒舵棩蹇楋紝浣犲彲浠ヤ娇鐢mysqlbinlog宸ュ叿鏉ユ仮澶嶄粠鎸囧畾鐨勬椂闂寸偣寮濮 (渚嬪锛屼粠浣犳渶鍚庝竴娆″浠)鐩村埌鐜板湪鎴栧彟涓涓寚瀹氱殑鏃堕棿鐐圭殑鏁版嵁銆傚叧浜庡惎鐢ㄤ簩杩涘埗鏃ュ織鐨勪俊鎭紝鍙傝5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥銆傚浜mysqlbinlog鐨勮缁嗕俊鎭紝鍙傝8.6鑺傦紝鈥渕ysqlbinlog锛氱敤浜庡鐞嗕簩杩涘埗鏃ュ織鏂囦欢鐨勫疄鐢ㄥ伐鍏封

瑕佹兂浠庝簩杩涘埗鏃ュ織鎭㈠鏁版嵁锛屼綘闇瑕佺煡閬撳綋鍓嶄簩杩涘埗鏃ュ織鏂囦欢鐨勮矾寰勫拰鏂囦欢鍚嶃備竴鑸彲浠ヤ粠閫夐」鏂囦欢(my.cnf or my.ini锛屽彇鍐充簬浣犵殑绯荤粺)涓壘鍒拌矾寰勩傚鏋滄湭鍖呭惈鍦ㄩ夐」鏂囦欢涓紝褰撴湇鍔″櫒鍚姩鏃讹紝鍙互鍦ㄥ懡浠よ涓互閫夐」鐨勫舰寮忕粰鍑恒傚惎鐢ㄤ簩杩涘埗鏃ュ織鐨勯夐」涓--log-bin銆傝鎯崇‘瀹氬綋鍓嶇殑浜岃繘鍒舵棩蹇楁枃浠剁殑鏂囦欢鍚嶏紝杈撳叆涓嬮潰鐨MySQL璇彞锛

SHOW BINLOG EVENTS \G

浣犺繕鍙互浠庡懡浠よ杈撳叆涓嬮潰鐨勫唴瀹癸細

mysql --user=root -pmy_pwd -e 'SHOW BINLOG EVENTS \G'

灏嗗瘑鐮my_pwd鏇挎崲涓烘湇鍔″櫒鐨root瀵嗙爜銆

5.9.3.1. 鎸囧畾鎭㈠鏃堕棿

瀵逛簬MySQL 4.1.4锛屽彲浠ュ湪mysqlbinlog璇彞涓氳繃--start-date--stop-date閫夐」鎸囧畾DATETIME鏍煎紡鐨勮捣姝㈡椂闂淬備妇渚嬭鏄庯紝鍋囪鍦ㄤ粖澶╀笂鍗10:00(浠婂ぉ鏄2005420)锛屾墽琛SQL璇彞鏉ュ垹闄や竴涓ぇ琛ㄣ傝鎯虫仮澶嶈〃鍜屾暟鎹紝浣犲彲浠ユ仮澶嶅墠鏅氫笂鐨勫浠斤紝骞惰緭鍏ワ細
mysqlbinlog --stop-date="2005-04-20 9:59:59" /var/log/mysql/bin.123456 \
     | mysql -u root -pmypwd

璇ュ懡浠ゅ皢鎭㈠鎴鍒板湪--stop-date閫夐」涓互DATETIME鏍煎紡缁欏嚭鐨勬棩鏈熷拰鏃堕棿鐨勬墍鏈夋暟鎹傚鏋滀綘娌℃湁妫娴嬪埌鍑犱釜灏忔椂鍚庤緭鍏ョ殑閿欒鐨SQL璇彞锛屽彲鑳戒綘鎯宠鎭㈠鍚庨潰鍙戠敓鐨勬椿鍔ㄣ傛牴鎹繖浜涳紝浣犲彲浠ョ敤璧蜂娇鏃ユ湡鍜屾椂闂村啀娆¤繍琛mysqlbinlog

mysqlbinlog --start-date="2005-04-20 10:01:00" /var/log/mysql/bin.123456 \
     | mysql -u root -pmypwd \

鍦ㄨ琛屼腑锛屼粠涓婂崍10:01鐧诲綍鐨SQL璇彞灏嗚繍琛屻傜粍鍚堟墽琛屽墠澶滅殑杞偍鏂囦欢鍜mysqlbinlog鐨勪袱琛屽彲浠ュ皢鎵鏈夋暟鎹仮澶嶅埌涓婂崍10:00鍓嶄竴绉掗挓銆備綘搴旀鏌ユ棩蹇椾互纭繚鏃堕棿纭垏銆備笅涓鑺備粙缁嶅浣曞疄鐜般

5.9.3.2. 鎸囧畾鎭㈠浣嶇疆

涔熷彲浠ヤ笉鎸囧畾鏃ユ湡鍜屾椂闂达紝鑰屼娇鐢mysqlbinlog鐨勯夐」--start-position--stop-position鏉ユ寚瀹氭棩蹇椾綅缃傚畠浠殑浣滅敤涓庤捣姝㈡棩閫夐」鐩稿悓锛屼笉鍚岀殑鏄粰鍑轰簡浠庢棩蹇楄捣鐨勪綅缃彿銆備娇鐢ㄦ棩蹇椾綅缃槸鏇村噯纭殑鎭㈠鏂规硶锛岀壒鍒槸褰撶敱浜庣牬鍧忔SQL璇彞鍚屾椂鍙戠敓璁稿浜嬪姟鐨勬椂鍊欍傝鎯崇‘瀹氫綅缃彿锛屽彲浠ヨ繍琛mysqlbinlog瀵绘壘鎵ц浜嗕笉鏈熸湜鐨勪簨鍔$殑鏃堕棿鑼冨洿锛屼絾搴斿皢缁撴灉閲嶆柊鎸囧悜鏂囨湰鏂囦欢浠ヤ究杩涜妫鏌ャ傛搷浣滄柟娉曚负锛
mysqlbinlog --start-date="2005-04-20 9:55:00" --stop-date="2005-04-20 10:05:00" \
      /var/log/mysql/bin.123456 > /tmp/mysql_restore.sql

璇ュ懡浠ゅ皢鍦/tmp鐩綍鍒涘缓灏忕殑鏂囨湰鏂囦欢锛屽皢鏄剧ず鎵ц浜嗛敊璇殑SQL璇彞鏃剁殑SQL璇彞銆備綘鍙互鐢ㄦ枃鏈紪杈戝櫒鎵撳紑璇ユ枃浠讹紝瀵绘壘浣犱笉瑕佹兂閲嶅鐨勮鍙ャ傚鏋滀簩杩涘埗鏃ュ織涓殑浣嶇疆鍙风敤浜庡仠姝㈠拰缁х画鎭㈠鎿嶄綔锛屽簲杩涜娉ㄩ噴銆傜敤log_pos鍔犱竴涓暟瀛楁潵鏍囪浣嶇疆銆備娇鐢ㄤ綅缃彿鎭㈠浜嗕互鍓嶇殑澶囦唤鏂囦欢鍚庯紝浣犲簲浠庡懡浠よ杈撳叆涓嬮潰鍐呭锛

mysqlbinlog --stop-position="368312" /var/log/mysql/bin.123456 \
    | mysql -u root -pmypwd 
 
mysqlbinlog --start-position="368315" /var/log/mysql/bin.123456 \
    | mysql -u root -pmypwd \ 

涓婇潰鐨勭1琛屽皢鎭㈠鍒板仠姝綅缃负姝㈢殑鎵鏈変簨鍔°備笅涓琛屽皢鎭㈠浠庣粰瀹氱殑璧峰浣嶇疆鐩村埌浜岃繘鍒舵棩蹇楃粨鏉熺殑鎵鏈変簨鍔°傚洜涓mysqlbinlog鐨勮緭鍑哄寘鎷瘡涓SQL璇彞璁板綍涔嬪墠鐨SET TIMESTAMP璇彞锛屾仮澶嶇殑鏁版嵁鍜岀浉鍏MySQL鏃ュ織灏嗗弽搴斾簨鍔℃墽琛岀殑鍘熸椂闂淬

5.9.4. 琛ㄧ淮鎶ゅ拰宕╂簝鎭㈠

鍚庨潰鍑犺妭璁ㄨ濡備綍浣跨敤myisamchk鏉ユ鏌ユ垨缁存姢MyISAM(瀵瑰簲.MYI.MYD鏂囦欢鐨勮〃)

浣犲彲浠ヤ娇鐢myisamchk瀹炵敤绋嬪簭鏉ヨ幏寰楁湁鍏充綘鐨勬暟鎹簱琛ㄧ殑淇℃伅鎴栨鏌ャ佷慨澶嶃佷紭鍖栦粬浠備笅鍒楀皬鑺傛弿杩板浣曡皟鐢myisamchk锛堝寘鎷畠鐨勯夐」鐨勬弿杩帮級锛屽浣曞缓绔嬭〃鐨勭淮鎶よ鍒掞紝浠ュ強濡備綍浣跨敤myisamchk鎵ц鍚勭鍔熻兘銆

灏界鐢myisamchk淇琛ㄥ緢瀹夊叏锛屽湪淇(鎴栦换浣曞彲浠ュぇ閲忔洿鏀硅〃鐨勭淮鎶ゆ搷浣)涔嬪墠鍏堣繘琛屽浠涔熸槸寰堝ソ鐨勪範鎯

褰卞搷绱㈠紩鐨myisamchk鎿嶄綔浼氫娇ULLTEXT绱㈠紩鐢full-text鍙傛暟閲嶅缓锛屼笉鍐嶄笌MySQL鏈嶅姟鍣ㄤ娇鐢ㄧ殑鍊煎吋瀹广傝鎯抽伩鍏嶏紝璇烽槄璇5.9.5.1鑺傦紝鈥滅敤浜巑yisamchk鐨勪竴鑸鐨勮鏄庛

鍦ㄨ澶氭儏鍐典笅锛屼綘浼氬彂鐜颁娇鐢SQL璇彞瀹炵幇MyISAM琛ㄧ殑缁存姢姣旀墽琛myisamchk鎿嶄綔瑕佸鏄撳湴澶氾細

         瑕佹兂妫鏌ユ垨缁存姢MyISAM琛紝浣跨敤CHECK TABLEREPAIR TABLE

         瑕佹兂浼樺寲MyISAM琛紝浣跨敤OPTIMIZE TABLE

         瑕佹兂鍒嗘瀽MyISAM琛紝浣跨敤ANALYZE TABLE

鍙互鐩存帴杩欎簺璇彞锛屾垨浣跨敤mysqlcheck瀹㈡埛绔▼搴忥紝鍙互鎻愪緵鍛戒护琛屾帴鍙c

杩欎簺璇彞姣myisamchk鏈夊埄鐨勫湴鏂规槸鏈嶅姟鍣ㄥ彲浠ュ仛浠讳綍宸ヤ綔銆備娇鐢myisamchk锛屼綘蹇呴』纭繚鏈嶅姟鍣ㄥ湪鍚屼竴鏃堕棿涓嶄娇鐢ㄨ〃銆傚惁鍒欙紝myisamchk鍜屾湇鍔″櫒涔嬮棿浼氬嚭鐜颁笉鏈熸湜鐨勭浉浜掑共娑夈

5.9.5. myisamchk锛歁yISAM琛ㄧ淮鎶ゅ疄鐢ㄥ伐鍏

鍙互浣跨敤myisamchk瀹炵敤绋嬪簭鏉ヨ幏寰楁湁鍏虫暟鎹簱琛ㄧ殑淇℃伅鎴栨鏌ャ佷慨澶嶃佷紭鍖栦粬浠myisamchk閫傜敤MyISAM(瀵瑰簲.MYI.MYD鏂囦欢鐨勮〃)

璋冪敤myisamchk鐨勬柟娉曪細

shell> myisamchk [options] tbl_name ...

options鎸囧畾浣犳兂璁myisamchk鍋氫粈涔堛傚湪鍚庨潰鎻忚堪瀹冧滑銆傝繕鍙互閫氳繃璋冪敤myisamchk --help寰楀埌閫夐」鍒楄〃銆

tbl_name鏄綘鎯宠妫鏌ユ垨淇鐨勬暟鎹簱琛ㄣ傚鏋滀綘涓嶅湪鏁版嵁搴撶洰褰曠殑鏌愬杩愯myisamchk锛屼綘蹇呴』鎸囧畾鏁版嵁搴撶洰褰曠殑璺緞锛屽洜涓myisamchk涓嶇煡閬撲綘鐨勬暟鎹簱浣嶄簬鍝効銆傚疄闄呬笂锛myisamchk涓嶅湪涔庝綘姝e湪鎿嶄綔鐨勬枃浠舵槸鍚︿綅浜庝竴涓暟鎹簱鐩綍锛涗綘鍙互灏嗗搴斾簬鏁版嵁搴撹〃鐨勬枃浠舵嫹璐濆埌鍒骞朵笖鍦ㄩ偅閲屾墽琛屾仮澶嶆搷浣溿

濡傛灉浣犳効鎰忥紝鍙互鐢myisamchk鍛戒护琛屽懡鍚嶅嚑涓〃銆傝繕鍙互閫氳繃鍛藉悕绱㈠紩鏂囦欢( .MYI鍚庣紑)鏉ユ寚瀹氫竴涓〃銆傚畠鍏佽浣犻氳繃浣跨敤妯″紡*.MYI鎸囧畾鍦ㄤ竴涓洰褰曟墍鏈夌殑琛ㄣ備緥濡傦紝濡傛灉浣犲湪鏁版嵁搴撶洰褰曪紝鍙互杩欐牱鍦ㄧ洰褰曚笅妫鏌ユ墍鏈夌殑MyISAM琛細

shell> myisamchk *.MYI

濡傛灉浣犱笉鍦ㄦ暟鎹簱鐩綍涓嬶紝鍙氳繃鎸囧畾鍒扮洰褰曠殑璺緞妫鏌ユ墍鏈夊湪閭i噷鐨勮〃锛

shell> myisamchk /path/to/database_dir/*.MYI

浣犵敋鑷冲彲浠ラ氳繃涓MySQL鏁版嵁鐩綍鐨勮矾寰勬寚瀹氫竴涓氶厤绗︽潵妫鏌ユ墍鏈夌殑鏁版嵁搴撲腑鐨勬墍鏈夎〃锛

shell> myisamchk /path/to/datadir/*/*.MYI

鎺ㄨ崘鐨勫揩閫熸鏌ユ墍鏈MyISAM琛ㄧ殑鏂瑰紡鏄細

shell> myisamchk --silent --fast /path/to/datadir/*/*.MYI

濡傛灉浣犳兂瑕佹鏌ユ墍鏈MyISAM琛ㄥ苟淇浠讳綍鐮村潖鐨勮〃锛屽彲浠ヤ娇鐢ㄤ笅闈㈢殑鍛戒护锛

shell> myisamchk --silent --force --fast --update-state \
          -O key_buffer=64M -O sort_buffer=64M \
          -O read_buffer=1M -O write_buffer=1M \
          /path/to/datadir/*/*.MYI

璇ュ懡浠ゅ亣瀹氫綘鏈夊ぇ浜64MB鐨勮嚜鐢卞唴瀛樸傚叧浜庣敤myisamchk鍒嗛厤鍐呭瓨鐨勮缁嗕俊鎭紝鍙傝5.9.5.5鑺傦紝鈥myisamchk鍐呭瓨浣跨敤鈥

褰撲綘杩愯myisamchk鏃讹紝蹇呴』纭繚鍏跺畠绋嬪簭涓嶄娇鐢ㄨ〃銆傚惁鍒欙紝褰撲綘杩愯myisamchk鏃讹紝浼氭樉绀轰笅闈㈢殑閿欒娑堟伅锛

warning: clients are using or haven't closed the table properly

杩欒鏄庝綘姝e皾璇曟鏌ユ琚彟涓涓繕娌℃湁鍏抽棴鏂囦欢鎴栧凡缁忕粓姝㈣屾病鏈夋纭湴鍏抽棴鏂囦欢鐨勭▼搴(渚嬪mysqld鏈嶅姟鍣)鏇存柊鐨勮〃銆

濡傛灉mysqld姝e湪杩愯锛屼綘蹇呴』閫氳繃FLUSH TABLES寮哄埗娓呯┖浠嶇劧鍦ㄥ唴瀛樹腑鐨勪换浣曡〃淇敼銆傚綋浣犺繍琛myisamchk鏃讹紝蹇呴』纭繚鍏跺畠绋嬪簭涓嶄娇鐢ㄨ〃銆傞伩鍏嶈闂鐨勬渶瀹规槗鐨勬柟娉曟槸浣跨敤CHECK TABLE鑰屼笉鐢myisamchk鏉ユ鏌ヨ〃銆

5.9.5.1. 鐢ㄤ簬myisamchk鐨勪竴鑸

鏈妭鎻忚堪鐨勯夐」鍙互鐢ㄤ簬鐢myisamchk鎵ц鐨勪换浣曠被鍨嬬殑琛ㄧ淮鎶ゆ搷浣溿傛湰鑺傚悗闈㈢殑绔犺妭涓弿杩扮殑閫夐」鍙傚悎鍏蜂綋鎿嶄綔锛屼緥濡傛鏌ユ垨淇琛ㄣ

         --help-?

鏄剧ず甯姪娑堟伅骞堕鍑恒

         --debug=debug_options, -# debug_options

杈撳嚭璋冭瘯璁板綍鏂囦欢銆debug_options瀛楃涓茬粡甯告槸'd:t:o,filename'

         --silent-s

娌夐粯妯″紡銆備粎褰撳彂鐢熼敊璇椂鍐欒緭鍑恒備綘鑳戒娇鐢-s涓ゆ(-ss)myisamchk娌夐粯銆

         --verbose-v

鍐楅暱妯″紡銆傛墦鍗版洿澶氱殑淇℃伅銆傝繖鑳戒笌-d-e涓璧蜂娇鐢ㄣ備负浜嗘洿鍐楅暱锛屼娇鐢-v澶氭(-vv, -vvv)

         --version, -V

鏄剧ず鐗堟湰淇℃伅骞堕鍑恒

         --wait, -w

濡傛灉琛ㄨ閿佸畾锛屼笉鏄彁绀洪敊璇粓姝紝鑰屾槸鍦ㄧ户缁墠绛夊緟鍒拌〃琚В閿併傝娉ㄦ剰濡傛灉鐢--skip-external-locking閫夐」杩愯mysqld锛屽彧鑳界敤鍙︿竴涓myisamchk鍛戒护閿佸畾琛ㄣ

杩樺彲浠ラ氳繃--var_name=value閫夐」璁剧疆涓嬮潰鐨勫彉閲忥細

鍙橀噺

榛樿鍊

decode_bits

9

ft_max_word_len

鍙栧喅浜庣増鏈

ft_min_word_len

4

ft_stopword_file

鍐呭缓鍒楄〃

key_buffer_size

523264

myisam_block_size

1024

read_buffer_size

262136

sort_buffer_size

2097144

sort_key_blocks

16

stats_method

nulls_unequal

write_buffer_size

262136

鍙互鐢myisamchk --help妫鏌myisamchk鍙橀噺鍙婂叾 榛樿鍊硷細

褰撶敤鎺掑簭閿间慨澶嶉敭鍊兼椂浣跨敤sort_buffer_size锛屼娇鐢--recover鏃惰繖鏄緢鏅氱殑鎯呭喌銆

褰撶敤--extend-check妫鏌ヨ〃鎴栭氳繃涓琛屼竴琛屽湴灏嗛敭鍊兼彃鍏ヨ〃涓(濡傚悓鏅氭彃鍏)鏉ヤ慨鏀归敭鍊兼椂浣跨敤Key_buffer_size銆傚湪浠ヤ笅鎯呭喌閫氳繃閿肩紦鍐插尯杩涜淇锛

         浣跨敤--safe-recover

         褰撶洿鎺ュ垱寤洪敭鍊兼枃浠舵椂锛岄渶瑕佸閿兼帓搴忕殑涓存椂鏂囦欢鏈変袱鍊嶅ぇ銆傞氬父鏄綋CHARVARCHAR銆佹垨TEXT鍒楃殑閿艰緝澶х殑鎯呭喌锛屽洜涓烘帓搴忔搷浣滃湪澶勭悊杩囩▼涓渶瑕佷繚瀛樺叏閮ㄩ敭鍊笺傚鏋滀綘鏈夊ぇ閲忎复鏃剁┖闂达紝鍙互閫氳繃鎺掑簭寮哄埗浣跨敤myisamchk鏉ヤ慨澶嶏紝鍙互浣跨敤--sort-recover閫夐」銆

閫氳繃閿肩紦鍐插尯鐨勪慨澶嶅崰鐢ㄧ殑纭洏绌洪棿姣斾娇鐢ㄦ帓搴忎箞灏戯紝浣嗘槸瑕佹參銆

濡傛灉鎯宠蹇熶慨澶嶏紝灏key_buffer_sizesort_buffer_size鍙橀噺璁剧疆鍒板ぇ绾﹀彲鐢ㄥ唴瀛樼殑25%銆傚彲浠ュ皢涓や釜鍙橀噺璁剧疆涓鸿緝澶х殑鍊硷紝鍥犱负涓涓椂闂村彧浣跨敤涓涓彉閲忋

myisam_block_size鏄敤浜庣储寮曞潡鐨勫唴瀛樺ぇ灏忋

stats_method褰卞搷褰撶粰瀹--analyze閫夐」鏃讹紝濡備綍涓虹储寮曠粺璁℃悳闆嗗鐞NULL鍊笺傚畠濡傚悓myisam_stats_method绯荤粺鍙橀噺銆傝缁嗕俊鎭弬瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥7.4.7鑺傦紝鈥淢yISAM绱㈠紩缁熻闆嗗悎鈥myisam_stats_method鐨勬弿杩般

ft_min_word_lenft_max_word_len琛ㄧずFULLTEXT绱㈠紩鐨勬渶灏忓拰鏈澶у瓧闀裤ft_stopword_file涓哄仠姝㈠瓧鏂囦欢鐨勬枃浠跺悕銆傞渶瑕佸湪浠ヤ笅鐜涓鍏惰繘琛岃缃

濡傛灉浣犱娇鐢myisamchk鏉ヤ慨鏀硅〃绱㈠紩(渚嬪淇鎴栧垎鏋)锛屼娇鐢ㄦ渶灏忓拰鏈澶у瓧闀垮拰鍋滄瀛楁枃浠剁殑 榛樿鍏ㄦ枃鍙傛暟鍊硷紙闄ら潪浣犲彟澶栨寚瀹氾級閲嶅缓FULLTEXT绱㈠紩銆傝繖鏍蜂細瀵艰嚧鏌ヨ澶辫触銆

鍑虹幇杩欎簺闂鏄洜涓哄彧鏈夋湇鍔″櫒鐭ラ亾杩欎簺鍙傛暟銆傚畠浠病鏈変繚瀛樺湪MyISAM绱㈠紩鏂囦欢涓傚鏋滀綘淇敼浜嗘湇鍔″櫒涓殑鏈灏忔垨鏈澶у瓧闀挎垨鍋滄瀛楁枃浠讹紝瑕侀伩鍏嶈闂锛屼负鐢ㄤ簬mysqldmyisamchk鎸囧畾鐩稿悓鐨ft_min_word_lenft_max_word_lenft_stopword_file鍊笺備緥濡傦紝濡傛灉浣犲皢鏈灏忓瓧闀胯缃负3,鍙互杩欐牱浣跨敤myisamchk鏉ヤ慨澶嶈〃锛

shell> myisamchk --recover --ft_min_word_len=3 tbl_name.MYI

瑕佹兂纭繚myisamchk鍜屾湇鍔″櫒浣跨敤鐩稿悓鐨勫叏鏂囧弬鏁板硷紝鍙互灏嗗畠浠斁鍏ラ夐」鏂囦欢鐨[mysqld][myisamchk]灏忚妭锛

[mysqld]
ft_min_word_len=3
 
[myisamchk]
ft_min_word_len=3

闄や簡myisamchk锛岃繕鍙互浣跨敤REPAIR TABLEANALYZE TABLEOPTIMIZE TABLEALTER TABLE銆傝繖浜涜鍙ョ敱鏈嶅姟鍣ㄦ墽琛岋紝鐭ラ亾瑕佷娇鐢ㄧ殑姝g‘鐨勫叏鏂囧弬鏁板笺

5.9.5.2. 鐢ㄤ簬myisamchk鐨勬鏌ラ夐」

myisamchk鏀寔涓嬮潰鐨勮〃妫鏌ユ搷浣滈夐」锛

         --check, -c

妫鏌ヨ〃鐨勯敊璇傚鏋滀綘涓嶆槑纭寚瀹氭搷浣滅被鍨嬮夐」锛岃繖灏辨槸榛樿鎿嶄綔銆

         --check-only-changed, -C

鍙鏌ヤ笂娆℃鏌ュ悗鏈夊彉鏇寸殑琛ㄣ

         --extend-check, -e

闈炲父浠旂粏鍦版鏌ヨ〃銆傚鏋滆〃鏈夎澶氱储寮曞皢浼氱浉褰撴參銆傝閫夐」鍙兘鐢ㄤ簬鏋佺鎯呭喌銆備竴鑸儏鍐典笅锛屽彲浠ヤ娇鐢myisamchkmyisamchk --medium-check鏉ョ‘瀹氳〃鍐呮槸鍚︽湁閿欒銆

濡傛灉浣犱娇鐢ㄤ簡--extend-check骞朵笖鏈夊厖鍒嗙殑鍐呭瓨锛屽皢key_buffer_size鍙橀噺璁剧疆涓鸿緝澶х殑鍊煎彲浠ヤ娇淇鎿嶄綔杩愯寰楁洿蹇

         --fast-F

鍙鏌ユ病鏈夋纭叧闂殑琛ㄣ

         --force, -f

濡傛灉myisamchk鍙戠幇琛ㄥ唴鏈変换浣曢敊璇紝鍒欒嚜鍔ㄨ繘琛屼慨澶嶃傜淮鎶ょ被鍨嬩笌--repair-r閫夐」鎸囧畾鐨勭浉鍚屻

         --information, -i

鎵撳嵃鎵妫鏌ヨ〃鐨勭粺璁′俊鎭

         --medium-check, -m

--extend-check鏇村揩閫熷湴杩涜妫鏌ャ傚彧鑳藉彂鐜99.99%鐨勯敊璇紝鍦ㄥぇ澶氭暟鎯呭喌涓嬪氨瓒冲浜嗐

         --read-only, -T

涓嶈灏嗚〃鏍囪涓哄凡缁忔鏌ャ傚鏋滀綘浣跨敤myisamchk鏉ユ鏌ユ琚叾瀹冨簲鐢ㄧ▼搴忎娇鐢ㄨ屾病鏈夐攣瀹氱殑琛ㄥ緢鏈夌敤锛屼緥濡傚綋鐢--skip-external-locking閫夐」杩愯鏃惰繍琛mysqld

         --update-state, -U

灏嗕俊鎭繚瀛樺湪.MYI鏂囦欢涓紝鏉ヨ〃绀鸿〃妫鏌ョ殑鏃堕棿浠ュ強鏄惁琛ㄥ穿婧冧簡銆傝閫夐」鐢ㄦ潵鍏呭垎鍒╃敤--check-only-changed閫夐」锛屼絾濡傛灉mysqld鏈嶅姟鍣姝d娇鐢ㄨ〃骞朵笖姝g敤--skip-external-locking閫夐」杩愯鏃朵笉搴斾娇鐢ㄨ閫夐」銆

5.9.5.3. myisamchk鐨勪慨澶嶉夐」

myisamchk鏀寔涓嬮潰鐨勮〃淇鎿嶄綔鐨勯夐」锛

         --backup, -B

.MYD鏂囦欢澶囦唤涓file_name-time.BAK

         --character-sets-dir=path

瀛楃闆嗗畨瑁呯洰褰曘傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --correct-checksum

绾犳琛ㄧ殑鏍¢獙鍜屼俊鎭

         --data-file-length=len, -D len

鏁版嵁鏂囦欢鐨勬渶澶ч暱搴(褰撻噸寤烘暟鎹枃浠朵笖涓衡滄弧鈥濇椂)

         --extend-check-e

杩涜淇锛岃瘯鍥句粠鏁版嵁鏂囦欢鎭㈠姣忎竴琛屻備竴鑸儏鍐典細鍙戠幇澶ч噺鐨勫瀮鍦捐銆備笉瑕佷娇鐢ㄨ閫夐」,闄ら潪浣犱笉椤惧悗鏋溿

         --force, -f

瑕嗙洊鏃х殑涓棿鏂囦欢(鏂囦欢鍚嶇被浼tbl_name.TMD)锛岃屼笉鏄腑鏂

         --keys-used=val, -k val

瀵逛簬myisamchk锛岃閫夐」鍊间负浣嶅硷紝璇存槑瑕佹洿鏂扮殑绱㈠紩銆傞夐」鍊肩殑姣忎竴涓簩杩涘埗浣嶅搴旇〃鐨勪竴涓储寮曪紝鍏朵腑绗竴涓储寮曞搴斾綅0銆傞夐」鍊0绂佺敤瀵规墍鏈夌储寮曠殑鏇存柊锛屽彲浠ヤ繚璇佸揩閫熸彃鍏ャ傞氳繃myisamchk -r鍙互閲嶆柊婵娲昏绂佺敤鐨勭储寮曘

         --no-symlinks, -l

涓嶈窡闅忕鍙疯繛鎺ャ傞氬父myisamchk淇涓涓鍙疯繛鎺ユ墍鎸囩殑琛ㄣ傚湪MySQL 4.0涓閫夐」涓嶅瓨鍦紝鍥犱负浠4.0寮濮嬬殑鐗堟湰鍦ㄤ慨澶嶈繃绋嬩腑涓嶇Щ闄ょ鍙烽摼鎺ャ

         --parallel-recover, -p

-r-n鐨勭敤娉曠浉鍚岋紝浣嗕娇鐢ㄤ笉鍚岀殑绾跨▼骞惰鍒涘缓鎵鏈夐敭銆杩欐槸alpha浠g爜銆傝嚜宸辨壙鎷呴闄╋紒

         --quick-q

涓嶄慨鏀规暟鎹枃浠讹紝蹇熻繘琛屼慨澶嶃傚嚭鐜板鍒堕敭鏃讹紝浣犲彲浠ヤ袱娆℃寚瀹氳椤逛互寮哄埗myisamchk淇敼鍘熸暟鎹枃浠躲

         --recover, -r

鍙互淇鍑犱箮鎵鏈変竴鍒囬棶棰橈紝闄ら潪鍞竴鐨勯敭涓嶅敮涓鏃(瀵逛簬MyISAM琛紝杩欐槸闈炲父涓嶅彲鑳界殑鎯呭喌)銆傚鏋滀綘鎯宠鎭㈠琛紝杩欐槸棣栧厛瑕佸皾璇曠殑閫夐」銆傚鏋myisamchk鎶ュ憡琛ㄤ笉鑳界敤-r鎭㈠锛屽垯鍙兘灏濊瘯-o銆傚湪涓嶅お鍙兘鐨勬儏鍐典笅-r澶辫触锛屾暟鎹枃浠朵繚鎸佸畬濂斤級

濡傛灉浣犳湁澶ч噺鍐呭瓨锛屼綘搴斿鍔sort_buffer_size鐨勫

         --safe-recover, -o

浣跨敤涓涓佺殑鎭㈠鏂规硶璇诲彇锛屾寜椤哄簭璇诲彇鎵鏈夎锛屽苟鏍规嵁鎵惧埌鐨勮鏇存柊鎵鏈夌储寮曟爲銆傝繖姣-r鎱簺锛屼絾鏄兘澶勭悊-r涓嶈兘澶勭悊鐨勬儏鍐点傝鎭㈠鏂规硶浣跨敤鐨勭‖鐩樼┖闂存瘮-r灏戙備竴鑸儏鍐碉紝浣犲簲棣栧厛鐢-r缁翠慨锛屽鏋-r澶辫触鍒欑敤-o

濡傛灉浣犳湁澶ч噺鍐呭瓨锛屼綘搴斿鍔sort_buffer_size鐨勫

         (OBSOLETE) --set-character-set=name

MySQL 5.1涓笉浣跨敤銆傚弬瑙--set-collation

         --set-collation=name

鏇存敼鐢ㄦ潵鎺掑簭琛ㄧ储寮曠殑鏍″瑙勫垯銆傛牎瀵硅鍒欏悕鐨勭涓閮ㄥ垎鍖呭惈瀛楃闆嗗悕銆

         --sort-recover, -n

寮哄埗myisamchk閫氳繃鎺掑簭鏉ヨВ鏋愰敭鍊硷紝鍗充娇涓存椂鏂囦欢灏嗗彲鑳藉緢澶с

         --tmpdir=path, -t path

鐢ㄤ簬淇濆瓨涓存椂鏂囦欢鐨勭洰褰曠殑璺緞銆傚鏋滄湭璁剧疆锛myisamchk浣跨敤TMPDIR鐜鍙橀噺鐨勫笺tmpdir鍙互璁剧疆涓轰竴绯诲垪鐩綍璺緞锛岀敤浜庢垚鍔熷湴浠round-robin妯″紡鍒涘缓涓存椂鏂囦欢銆傚湪Unix涓紝鐩綍鍚嶄箣闂寸殑闂撮殧瀛楃涓哄啋鍙(:)锛屽湪WindowsNetWareOS/2涓负鍒嗗彿 ()

         --unpack-u

灏嗙敤myisampack鎵撳寘鐨勮〃瑙e寘銆

5.9.5.4. 鐢ㄤ簬myisamchk鐨勫叾瀹冮夐」

myisamchk鏀寔浠ヤ笅琛ㄦ鏌ュ拰淇涔嬪鐨勫叾瀹冩搷浣滅殑閫夐」锛

         --analyze-a

鍒嗘瀽閿肩殑鍒嗗竷銆傝繖閫氳繃璁╄仈缁撲紭鍖栧櫒鏇村ソ鍦伴夋嫨琛ㄥ簲璇ヤ互浠涔堟搴忚仈缁撳拰搴旇浣跨敤鍝釜閿潵鏀硅繘鑱旂粨鎬ц兘銆傝鎯宠幏鍙栧垎甯冪浉鍏充俊鎭紝浣跨敤myisamchk --description --verbose tbl_name鍛戒护鎴SHOW KEYS FROM tbl_name璇彞銆

         --description, -d

鎵撳嵃鍑哄叧浜庤〃鐨勬弿杩版т俊鎭

         --set-auto-increment[=value], -A[value]

寮哄埗浠庣粰瀹氬煎紑濮嬬殑鏂拌褰曚娇鐢AUTO_INCREMENT缂栧彿(鎴栧鏋滃凡缁忔湁AUTO_INCREMENT鍊煎ぇ灏忕殑璁板綍锛屽簲浣跨敤鏇撮珮鍊)銆傚鏋滄湭鎸囧畾value锛屾柊璁板綍鐨AUTO_INCREMENT缂栧彿搴斾娇鐢ㄥ綋鍓嶈〃鐨勬渶澶у煎姞涓1

         --sort-index, -S

浠ヤ粠楂樺埌浣庣殑椤哄簭鎺掑簭绱㈠紩鏍戝潡銆傝繖灏嗕紭鍖栨悳瀵诲苟涓斿皢浣挎寜閿肩殑琛ㄦ壂鎻忔洿蹇

         --sort-records=N, -R N

鏍规嵁涓涓叿浣撶储寮曟帓搴忚褰曘傝繖浣夸綘鐨勬暟鎹洿灞閮ㄥ寲骞朵笖鍙互鍔犲揩鍦ㄨ閿笂鐨SELECTORDER BY鐨勮寖鍥存悳绱€傦紙绗竴娆″仛鎺掑簭鍙兘寰堟參锛侊級涓轰簡鎵惧嚭涓寮犺〃鐨勭储寮曠紪鍙凤紝浣跨敤SHOW INDEX锛屽畠浠myisamchk鐪嬭浠栦滑鐨勭浉鍚岄『搴忔樉绀轰竴寮犺〃鐨勭储寮曘傜储寮曚粠1寮濮嬬紪鍙枫

濡傛灉閿病鏈夋墦鍖(PACK_KEYS=0)锛屽畠浠殑闀垮害鐩稿悓锛屽洜姝ゅ綋myisamchk 鎺掑簭骞剁Щ鍔ㄨ褰曟椂锛屽彧瑕嗙洊绱㈠紩涓殑璁板綍鍋忕Щ閲忋傚鏋滈敭宸茬粡鎵撳寘(PACK_KEYS=1)myisamchk蹇呴』鍏堣В寮鎵撳寘鐨勯敭鍧楋紝鐒跺悗閲嶆柊鍒涘缓绱㈠紩骞跺啀娆″皢閿潡鎵撳寘銆(鍦ㄨ繖绉嶆儏鍐典笅锛岄噸鏂板垱寤虹储寮曟瘮鏇存柊姣忎釜绱㈠紩鐨勫亸绉婚噺瑕佸揩锛

5.9.5.5.聽myisamchk鍐呭瓨浣跨敤

褰撲綘杩愯myisamchk鏃跺唴瀛樺垎閰嶉噸瑕.MYIsamchk浣跨敤鐨勫唴瀛樺ぇ灏忎笉鑳借秴杩囩敤-O閫夐」鎸囧畾鐨勩傚鏋滀綘鎯冲姣忎竴涓ぇ琛ㄤ娇鐢myisamchk锛屼綘蹇呴』棣栧厛纭畾浣犳兂浣跨敤澶氬皯鍐呭瓨銆備慨澶嶆椂鍙互浣跨敤鐨 榛樿鍊煎彧鏈3MB銆備娇鐢ㄦ洿澶х殑鍐呭瓨锛屽彲浠ヨmyisamchk宸ヤ綔寰楁洿蹇竴浜涖備緥濡傦紝濡傛灉鏈夊ぇ浜32MBRAM锛屽彲浠ヤ娇鐢ㄥ涓嬫墍绀洪夐」(闄や簡浣犲彲浠ユ寚瀹氱殑鍏跺畠閫夐」)

shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...

瀵逛簬澶у鏁版儏鍐碉紝浣跨敤-O sort=16M搴旇瓒冲浜嗐

搴旇浣myisamchk浣跨敤TMPDIR涓殑涓存椂鏂囦欢銆傚鏋TMPDIR鎸囧悜鍐呭瓨鏂囦欢绯荤粺锛屼綘鍙兘寰堝鏄撳緱鍒板唴瀛樻孩鍑虹殑閿欒銆傚鏋滃彂鐢燂紝璁惧畾TMPDIR鎸囧悜鏈夋洿澶氱┖闂寸殑鏂囦欢绯荤粺鐩綍骞朵笖閲嶅惎myisamchk

淇鏃myisamchk涔熼渶瑕佸ぇ閲忕‖鐩樼┖闂达細

         灏嗘暟鎹枃浠跺ぇ灏忔墿澶т竴鍊(鍘熸枃浠跺拰澶嶅埗鏂囦欢)銆傚鏋滀綘鐢--quick淇鍒欎笉闇瑕佽绌洪棿锛涘湪杩欑鎯呭喌涓嬶紝鍙噸鏂板垱寤轰簡绱㈠紩鏂囦欢銆傚湪鏂囦欢绯荤粺涓婇渶瑕佺殑绌洪棿涓庡師鏁版嵁鏂囦欢鐩稿悓锛(鍒涘缓鐨勫鍒舵枃浠朵綅浜庡師鏂囦欢鎵鍦ㄧ洰褰曪級

         浠f浛鏃х储寮曟枃浠剁殑鏂扮储寮曟枃浠舵墍鍗犵┖闂淬備慨澶嶅伐浣滀竴寮濮嬶紝灏卞鏃х储寮曟枃浠惰繘琛屼簡鍒犲噺锛屽洜姝や綘閫氬父浼氬拷鐣ヨ绌洪棿銆傚湪鏂囦欢绯荤粺涓婇渶瑕佺殑璇ョ┖闂翠笌鍘熸暟鎹枃浠剁浉鍚岋紒

         褰撲娇鐢--recover---sort-recover(浣嗕笉浣跨敤--safe-recover)鏃讹紝闇瑕佹帓搴忕紦鍐插尯绌洪棿銆傞渶瑕佺殑绌洪棿涓猴細

                (largest_key + row_pointer_length) * number_of_rows * 2

鍙互鐢myisamchk -dv tbl_name妫鏌ラ敭鍊煎拰row_pointer_length鐨勯暱搴︺傚湪涓存椂鐩綍鍒嗛厤璇ョ┖闂(TMPDIR--tmpdir=path鎸囧畾)

濡傛灉鍦ㄤ慨澶嶈繃绋嬩腑鍑虹幇纭洏绌洪棿闂锛屽彲浠ヨ瘯璇曠敤--safe-recover浠f浛--recover

5.9.5.6. 灏唌yisamchk鐢ㄤ簬宕╂簝鎭

濡傛灉鐢--skip-external-locking杩愯mysqld(鍦ㄦ煇浜涚郴缁熶笂涓 榛樿璁剧疆锛屼緥濡Linux)锛屽綋mysqld浣跨敤鏌愪釜琛ㄦ椂锛屼綘涓嶈兘鍙潬鍦颁娇鐢myisamchk鏉ユ鏌ョ浉鍚岀殑琛ㄣ傚綋浣犺繍琛myisamchk鏃跺鏋滃彲浠ョ‘淇濇病鏈変汉鍦ㄩ氳繃mysqld璁块棶琛紝鍦ㄥ紑濮嬫鏌ヨ〃鍓嶏紝浣犲彧闇瑕佽繍琛mysqladmin flush-tables銆傚鏋滀綘涓嶈兘淇濊瘉锛屽垯浣犳鏌ヨ〃鏃朵綘蹇呴』鍋滄mysqld銆傚鏋mysqld鏇存柊琛ㄦ椂杩愯myisamchk锛屼綘鍙兘浼氳幏寰楄〃琚牬鍧忕殑璀﹀憡锛屽嵆浣夸簨瀹炲苟闈炲姝ゃ

濡傛灉涓嶄娇鐢--skip-external-locking锛屽彲浠ラ殢鏃朵娇鐢myisamchk鏉ユ鏌ヨ〃銆傚綋妫鏌ヨ〃鏃讹紝鎵鏈夊皾璇曟洿鏂拌〃鐨勫鎴风灏嗙瓑寰咃紝鐩村埌myisamchk鍑嗗濂藉彲浠ョ户缁

濡傛灉浣跨敤myisamchk鏉ヤ慨澶嶆垨浼樺寲琛紝蹇呴』纭繚mysqld鏈嶅姟鍣娌℃湁鍦ㄤ娇鐢ㄨ琛(濡傛灉浣犳浣跨敤--skip-external-locking閫夐」涔熼傜敤)銆傚鏋滀笉鍏抽棴mysqld锛屽湪杩愯myisamchk涔嬪墠鑷冲皯搴旀墽琛mysqladmin flush-tables銆傚鏋滄湇鍔″櫒鍜myisamchk鍚屾椂璁块棶琛紝琛鍙兘浼氳鐮村潖

鏈妭鎻忚堪濡備綍妫鏌ュ拰澶勭悊MySQL鏁版嵁搴撲腑鐨勬暟鎹牬鍧忋傚鏋滆〃缁忓父琚牬鍧忥紝浣犲簲灏藉姏鎵惧埌鍘熷洜銆傚弬瑙A.4.2鑺傦紝鈥滃鏋淢ySQL渚濈劧宕╂簝锛屽簲浣滀簺浠涔堚

鍏充簬MyISAM琛ㄦ庢牱浼氳鐮村潖鐨勮В閲婏紝鍙傝15.1.4鑺傦紝鈥淢yISAM琛ㄦ柟闈㈢殑闂鈥

鍦ㄦ墽琛屽穿婧冩仮澶嶆椂锛岀悊瑙e湪涓涓暟鎹簱涓殑姣忎竴涓MyISAMtbl_name瀵瑰簲鐨勫湪鏁版嵁搴撶洰褰曚腑鐨3涓枃浠舵槸寰堥噸瑕佺殑锛

鏂囦欢

鐩殑

tbl_name.frm

瀹氫箟(鏍煎紡)鏂囦欢

tbl_name.MYD

鏁版嵁鏂囦欢

tbl_name.MYI

绱㈠紩鏂囦欢

3绫绘枃浠剁殑姣忎竴绫婚兘鍙兘閬彈涓嶅悓褰㈠紡鐨勬崯鍧忥紝浣嗘槸闂鏈甯稿彂鐢熷湪鏁版嵁鏂囦欢鍜岀储寮曟枃浠躲

myisamchk閫氳繃涓琛屼竴琛屽湴鍒涘缓涓涓.MYD鏁版嵁鏂囦欢鐨勫壇鏈潵宸ヤ綔锛屽畠閫氳繃鍒犻櫎鏃х殑.MYD 鏂囦欢骞朵笖閲嶅懡鍚嶆柊鏂囦欢鍒板師鏉ョ殑鏂囦欢鍚嶇粨鏉熶慨澶嶉樁娈点傚鏋滀綘浣跨敤--quickmyisamchk涓嶅垱寤轰竴涓复鏃.MYD鏂囦欢锛屽彧鏄亣瀹.MYD鏂囦欢鏄纭殑骞朵笖浠呭垱寤轰竴涓柊鐨勭储寮曟枃浠讹紝涓嶆帴瑙.MYD鏂囦欢锛岃繖鏄畨鍏ㄧ殑锛屽洜涓myisamchk鑷姩妫娴.MYD鏂囦欢鏄惁鎹熷潖骞朵笖鍦ㄨ繖绉嶆儏鍐典笅锛屾斁寮冧慨澶嶃備綘涔熷彲浠ョ粰myisamchk涓や釜--quick閫夐」銆傚湪杩欑鎯呭喌涓嬶紝myisamchk涓嶄細鍦ㄤ竴浜涢敊璇笂(璞¢噸澶嶉敭)鏀惧純锛岀浉鍙嶈瘯鍥鹃氳繃淇敼.MYD鏂囦欢瑙e喅瀹冧滑銆傞氬父锛屽彧鏈夊湪澶皯鐨勭┖闂茬鐩樼┖闂翠笂瀹炴柦姝e父淇锛屼娇鐢ㄤ袱涓--quick閫夐」鏃舵墠鏈夌敤銆傚湪杩欑鎯呭喌涓嬶紝浣犺嚦灏戝簲璇ュ湪杩愯myisamchk鍓嶅仛杩涜澶囦唤銆

5.9.5.7. 濡備綍妫鏌yISAM琛ㄧ殑閿欒

瑕佹兂妫鏌MyISAM琛紝搴斾娇鐢ㄤ笅闈㈢殑鍛戒护锛

         myisamchk tbl_name

杩欐牱鑳芥壘鍑99.99%鐨勯敊璇傚畠涓嶈兘鎵惧嚭鐨勬槸浠呬粎娑夊強鏁版嵁鏂囦欢鐨勬崯鍧(杩欏緢涓嶅父瑙)銆傚鏋滄兂瑕佹鏌ヤ竴寮犺〃锛岄氬父搴旇娌℃湁閫夐」鍦拌繍琛myisamchk鎴栫敤-s--silent閫夐」鐨勪换浣曚竴涓

         myisamchk -m tbl_name

杩欐牱鑳芥壘鍑99.99%鐨勯敊璇傚畠棣栧厛妫鏌ユ墍鏈夌储寮曟潯鐩殑閿欒骞堕氳鎵鏈夎銆傚畠杩樿绠楄鍐呮墍鏈夐敭鍊肩殑鏍¢獙鍜岋紝骞剁‘璁ゆ牎楠屽拰涓庣储寮曟爲鍐呴敭鐨勬牎楠屽拰鐩稿尮閰嶃

         myisamchk -e tbl_name

鍙互瀹屽叏褰诲簳鍦版鏌ユ暟鎹(-e鎰忔濇槸鈥滄墿灞曟鏌モ)銆傚畠瀵规瘡涓琛屽仛姣忎釜閿殑璇绘鏌ヤ互璇佸疄瀹冧滑纭疄鎸囧悜姝g‘鐨勮銆傝繖鍦ㄤ竴涓湁寰堝閿殑澶ц〃涓婂彲鑳借姳寰堥暱鏃堕棿銆myisamchk閫氬父灏嗗湪瀹冨彂鐜扮涓涓敊璇互鍚庡仠姝€傚鏋滀綘鎯宠鑾峰緱鏇村鐨勪俊鎭紝鍙互澧炲姞--verbose(-v)閫夐」銆傝繖浣垮緱myisamchk缁х画涓鐩村埌鏈澶20涓敊璇

         myisamchk -e -i tbl_name

璞″墠闈㈢殑鍛戒护涓鏍凤紝浣嗘槸-i閫夐」鍛婅瘔myisamchk杩樻墦鍗板嚭涓浜涚粺璁′俊鎭

鍦ㄤ竴鑸娇鐢ㄤ腑锛屼竴涓畝鍗曠殑myisamchk锛堟病鏈夐櫎琛ㄥ悕浠ュ鐨勫弬鏁帮級灏辫冻澶熸鏌ヨ〃浜嗐

5.9.5.8. 濡備綍淇琛

鏈妭鎻忚堪濡備綍瀵MyISAM琛ㄤ娇鐢myisamchk(鎵╁睍鍚.MYI.MYD)

浣犺繕鍙互(骞朵笖搴旇锛屽鏋滃彲鑳)浣跨敤CHECK TABLEREPAIR TABLE璇彞鏉ユ鏌ュ拰淇MyISAM琛ㄣ傚弬瑙13.5.2.3鑺傦紝鈥淐HECK TABLE璇硶鈥13.5.2.6鑺傦紝鈥淩EPAIR TABLE璇硶鈥

涓寮犳崯鍧忕殑琛ㄧ殑鐥囩姸閫氬父鏄煡璇㈡剰澶栦腑鏂苟涓旇兘鐪嬪埌涓嬭堪閿欒锛

  • tbl_name.frm琚攣瀹氫笉鑳芥洿鏀广
  • 涓嶈兘鎵惧埌鏂囦欢tbl_name.MYIErrcodennn锛夈
  • 鏂囦欢鎰忓缁撴潫銆
  • 璁板綍鏂囦欢琚瘉鍧忋
  • 浠庤〃澶勭悊鍣ㄥ緱鍒伴敊璇nnn

瑕佹兂寰楀埌閿欒鐩稿叧鐨勮缁嗕俊鎭紝浣犲彲浠ヨ繍琛perror nnn锛屽叾涓nnn涓洪敊璇紪鍙枫備笅闈㈢殑绀轰緥鏄剧ず浜嗗浣曚娇鐢perror鏉ユ壘鍒版渶甯哥敤閿欒缂栧彿锛堢敤琛ㄧ殑鏂瑰紡鎸囧嚭闂锛夌殑鍚箟锛

shell> perror 126 127 132 134 135 136 141 144 145
126 = Index file is crashed / Wrong file format
127 = Record-file is crashed
132 = Old database file
134 = Record was already deleted (or record file crashed)
135 = No more room in record file
136 = No more room in index file
141 = Duplicate unique key or constraint on write or update
144 = Table is crashed and last repair failed

145 = Table was marked as crashed and should be repaired

璇锋敞鎰忛敊璇135(璁板綍鏂囦欢涓病鏈夋洿澶氱殑绌洪棿)鍜岄敊璇136(绱㈠紩鏂囦欢涓病鏈夋洿澶氱殑绌洪棿)涓嶆槸鍙互閫氳繃绠鍗曚慨澶嶅彲浠ヤ慨澶嶇殑閿欒銆傚湪杩欑鎯呭喌涓嬶紝蹇呴』浣跨敤ALTER TABLE鏉ュ鍔MAX_ROWSAVG_ROW_LENGTH琛ㄩ夐」鍊硷細

ALTER TABLE tbl_name MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;

濡傛灉浣犱笉鐭ラ亾褰撳墠鐨勮〃鐨勯夐」鍊硷紝浣跨敤SHOW CREATE TABLEDESCRIBE鏉ユ煡璇

瀵逛簬鍏跺畠鐨勯敊璇紝浣犲繀椤讳慨澶嶈〃銆myisamchk閫氬父鍙互妫娴嬪拰淇澶у鏁伴棶棰樸

淇杩囩▼鍖呮嫭鍥涗釜闃舵锛屾澶勫皢杩涜鎻忚堪銆傚紑濮嬩慨澶嶅墠锛屽簲杩涘叆鏁版嵁搴撶洰褰曞苟妫鏌ヨ〃鏂囦欢鐨勮鍙傚湪Unix涓紝纭繚瀹冧滑瀵逛簬杩愯mysqld鐢ㄦ埛鍙(浣犱篃搴斿彲璇伙紝鍥犱负浣犻渶瑕佽闂鏌ョ殑鏂囦欢)銆傚鏋滀綘闇瑕佷慨鏀规枃浠讹紝浣犺繕蹇呴』鎷ユ湁鍐欒闂潈闄愩

myisamchk淇琛ㄧ殑閫夐」鐨勬弿杩板弬瑙5.9.5鑺傦紝鈥渕yisamchk锛歁yISAM琛ㄧ淮鎶ゅ疄鐢ㄥ伐鍏封鐨勫墠鍑犺妭銆

涓嬮潰鍑犺妭鍒楀嚭浜嗕笂杩板懡浠ゅけ璐ユ垨浣犳兂瑕佷娇鐢myisamchk鎻愪緵鐨勬墿灞曠壒鎬х瓑鎯呭喌鐨勪緥瀛愩

濡傛灉浣犺閫氳繃鍛戒护琛屾潵淇琛紝蹇呴』棣栧厛鍋滄mysqld鏈嶅姟鍣銆傝娉ㄦ剰褰撲綘鍦ㄨ繙绋嬫湇鍔″櫒涓婅繍琛mysqladmin shutdown鏃讹紝mysqladmin杩斿洖鍚庯紝mysqld鏈嶅姟鍣ㄥ皢浠嶇劧杩愯涓浼氬効锛岀洿鍒板仠姝㈡墍鏈夋煡璇㈠苟灏嗘墍鏈夐敭娓呯┖鍒扮‖鐩樹笂銆

闃舵1锛氭鏌ヤ綘鐨勮〃

濡傛灉浣犳湁寰堝鏃堕棿锛岃繍琛myisamchk *.MYImyisamchk -e *.MYI銆備娇鐢-s锛堟矇榛橈級閫夐」绂佹涓嶅繀瑕佺殑淇℃伅銆

濡傛灉mysqld鏈嶅姟鍣ㄥ浜庡畷鏈虹姸鎬锛屽簲浣跨敤--update-state閫夐」鏉ュ憡璇myisamchk灏嗚〃鏍囪涓'妫鏌ヨ繃鐨'

浣犲繀椤诲彧淇閭d簺myisamchk鎶ュ憡鏈夐敊璇殑琛ㄣ傚杩欐牱鐨勮〃锛岀户缁埌闃舵2

濡傛灉鍦ㄦ鏌ユ椂锛屼綘寰楀埌濂囨殑閿欒(渚嬪out of memory閿欒)锛屾垨濡傛灉myisamchk宕╂簝锛屽埌闃舵3

闃舵2锛氱畝鍗曞畨鍏ㄧ殑淇

娉ㄩ噴锛氬鏋滄兂鏇村揩鍦拌繘琛屼慨澶嶏紝褰撹繍琛myisamchk鏃讹紝浣犲簲灏sort_buffer_sizeKey_buffer_size鍙橀噺鐨勫艰缃负鍙敤鍐呭瓨鐨勫ぇ绾25%

棣栧厛锛岃瘯璇myisamchk -r -q tbl_name(-r -q鎰忓懗鐫鈥滃揩閫熸仮澶嶆ā寮忊)銆傝繖灏嗚瘯鍥句笉鎺ヨЕ鏁版嵁鏂囦欢鏉ヤ慨澶嶇储寮曟枃浠躲傚鏋滄暟鎹枃浠跺寘鍚畠搴旀湁鐨勪竴鍒囧唴瀹瑰拰鎸囧悜鏁版嵁鏂囦欢鍐呮纭湴鐐圭殑鍒犻櫎杩炴帴锛岃繖搴旇绠$敤骞朵笖琛ㄥ彲琚慨澶嶃傚紑濮嬩慨澶嶄笅涓寮犺〃銆傚惁鍒欙紝鎵ц涓嬪垪杩囩▼锛

  1. 鍦ㄧ户缁墠瀵规暟鎹枃浠惰繘琛屽浠姐
  2. 浣跨敤myisamchk -r tbl_name(-r鎰忓懗鐫鈥滄仮澶嶆ā寮忊)銆傝繖灏嗕粠鏁版嵁鏂囦欢涓垹闄や笉姝g‘鐨勮褰曞拰宸茶鍒犻櫎鐨勮褰曞苟閲嶅缓绱㈠紩鏂囦欢銆
  3. 濡傛灉鍓嶉潰鐨勬楠ゅけ璐ワ紝浣跨敤myisamchk --safe-recover tbl_name銆傚畨鍏ㄦ仮澶嶆ā寮忎娇鐢ㄤ竴涓佺殑鎭㈠鏂规硶锛屽鐞嗗父瑙勬仮澶嶆ā寮忎笉琛岀殑灏戞暟鎯呭喌(浣嗘槸鏇存參)

濡傛灉鍦ㄤ慨澶嶆椂锛屼綘寰楀埌濂囨殑閿欒(渚嬪out of memory閿欒)锛屾垨濡傛灉myisamchk宕╂簝锛屽埌闃舵3

闃舵3锛氬洶闅剧殑淇

鍙湁鍦ㄧ储寮曟枃浠剁殑绗竴涓16K鍧楄鐮村潖锛屾垨鍖呭惈涓嶆纭殑淇℃伅锛屾垨濡傛灉绱㈠紩鏂囦欢涓㈠け锛屼綘鎵嶅簲璇ュ埌杩欎釜闃舵銆傚湪杩欑鎯呭喌涓嬶紝闇瑕佸垱寤轰竴涓柊鐨勭储寮曟枃浠躲傛寜濡備笅姝ラ鎿嶅仛锛

  1. 鎶婃暟鎹枃浠剁Щ鍒板畨鍏ㄧ殑鍦版柟銆
  2. 浣跨敤琛ㄦ弿杩版枃浠跺垱寤烘柊鐨()鏁版嵁鏂囦欢鍜岀储寮曟枃浠讹細
  3. shell> mysql db_name
  4. mysql> SET AUTOCOMMIT=1;
  5. mysql> TRUNCATE TABLE tbl_name;
  6. mysql> quit

濡傛灉浣犵殑MySQL鐗堟湰娌℃湁TRUNCATE TABLE锛屽垯浣跨敤DELETE FROM tbl_name

  1. 灏嗚佺殑鏁版嵁鏂囦欢鎷疯礉鍒版柊鍒涘缓鐨勬暟鎹枃浠朵箣涓傦紙涓嶈鍙槸灏嗚佹枃浠剁Щ鍥炴柊鏂囦欢涔嬩腑锛涗綘瑕佷繚鐣欎竴涓壇鏈互闃叉煇浜涗笢瑗垮嚭閿欍傦級

鍥炲埌闃舵2銆傜幇鍦myisamchk -r -q搴旇宸ヤ綔浜嗐傦紙杩欎笉搴旇鏄竴涓棤闄愬惊鐜級銆

浣犺繕鍙互浣跨敤REPAIR TABLE tbl_name USE_FRM锛屽皢鑷姩鎵ц鏁翠釜绋嬪簭銆

闃舵4锛氶潪甯稿洶闅剧殑淇

鍙湁.frm鎻忚堪鏂囦欢涔熺牬鍧忎簡锛屼綘鎵嶅簲璇ュ埌杈捐繖涓樁娈点傝繖搴旇浠庢湭鍙戠敓杩囷紝鍥犱负鍦ㄨ〃琚垱寤轰互鍚庯紝鎻忚堪鏂囦欢灏变笉鍐嶆敼鍙樹簡銆

  1. 浠庝竴涓浠芥仮澶嶆弿杩版枃浠剁劧鍚庡洖鍒伴樁娈3銆備綘涔熷彲浠ユ仮澶嶇储寮曟枃浠剁劧鍚庡洖鍒伴樁娈2銆傚鍚庤咃紝浣犲簲璇ョ敤myisamchk -r鍚姩銆
  2. 濡傛灉浣犳病鏈夎繘琛屽浠戒絾鏄‘鍒囧湴鐭ラ亾琛ㄦ槸鎬庢牱鍒涘缓鐨勶紝鍦ㄥ彟涓涓暟鎹簱涓垱寤鸿〃鐨勪竴涓嫹璐濄傚垹闄ゆ柊鐨勬暟鎹枃浠讹紝鐒跺悗浠庡叾浠栨暟鎹簱灏嗘弿杩版枃浠跺拰绱㈠紩鏂囦欢绉诲埌鐮村潖鐨勬暟鎹簱涓傝繖鏍锋彁渚涗簡鏂扮殑鎻忚堪鍜岀储寮曟枃浠讹紝浣嗘槸璁.MYD鏁版嵁鏂囦欢鐙嚜鐣欎笅鏉ヤ簡銆傚洖鍒伴樁娈2骞朵笖灏濊瘯閲嶅缓绱㈠紩鏂囦欢銆

5.9.5.9. 琛ㄤ紭鍖

涓轰簡缁勫悎纰庣墖璁板綍骞朵笖娑堥櫎鐢变簬鍒犻櫎鎴栨洿鏂拌褰曡屾氮璐圭殑绌洪棿锛屼互鎭㈠妯″紡杩愯myisamchk

shell> myisamchk -r tbl_name

浣犲彲浠ョ敤SQLOPTIMIZE TABLE璇彞浣跨敤鐨勭浉鍚屾柟寮忔潵浼樺寲琛紝OPTIMIZE TABLE鍙互淇琛ㄥ苟瀵归敭鍊艰繘琛屽垎鏋愶紝骞朵笖鍙互瀵圭储寮曟爲杩涜鎺掑簭浠ヤ究鏇村揩鍦版煡鎵鹃敭鍊笺傚疄鐢ㄧ▼搴忓拰鏈嶅姟鍣ㄤ箣闂翠笉鍙兘浜や簰鎿嶄綔锛屽洜涓哄綋浣犱娇鐢OPTIMIZE TABLE鏃讹紝鏈嶅姟鍣ㄥ仛鎵鏈夌殑宸ヤ綔銆傚弬瑙13.5.2.5鑺傦紝鈥淥PTIMIZE TABLE璇硶鈥

myisamchk杩樻湁寰堝鍏跺畠鍙敤鏉ユ彁楂樿〃鐨勬ц兘鐨勯夐」锛

         -S, --sort-index

         -R index_num, --sort-records=index_num

         -a, --analyze

鍏充簬杩欎簺閫夐」鐨勫畬鏁寸殑鎻忚堪锛屽弬瑙5.9.5鑺傦紝鈥渕yisamchk锛歁yISAM琛ㄧ淮鎶ゅ疄鐢ㄥ伐鍏封

5.9.6. 寤虹珛琛ㄧ淮鎶よ鍒

瀹氭湡瀵硅〃杩涜妫鏌ヨ岄潪绛夊埌闂鍑虹幇鍚庡啀妫鏌ユ暟鎹簱琛ㄦ槸涓涓ソ涓绘剰銆傛鏌ュ拰淇MyISAM琛ㄧ殑涓涓柟寮忔槸浣跨敤CHECK TABLEREPAIR TABLE璇彞銆傚弬瑙13.5.2.3鑺傦紝鈥淐HECK TABLE璇硶鈥13.5.2.6鑺傦紝鈥淩EPAIR TABLE璇硶鈥

妫鏌ヨ〃鐨勫彟涓涓柟娉曟槸浣跨敤myisamchk銆備负缁存姢鐩殑锛屽彲浠ヤ娇鐢myisamchk -s妫鏌ヨ〃銆-s閫夐」锛堢畝绉--silent锛変娇myisamchk浠ユ矇榛樻ā寮忚繍琛岋紝鍙湁褰撻敊璇嚭鐜版椂鎵嶆墦鍗版秷鎭

鍦ㄦ湇鍔″櫒鍚姩鏃舵鏌ヨ〃鏄竴涓ソ涓绘剰銆備緥濡傦紝鏃犺浣曟椂鏈哄櫒鍦ㄦ洿鏂板綋涓噸鏂板惎鍔ㄤ簡锛屼綘閫氬父闇瑕佹鏌ユ墍鏈夊彲鑳藉彈褰卞搷鐨勮〃銆傦紙鍗斥滈鏈熺殑鐮村潖浜嗙殑琛ㄢ濓級銆傝鎯宠嚜鍔ㄦ鏌MyISAM琛紝鐢--myisam-recover閫夐」鍚姩鏈嶅姟鍣ㄣ

涓涓洿濂界殑娴嬭瘯灏嗘槸妫鏌ユ渶鍚庝慨鏀规椂闂存瘮.pid鏂囦欢鏂扮殑琛ㄣ

浣犺繕搴旇鍦ㄦ甯哥郴缁熸搷浣滄湡闂村畾鏈熸鏌ヨ〃銆傚湪MySQL AB锛屾垜浠繍琛屼竴涓cron浠诲姟锛屾瘡鍛ㄤ竴娆℃鏌ユ墍鏈夐噸瑕佺殑琛紝浣跨敤crontab鏂囦欢涓繖鏍风殑琛岋細

35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI

鍙互鎵撳嵃鎹熷潖鐨勮〃鐨勪俊鎭紝浠ヤ究鎴戜滑鍦ㄩ渶瑕佹椂鑳藉妫楠屽苟涓斾慨澶嶅畠浠

澶氬勾浜嗘垜浠繕娌℃湁鍙戠幇(鐨勭‘鏄湡鐨)閮芥病鏈変换浣曟剰澶栨崯鍧忕殑琛ㄦ椂(鐢变簬闄ょ‖浠舵晠闅滃鐨勫叾瀹冨師鍥犻犳垚鎹熷潖鐨勮〃)锛屾瘡鍛ㄤ竴娆″鎴戜滑鏄冻澶熶簡銆

鎴戜滑寤鸿鐜板湪寮濮嬶紝浣犲鎵鏈夋渶鍚24灏忔椂鍐呰鏇存柊浜嗙殑琛ㄦ瘡鏅氶兘鎵цmyisamchk -s锛岀洿鍒颁綘鍙樺緱璞℃垜浠偅鏍蜂俊浠MySQL

涓鑸儏鍐碉紝MySQL琛ㄥ緢灏戦渶瑕佺淮鎶ゃ傚鏋滀綘鐢ㄥ姩鎬佸ぇ灏忕殑琛屾洿鏀MyISAM(VARCHARBLOBTEXT鍒楃殑琛)鎴栨湁鍒犻櫎浜嗚澶氳鐨勮〃锛屼綘鍙兘鎯宠涓嶆椂鍦帮紙姣忔湀涓娆★級鏁寸悊/缁勫悎琛ㄧ殑绌洪棿銆

鍙互瀵规湁闂鐨勮〃鎵цOPTIMIZE TABLE鏉ヤ紭鍖栥傛垨鑰呮槸锛屽鏋滃彲浠ュ仠涓浼mysqld鏈嶅姟鍣锛岃繘鍏ユ暟鎹洰褰曪紝褰撴湇鍔″櫒鍋滄鏃朵娇鐢ㄨ鍛戒护锛

shell> myisamchk -r -s --sort-index -O sort_buffer_size=16M */*.MYI

5.9.7. 鑾峰彇鍏充簬琛ㄧ殑淇℃伅

涓轰簡鑾峰緱鍏充簬涓涓〃鐨勬弿杩版垨缁熻锛屼娇鐢ㄤ笅闈㈢殑鍛戒护锛

         myisamchk -d tbl_name

浠モ滄弿杩版ā寮忊濊繍琛myisamchk锛岀敓鎴愯〃鐨勬弿杩般傚鏋滅敤--skip-external-locking閫夐」鍚姩MySQL鏈嶅姟鍣紝myisamchk鍙互鎶ュ憡杩愯鐨勮〃琚洿鏂扮殑閿欒銆傜劧鑰岋紝鏃㈢劧鍦ㄦ弿杩版ā寮忎腑myisamchk涓嶆洿鏀硅〃锛屾病鏈変换浣曠牬鍧忔暟鎹殑椋庨櫓銆

         myisamchk -d -v tbl_name

涓轰簡鐢熸垚鏇村鍏充簬myisamchk姝e湪鍋氫粈涔堢殑淇℃伅锛屽姞涓-v鍛婅瘔瀹冧互鍐楅暱妯″紡杩愯銆

         myisamchk -eis tbl_name

浠呮樉绀鸿〃鐨勬渶閲嶈鐨勪俊鎭傚洜涓哄繀椤昏鍙栨暣涓〃锛岃鎿嶄綔寰堟參銆

         myisamchk -eiv tbl_name

杩欑被浼 -eis锛屽彧鏄憡璇変綘姝e湪鍋氫粈涔堛

涓嬮潰涓鸿繖浜涘懡浠ょ殑杈撳嚭绀轰緥銆傚畠浠熀浜庡惈杩欎簺鏁版嵁鍜岀储寮曟枃浠跺ぇ灏忕殑琛細

-rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
-rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM

myisamchk -d杈撳嚭绀轰緥锛

MyISAM file:     company.MYI
Record format:   Fixed length
Data records:    1403698  Deleted blocks:         0
Recordlength:    226
 
table description:
Key Start Len Index   Type
1   2     8   unique  double
2   15    10  multip. text packed stripped
3   219   8   multip. double
4   63    10  multip. text packed stripped
5   167   2   multip. unsigned short
6   177   4   multip. unsigned long
7   155   4   multip. text
8   138   4   multip. unsigned long
9   177   4   multip. unsigned long
    193   1           text

myisamchk -d -v 杈撳嚭绀轰緥锛

MyISAM file:         company
Record format:       Fixed length
File-version:        1
Creation time:       1999-10-30 12:12:51
Recover time:        1999-10-31 19:13:01
Status:              checked
Data records:            1403698  Deleted blocks:              0
Datafile parts:          1403698  Deleted data:                0
Datafile pointer (bytes):      3  Keyfile pointer (bytes):     3
Max datafile length:  3791650815  Max keyfile length: 4294967294
Recordlength:                226
 
table description:
Key Start Len Index   Type                  Rec/key     Root Blocksize
1   2     8   unique  double                      1 15845376      1024
2   15    10  multip. text packed stripped        2 25062400      1024
3   219   8   multip. double                     73 40907776      1024
4   63    10  multip. text packed stripped        5 48097280      1024
5   167   2   multip. unsigned short           4840 55200768      1024
6   177   4   multip. unsigned long            1346 65145856      1024
7   155   4   multip. text                     4995 75090944      1024
8   138   4   multip. unsigned long              87 85036032      1024
9   177   4   multip. unsigned long             178 96481280      1024
    193   1           text

myisamchk -eis 杈撳嚭绀轰緥锛

Checking MyISAM file: company
Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
Total:    Keyblocks used:  98%  Packed:   17%
 
Records:          1403698    M.recordlength:     226
Packed:             0%
Recordspace used:     100%   Empty space:          0%
Blocks/Record:   1.00
Record blocks:    1403698    Delete blocks:        0
Recorddata:     317235748    Deleted data:         0
Lost space:             0    Linkdata:             0
 
User time 1626.51, System time 232.36
Maximum resident set size 0, Integral resident set size 0
Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 639, Involuntary context switches 28966

myisamchk -eiv 杈撳嚭绀轰緥锛

Checking MyISAM file: company
Data records: 1403698   Deleted blocks:       0
- check file-size
- check delete-chain
block_size 1024:
index  1:
index  2:
index  3:
index  4:
index  5:
index  6:
index  7:
index  8:
index  9:
No recordlinks
- check index reference
- check data record references index: 1
Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
- check data record references index: 2
Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
- check data record references index: 3
Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
- check data record references index: 4
Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
- check data record references index: 5
Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
- check data record references index: 6
Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
- check data record references index: 7
Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
- check data record references index: 8
Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
- check data record references index: 9
Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
Total:    Keyblocks used:   9%  Packed:   17%
 
- check records and index references
[LOTS OF ROW NUMBERS DELETED]
 
Records:         1403698   M.recordlength:   226   Packed:           0%
Recordspace used:    100%  Empty space:        0%  Blocks/Record: 1.00
Record blocks:   1403698   Delete blocks:      0
Recorddata:    317235748   Deleted data:       0
Lost space:            0   Linkdata:           0
 
User time 1639.63, System time 251.61
Maximum resident set size 0, Integral resident set size 0
Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
Blocks in 4 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 10604, Involuntary context switches 122798

涓嬮潰瑙i噴myisamchk浜х敓鐨勪俊鎭殑绫诲瀷銆傗keyfile鈥濇槸绱㈠紩鏂囦欢銆傗滆褰曗濆拰鈥滆鈥濇槸鍚屼箟璇嶃

         MyISAM file

ISAM(绱㈠紩)鏂囦欢鍚嶃

         File-version

ISAM鏍煎紡鐨勭増鏈傚綋鍓嶆绘槸2

         Creation time

鏁版嵁鏂囦欢鍒涘缓鐨勬椂闂淬

         Recover time

绱㈠紩/鏁版嵁鏂囦欢涓婃琚噸寤虹殑鏃堕棿銆

         Data records

鍦ㄨ〃涓湁澶氬皯璁板綍銆

         Deleted blocks

鏈夊灏戝垹闄ょ殑鍧椾粛鐒朵繚鐣欑潃绌洪棿銆備綘鍙互浼樺寲琛ㄤ互浣胯繖涓┖闂村噺鍒版渶灏忋傚弬瑙绗7绔狅細浼樺寲

         Datafile parts

瀵瑰姩鎬佽褰曟牸寮忥紝杩欐寚鍑烘湁澶氬皯鏁版嵁鍧椼傚浜庝竴涓病鏈夌鐗囩殑浼樺寲杩囩殑琛紝杩欎笌Data records鐩稿悓銆

         Deleted data

涓嶈兘鍥炴敹鐨勫垹闄ゆ暟鎹湁澶氬皯瀛楄妭銆備綘鍙互浼樺寲琛ㄤ互浣胯繖涓┖闂村噺鍒版渶灏忋傚弬瑙绗7绔狅細浼樺寲

         Datafile pointer

鏁版嵁鏂囦欢鎸囬拡鐨勫ぇ灏忥紝浠ュ瓧鑺傝銆傚畠閫氬父鏄2345涓瓧鑺傘傚ぇ澶氭暟琛ㄧ敤2涓瓧鑺傜鐞嗭紝浣嗘槸鐩墠杩欒繕涓嶈兘浠MySQL鎺у埗銆傚鍥哄畾琛紝杩欐槸涓涓褰曞湴鍧銆傚鍔ㄦ佽〃锛岃繖鏄竴涓瓧鑺傚湴鍧銆

         Keyfile pointer

绱㈠紩鏂囦欢鎸囬拡鐨勫ぇ灏忥紝浠ュ瓧鑺傝銆傚畠閫氬父鏄123涓瓧鑺傘傚ぇ澶氭暟琛ㄧ敤 2 涓瓧鑺傜鐞嗭紝浣嗘槸瀹冭嚜鍔ㄧ敱MySQL璁$畻銆傚畠鎬绘槸涓涓潡鍦板潃銆

         Max datafile length

琛ㄧ殑鏁版嵁鏂囦欢(.MYD鏂囦欢)鑳藉鏈夊闀匡紝浠ュ瓧鑺傝銆

         Max keyfile length

琛ㄧ殑閿兼枃浠(.MYI鏂囦欢)鑳藉鏈夊闀匡紝浠ュ瓧鑺傝銆

           Recordlength

姣忎釜璁板綍鍗犲灏戠┖闂达紝浠ュ瓧鑺傝銆

         Record format

鐢ㄤ簬瀛樺偍琛ㄨ鐨勬牸寮忋備笂闈㈢殑渚嬪瓙浣跨敤Fixed length鍏朵粬鍙兘鐨勫兼槸CompressedPacked

         table description

鍦ㄨ〃涓墍鏈夐敭鍊肩殑鍒楄〃銆傚姣忎釜閿紝缁欏嚭涓浜涘簳灞傜殑淇℃伅锛

o        Key

璇ラ敭鐨勭紪鍙枫

o        Start

璇ョ储寮曢儴鍒嗕粠璁板綍鐨勫摢閲屽紑濮嬨

o        Len

璇ョ储寮曢儴鍒嗘槸澶氶暱銆傚浜庣揣鍑戠殑鏁板瓧锛岃繖搴旇鎬绘槸鍒楃殑鍏ㄩ暱銆傚瀛楃涓诧紝瀹冨彲浠ユ瘮绱㈠紩鐨勫垪鐨勫叏闀跨煭浜涳紝鍥犱负浣犲彲鑳戒細绱㈠紩鍒板瓧绗︿覆鍒楃殑鍓嶇紑銆

o        Index

uniquemultipmultiple)銆傝〃鏄庝竴涓兼槸鍚﹁兘鍦ㄨ绱㈠紩涓瓨鍦ㄥ娆°

o        Type

璇ョ储寮曢儴鍒嗘湁浠涔堟暟鎹被鍨嬨傝繖鏄竴涓packedstrippedempty閫夐」鐨ISAM鏁版嵁绫诲瀷銆

o        Root

鏍圭储寮曞潡鐨勫湴鍧銆

o        Blocksize

姣忎釜绱㈠紩鍧楃殑澶у皬銆傞粯璁ゆ槸1024锛屼絾鏄粠婧愮爜鏋勫缓MySQL鏃讹紝璇ュ煎彲浠ュ湪缂栬瘧鏃舵敼鍙樸

o        Rec/key

杩欐槸鐢变紭鍖栧櫒浣跨敤鐨勭粺璁″笺傚畠鍛婅瘔瀵硅閿殑姣忎釜鍊兼湁澶氬皯鏉¤褰曘傚敮涓閿绘槸鏈変竴涓1鍊笺傚湪涓涓〃琚杞藉悗(鎴栧彉鏇村緢澶)锛屽彲浠ョ敤myisamchk -a鏇存柊銆傚鏋滄牴鏈病琚洿鏂帮紝缁欏畾涓涓30鐨勯粯璁ゅ笺

鍦ㄤ笂闈緥瀛愮殑琛ㄤ腑锛岀9涓敭鏈変袱涓table description琛屻傝呰鏄庡畠鏄湁2涓儴鍒嗙殑澶氶儴閿

         Keyblocks used

閿潡浣跨敤鐨勭櫨鍒嗘瘮鏄粈涔堛傚綋鍦ㄤ緥瀛愪腑浣跨敤鐨勮〃鍒氬垰鐢myisamchk閲嶆柊缁勭粐鏃讹紝璇ュ奸潪甯搁珮(寰堟帴杩戠悊璁轰笂鐨勬渶澶у)

         Packed

MySQL璇曞浘鐢ㄤ竴涓氱敤鍚庣紑鍘嬬缉閿傝繖鍙兘琚敤浜CHAR/VARCHAR/DECIMAL鍒楃殑閿傚浜庡乏閮ㄥ垎绫讳技鐨勯暱瀛楃涓诧紝鑳芥樉钁楀湴鍑忓皯浣跨敤绌洪棿銆傚湪涓婇潰鐨勭3涓緥瀛愪腑锛岀4涓敭鏄10涓瓧绗﹂暱锛屽彲浠ュ噺灏60%鐨勭┖闂淬

         Max levels

瀵逛簬璇ラ敭鐨B鏍戞湁澶氭繁銆傛湁闀块敭鐨勫ぇ琛ㄦ湁杈冮珮鐨勫笺

         Records

琛ㄤ腑鏈夊灏戣銆

         M.recordlength

骞冲潎璁板綍闀垮害銆傚浜庢湁瀹氶暱璁板綍鐨勮〃锛岃繖鏄噯纭殑璁板綍闀垮害锛屽洜涓烘墍鏈夎褰曠殑闀垮害鐩稿悓銆

         Packed

MySQL浠庡瓧绗︿覆鐨勭粨灏惧幓鎺夌┖鏍笺Packed鍊艰〃鏄庤繖鏍峰仛杈惧埌鐨勮妭绾︾殑鐧惧垎姣斻

         Recordspace used

鏁版嵁鏂囦欢琚娇鐢ㄧ殑鐧惧垎姣斻

         Empty space

鏁版嵁鏂囦欢鏈浣跨敤鐨勭櫨鍒嗘瘮銆

         Blocks/Record

姣忎釜璁板綍鐨勫钩鍧囧潡鏁(鍗筹紝涓涓鐗囪褰曠敱澶氬皯涓繛鎺ョ粍鎴)銆傚鍥哄畾鏍煎紡琛紝杩欐绘槸1銆傝鍊煎簲璇ュ敖鍙兘淇濇寔鎺ヨ繎1.0銆傚鏋滃畠鍙樺緱澶ぇ锛屼綘鍙互閲嶆柊缁勭粐琛ㄣ傚弬瑙绗7绔狅細浼樺寲

         Recordblocks

澶氬皯鍧(閾炬帴)琚娇鐢ㄣ傚鍥哄畾鏍煎紡锛屽畠涓庤褰曠殑涓暟鐩稿悓銆

         Deleteblocks

澶氬皯鍧(閾炬帴)琚垹闄ゃ

         Recorddata

鍦ㄦ暟鎹枃浠朵腑浣跨敤浜嗗灏戝瓧鑺傘

         Deleted data

鍦ㄦ暟鎹枃浠朵腑澶氬皯瀛楄妭琚垹闄(鏈娇鐢)

         Lost space

濡傛灉涓涓褰曡鏇存柊涓烘洿鐭殑闀垮害锛屽氨鎹熷け浜嗕竴浜涚┖闂淬傝繖鏄墍鏈夎繖鏍风殑鎹熷け涔嬪拰锛屼互瀛楄妭璁°

         Linkdata

褰撲娇鐢ㄥ姩鎬佽〃鏍煎紡锛岃褰曠鐗囩敤鎸囬拡杩炴帴(姣忎釜4 7瀛楄妭)Linkdata鎸囪繖鏍风殑鎸囬拡浣跨敤鐨勫唴瀛橀噺涔嬪拰銆

濡傛灉涓寮犺〃宸茬粡鐢myisampack鍘嬬缉浜嗭紝myisamchk -d鎵撳嵃姣忎釜琛ㄥ垪鐨勯檮鍔犱俊鎭傚浜庡畠鐨勪竴涓緥瀛愬強鍏跺惈涔夌殑鎻忚堪锛屽弬瑙8.2鑺傦紝鈥渕yisampack锛氱敓鎴愬帇缂┿佸彧璇籑yISAM琛ㄢ

5.10. MySQL鏈湴鍖栧拰鍥介檯搴旂敤

鏈妭鎻忚堪濡備綍閰嶇疆鏈嶅姟鍣ㄦ潵浣跨敤涓嶅悓鐨勫瓧绗﹂泦銆傝繕璁ㄨ濡備綍璁剧疆鏈嶅姟鍣ㄧ殑鏃跺尯骞跺惎鐢ㄥ悇涓繛鎺ョ殑鏃跺尯鏀寔銆

5.10.1. 鏁版嵁鍜屾帓搴忕敤瀛楃闆

榛樿鎯呭喌涓嬶紝MySQL浣跨敤cp1252(Latin1)瀛楃闆嗘牴鎹Swedish/Finnish瑙勫垯杩涜鎺掑簭銆傝繖浜 榛樿鍊奸傚悎缇庡浗鍜岃タ娆уぇ閮ㄥ垎鍥藉銆

鎵鏈MySQL浜岃繘鍒跺垎鍙戠増鐢--with-extra-charsets=complex缂栬瘧鑰屾垚銆傚彲浠ュ湪鎵鏈夋爣鍑嗙▼搴忎腑娣诲姞浠g爜锛屼娇瀹冧滑鍙互澶勭悊latin1鍜屾墍鏈夊瀛楄妭浜岃繘鍒跺瓧绗﹂泦銆傚叾瀹冨瓧绗﹂泦鏍规嵁闇瑕佷粠瀛楃闆嗗畾涔夋枃浠惰浇鍏ャ

瀛楃闆嗙‘瀹氬湪鍚嶇О涓娇鐢ㄤ粈涔堝瓧绗︺傚畠杩樼‘瀹氬浣曠敤SELECT璇彞鐨ORDER BYGROUP BY瀛愬彞瀵瑰瓧绗︿覆杩涜鎺掑簭銆

杩樺彲浠ュ湪鍚姩鏈嶅姟鍣ㄦ椂鐢--default-character-set閫夐」鏇存敼瀛楃闆嗐傚瓧绗﹂泦鍙互鐢--with-charset=charset--with-extra-charsets=list-of-charsets | complex | all | none閫夐」鏉configure锛屽瓧绗﹂泦閰嶇疆鏂囦欢鍒椾簬SHAREDIR/charsets/Index銆傚弬瑙2.8.2鑺傦紝鈥滃吀鍨嬮厤缃夐」

杩樺彲浠ュ湪浣犲惎鍔ㄦ湇鍔″櫒鏃剁敤--default-collation閫夐」鏇存敼瀛楃闆 鏍″瑙勫垯銆傛牎瀵硅鍒欏繀椤绘槸榛樿瀛楃闆嗙殑鍚堟硶鏍″瑙勫垯銆(浣跨敤SHOW COLLATION璇彞鏉ョ‘瀹氭瘡涓瓧绗﹂泦浣跨敤鍝釜鏍″瑙勫垯锛 鍙傝2.8.2鑺傦紝鈥滃吀鍨嬮厤缃夐」

濡傛灉鍦ㄨ繍琛MySQL鏃舵洿鏀瑰瓧绗﹂泦锛岃繕浼氭洿鏀规帓搴忛『搴忋傜粨鏋滄槸浣犲繀椤诲鎵鏈夎〃杩愯myisamchk -r -q --set-character-set=charset 锛屾垨姝g‘鍦板绱㈠紩杩涜鎺掑簭銆

褰撳鎴风杩炴帴MySQL鏈嶅姟鍣ㄦ椂锛屾湇鍔″櫒鍛婅瘔瀹㈡埛绔湇鍔″櫒鐨勯粯璁ゅ瓧绗﹂泦鏄粈涔堛傚鎴风鍒囨崲鍒拌瀛楃闆嗚繘琛岃繛鎺ャ

褰撹浆涔SQL鏌ヨ鐨勫瓧绗︿覆鏃讹紝浣犲簲浣跨敤mysql_real_escape_string()mysql_real_escape_string()绛変环浜庢棫鐨mysql_escape_string()鍑芥暟锛屼笉鍚岀殑鏄畠浣跨敤MYSQL杩炴帴鍙ユ焺浣滀负绗竴涓弬鏁帮紝浠ヤ究杞箟瀛楃鏃跺彲浠ヤ娇鐢ㄧ浉搴旂殑瀛楃闆嗐

濡傛灉瀹㈡埛绔殑缂栬瘧璺緞涓嶆槸鏈嶅姟鍣ㄧ殑瀹夎鐩綍锛屽苟涓旈厤缃MySQL鏃舵病鏈夊寘鎷MySQL浜岃繘鍒朵腑鐨勬墍鏈夊瓧绗﹂泦锛屽鏋滄湇鍔″櫒杩愯鏃堕渶瑕佷娇鐢ㄥ鎴风璁剧疆鐨勫瓧绗﹂泦涔嬪鐨勫叾瀹冨瓧绗﹂泦锛屼綘蹇呴』鍛婅瘔瀹㈡埛绔粠鍝噷鎵惧埌鏇村鐨勫瓧绗﹂泦銆

鍙互鎸囧畾--character-sets-dir閫夐」鏉ヨ〃绀哄姩鎬MySQL瀛楃闆嗘墍淇濆瓨鐩綍鐨勮矾寰勩備緥濡傦紝鍙互灏嗕笅闈㈢殑琛屾斁鍏ラ夐」鏂囦欢涓細

[client]
character-sets-dir=/usr/local/mysql/share/mysql/charsets

浣犲彲浠ュ己鍒跺鎴风浣跨敤涓撶敤瀛楃闆嗭細

[client]
default-character-set=charset

浣嗘槸涓鑸儏鍐典笉闇瑕併

5.10.1.1. 浣跨敤寰峰浗瀛楃闆

MySQL 5.1,鍒嗗埆鎸囧畾瀛楃闆嗗拰 鏍″瑙勫垯銆傝繖璇存槑濡傛灉浣犳兂浣跨敤German鎺掑簭椤哄簭锛屼綘搴旈夋嫨latin1 瀛楃闆嗗拰latin1_german1_cilatin1_german2_ci鏍″瑙勫垯銆備緥濡傦紝瑕佺敤latin1_german1_ci鏍″瑙勫垯鍚姩鏈嶅姟鍣紝搴斾娇鐢--character-set-server=latin1--collation-server=latin1_german1_ci閫夐」銆

鍏充簬杩欎袱绉嶆牎瀵硅鍒欑殑涓嶅悓涔嬪锛屽弬瑙10.10.2鑺傦紝鈥滆タ娆у瓧绗﹂泦鈥

5.10.2. 璁剧疆閿欒娑堟伅璇█

榛樿鎯呭喌涓嬶紝mysqld鐢ㄨ嫳璇粰鍑洪敊璇秷鎭紝浣嗕篃鍙互鐢ㄤ互涓嬭瑷鏄剧ず锛CzechDanishDutchEstonianFrenchGermanGreekHungarianItalianJapaneseKoreanNorwegianNorwegian-nyPolishPortugueseRomanianRussianSlovakSpanish Swedish

瑕佹兂鍦ㄥ惎鍔mysqld鍚庣敤鍏蜂綋璇█鏄剧ず閿欒娑堟伅锛屼娇鐢--language-L閫夐」銆傞夐」鍊煎彲浠ヤ负璇█鍚嶇О鎴栭敊璇秷鎭枃浠剁殑鍏ㄨ矾寰勩備緥濡傦細

shell> mysqld --language=swedish

鎴栵細

shell> mysqld --language=/usr/local/share/swedish

璇█鍚嶅簲涓哄皬鍐欍

璇█鏂囦欢浣嶄簬(榛樿鎯呭喌涓)MySQL鍩烘湰鐩綍鐨share/LANGUAGE鐩綍涓嬨

瑕佹兂鏇存敼閿欒娑堟伅鏂囦欢锛屽簲缂栬緫errmsg.txt鏂囦欢锛岀劧鍚庢墽琛屼笅闈㈢殑鍛戒护浠ョ敓鎴errmsg.sys鏂囦欢锛

shell> comp_err errmsg.txt errmsg.sys

濡傛灉浣犲崌绾у埌鏂扮増鏈殑MySQL锛岃浣忎娇鐢ㄦ柊鐨errmsg.txt鏂囦欢鏉ラ噸鏂版洿鏀广

5.10.3. 娣诲姞鏂扮殑瀛楃闆

鏈妭璁ㄨ鍦MySQL涓坊鍔犳柊瀛楃闆嗙殑绋嬪簭銆備綘蹇呴』鏈変竴涓MySQL婧愮爜鍒嗗彂鐗堛

瑕侀夋嫨姝g‘鐨勭▼搴忥紝鍏堢‘瀹氬瓧绗﹂泦鏄畝鍗曞瓧绗﹂泦杩樻槸澶嶆潅瀛楃闆嗭細

         濡傛灉瀛楃闆嗕笉闇瑕佷娇鐢ㄧ壒娈婂瓧绗︿覆鏍″瑙勫垯绋嬪簭杩涜鎺掑簭锛屽苟涓斾笉闇瑕佸瀛楄妭瀛楃鏀寔锛屽垯涓虹畝鍗曞瓧绗﹂泦銆

         濡傛灉闇瑕佷笂杩版煇涓壒鎬э紝鍒欎负澶嶆潅瀛楃闆嗐

渚嬪锛latin1danish涓虹畝鍗曞瓧绗﹂泦锛岃big5czech涓哄鏉傚瓧绗﹂泦銆

鍦ㄤ笅闈㈢殑绋嬪簭涓紝瀛楃闆嗗悕鐢MYSET琛ㄧず銆

瀵逛簬绠鍗曞瓧绗﹂泦锛屽簲锛

1.    sql/share/charsets/Index鏂囦欢鏈鍚庢坊鍔MYSET銆傚苟鎸囧畾鍞竴鐨勭紪鍙枫

2.    鍒涘缓鏂囦欢sql/share/charsets/MYSET.conf(浣犲彲浠ヤ娇鐢sql/share/charsets/latin1.conf鐨勫浠芥枃浠朵綔涓鸿鏂囦欢鐨勫熀纭锛

鏂囦欢鐨勮娉曞緢绠鍗曪細

         娉ㄩ噴浠庘#鈥欏瓧绗﹀紑濮嬶紝涓鐩村埌璇ヨ鏈熬銆

         鍚勫瓧涔嬮棿鐢ㄤ换鎰忔暟閲忕殑绌烘牸闂撮殧寮銆

         瀹氫箟瀛楃闆嗘椂锛屾瘡涓瓧蹇呴』涓哄崄鍏繘鍒舵牸寮忕殑鏁板瓧銆

         ctype鏁扮粍鍗犳嵁鍓257涓瓧銆to_lower[]to_upper[]sort_order[]鏁扮粍渚濇鍗犳嵁256涓瓧銆

鍙傝5.10.4鑺傦紝鈥滃瓧绗﹀畾涔夋暟缁勨

3.    灏嗗瓧绗﹂泦鍚嶆坊鍔犲埌configurE.inCHARSETS_AVAILABLECOMPILED_CHARSETS鍒椼

4.    閲嶆柊閰嶇疆銆佺紪璇戝苟娴嬭瘯銆

瀵逛簬澶嶆潅瀛楃闆嗭紝搴旓細

1.    MySQL婧愮爜鍒嗗彂鐗堜腑鍒涘缓鏂囦欢strings/ctype-MYSET.c

2.    sql/share/charsets/Index鏂囦欢鏈鍚庢坊鍔MYSET銆傚苟鎸囧畾鍞竴鐨勭紪鍙枫

3.    鐪嬬湅宸叉湁鐨ctype-*.c鏂囦欢(渚嬪strings/ctype-big5.c)锛岀湅鐪嬮渶瑕佸畾涔変粈涔堛傝娉ㄦ剰鏂囦欢涓殑鏁扮粍鍚嶅繀椤讳负ctype_MYSETto_lower_MYSET绛夌瓑銆傚搴旂畝鍗曞瓧绗﹂泦鐨勬暟缁勩傚弬瑙5.10.4鑺傦紝鈥滃瓧绗﹀畾涔夋暟缁勨

4.    鍦ㄦ枃浠堕《閮紝娣诲姞娉ㄩ噴锛

5.            /*
6.            * This comment is parsed by configure to create ctype.c,
7.            * so don't change it unless you know what you are doing.
8.            *
9.            * .configure. number_MYSET=MYNUMBER
10.        * .configure. strxfrm_multiply_MYSET=N
11.        * .configure. mbmaxlen_MYSET=N
12.        */

configure绋嬪簭浣跨敤璇ユ敞閲婅嚜鍔ㄥ皢瀛楃闆嗗寘鎷繘MySQL搴撲腑銆

鍦ㄤ笅闈㈢珷鑺備腑瑙i噴strxfrm_multiplymbmaxlen 琛屻傚彧鏈夐渶瑕佸瓧绗︿覆姣旇緝鍑芥暟鎴栧瀛楄妭瀛楃闆嗗嚱鏁版椂锛屾墠闇瑕佸崟鐙皢瀹冧滑鍖呮嫭杩涙潵銆

13.鐒跺悗浣犲簲鍒涘缓涓嬮潰鐨勫嚱鏁帮細

    • my_strncoll_MYSET()
    • my_strcoll_MYSET()
    • my_strxfrm_MYSET()
    • my_like_range_MYSET()

鍙傝5.10.5鑺傦紝鈥滃瓧绗︿覆姣旇緝鏀寔鈥

14.灏嗗瓧绗﹂泦鍚嶆坊鍔犲埌configurE.inCHARSETS_AVAILABLECOMPILED_CHARSETS鍒椼

15.閲嶆柊閰嶇疆銆佺紪璇戝苟娴嬭瘯銆

sql/share/charsets/README鏂囦欢涓寘鎷缁嗙殑璇存槑銆

濡傛灉浣犳兂瑕MySQL鍒嗗彂涓殑瀛楃闆嗭紝璇峰悜MySQL鍐呴儴閭欢绯荤粺鍙戦偖浠躲傚弬瑙1.7.1.1鑺傦紝鈥淭he MySQL閭欢鍒楄〃鈥

5.10.4. 瀛楃瀹氫箟鏁扮粍

to_lower[]to_upper[]鏄畝鍗曟暟缁勶紝鍚湁灏忓啓鍜屽ぇ鍐欏瓧绗︼紝瀵瑰簲瀛楃闆嗙殑姣忎釜鎴愬憳銆備緥濡傦細

to_lower['A'] should contain 'a'
to_upper['a'] should contain 'A'

sort_order[]鏄竴涓槧灏勶紝琛ㄧず濡備綍鎺掑垪瀛楃鐨勯『搴忥紝浠ヤ究杩涜姣旇緝鍜屾帓搴忋傞氬父(浣嗛潪瀵逛簬鎵鏈夊瓧绗﹂泦)to_upper[]鐩稿悓锛岃鏄庢帓搴忓澶у皬鍐欐晱鎰熴MySQL鎺掑簭瀛楃鍩轰簬sort_order[]鍏冪礌鐨勫笺傚浜庢洿鍔犲鏉傜殑鎺掑簭瑙勫垯锛屽弬瑙5.10.5鑺傦紝鈥滃瓧绗︿覆姣旇緝鏀寔鈥鐨勫瓧绗︿覆 鏍″瑙勫垯璁ㄨ銆

ctype[]鏄竴涓綅鏁扮粍锛屾瘡涓瓧绗︿负涓涓厓绱犮(璇锋敞鎰忓瓧绗﹀肩储寮to_lower[]to_upper[]sort_order[]锛屼絾鐢ㄥ瓧绗﹀+ 1绱㈠紩ctype[]銆傝繖鏄紶缁熺殑杞崲鏂规硶锛岃兘澶熷鐞EOF

m_ctype.h涓湁涓嬮潰鐨勪綅鎺╃爜瀹氫箟锛

#define _U      01      /* Uppercase */
#define _L      02      /* Lowercase */
#define _N      04      /* Numeral (digit) */
#define _S      010     /* Spacing character */
#define _P      020     /* Punctuation */
#define _C      040     /* Control character */
#define _B      0100    /* Blank */
#define _X      0200    /* heXadecimal digit */

姣忎釜瀛楃鐨ctype[]鏉$洰搴斾负鐩稿簲鐨勬弿杩板瓧绗︾殑浣嶆帺鐮佸肩殑鑱斿悎銆備緥濡傦紝'A'鏄ぇ鍐欏瓧绗(_U)浠ュ強鍗佸叚杩涘埗鏁存暟(_X)锛屽洜姝ctype['A'+1]搴斿寘鍚 鍊硷細

_U + _X = 01 + 0200 = 0201

5.10.5. 瀛楃涓叉瘮杈冩敮鎸

濡傛灉璇█鐨勬帓搴忚鍒欐瘮杈冨鏉傦紝涓嶈兘鐢ㄧ畝鍗sort_order[]琛ㄦ潵澶勭悊锛岄渶瑕佷娇鐢ㄥ瓧绗︿覆姣旇緝鍑芥暟銆

鏈濂界殑鏂囨。鏄凡鏈夊瓧绗﹂泦銆備互big5czechgbksjistis160瀛楃闆嗕綔涓轰緥瀛愩

浣犲繀椤诲湪鏂囦欢椤堕儴鐨勭壒娈婃敞閲婂鎸囧畾strxfrm_multiply_MYSET=N鍊笺N搴旇缃负瀛楃涓插湪my_strxfrm_MYSET杩囩▼涓彲鑳藉闀跨殑鏈澶ф瘮渚(蹇呴』涓烘鏁存暟)

5.10.6. 澶氬瓧鑺傚瓧绗︽敮鎸

濡傛灉浣犳兂瑕佹坊鍔犲寘鎷瀛楄妭瀛楃鐨勬柊瀛楃闆嗘敮鎸侊紝闇瑕佷娇鐢ㄥ瀛楄妭瀛楃鍑芥暟銆

鏈濂界殑鏂囨。鏄凡鏈夊瓧绗﹂泦銆備互euc_krgb2312,gbksjisujis瀛楃闆嗕綔涓轰緥瀛愩傝繖浜涘瓧绗﹂泦浣嶄簬strings鐩綍鐨ctype-charset.c鏂囦欢涓

蹇呴』鍦ㄦ枃浠堕《閮ㄧ殑鐗规畩娉ㄩ噴澶勬寚瀹mbmaxlen_MYSET=N鍊笺N搴旇缃负瀛楃闆嗗唴鏈闀垮瓧绗︾殑瀛楄妭鏁般

5.10.7. 瀛楃闆嗛棶棰

濡傛灉浣犳兂瑕佷娇鐢ㄦ病鏈夌紪璇戜负浜岃繘鍒剁殑瀛楃闆嗭紝鍙兘浼氶亣鍒颁笅闈㈢殑闂锛

         浣犵殑绋嬪簭鐨勫瓧绗﹂泦淇濆瓨璺緞涓嶆纭(榛樿涓/usr/local/mysql/share/mysql/charsets)銆傚彲浠ュ湪杩愯鏈夐棶棰樼殑绋嬪簭鏃堕氳繃--character-sets-dir閫夐」鏉ヤ慨澶嶃

         瀛楃闆嗕负澶氬瓧鑺傚瓧绗﹂泦锛屼笉鑳藉姩鎬佽浇鍏ャ傚湪杩欑鎯呭喌涓嬶紝浣犲繀椤婚噸鏂扮紪璇戠▼搴忥紝浠ユ敮鎸佸瓧绗﹂泦銆

         瀛楃闆嗕负鍔ㄦ佸瓧绗﹂泦锛屼絾浣犳病鏈夊搴旂殑閰嶇疆鏂囦欢銆傚湪杩欑鎯呭喌涓嬶紝浣犲簲浠庢柊MySQL鍒嗗彂瀹夎璇ュ瓧绗﹂泦鐨勯厤缃枃浠躲

         濡傛灉Index鏂囦欢娌℃湁鍖呭惈瀛楃闆嗗悕锛岀▼搴忓皢鏄剧ず涓嬮潰鐨勯敊璇秷鎭細

                ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf'
                not found (Errcode2)

鍦ㄨ繖绉嶆儏鍐典笅锛屼綘搴旇幏寰楁柊Index鏂囦欢鎴栧湪褰撳墠鏂囦欢涓墜鍔ㄦ坊鍔犲瓧绗﹂泦銆

瀵逛簬MyISAM琛紝鍙互鐢myisamchk -dvv tbl_name妫鏌ヨ〃鐨勫瓧绗﹂泦鍚嶅拰缂栧彿銆

5.10.8. MySQL鏈嶅姟鍣ㄦ椂鍖烘敮鎸

 MySQL鏈嶅姟鍣ㄦ湁鍑犱釜鏃跺尯璁剧疆锛

         绯荤粺鏃跺尯銆傛湇鍔″櫒鍚姩鏃朵究璇曞浘纭畾涓绘満鐨勬椂鍖猴紝鐢ㄥ畠鏉ヨ缃system_time_zone绯荤粺鍙橀噺銆

         鏈嶅姟鍣ㄥ綋鍓嶇殑鏃跺尯銆傚叏灞绯荤粺鍙橀噺time_zone琛ㄧず鏈嶅姟鍣ㄥ綋鍓嶄娇鐢ㄧ殑鏃跺尯銆傚垵浣垮间负'SYSTEM'锛岃鏄庢湇鍔″櫒鏃跺尯涓庣郴缁熸椂鍖虹浉鍚屻傚彲浠ョ敤--default-time-zone=timez閫夐」鏄惧紡鎸囧畾鍒濅娇鍊笺傚鏋滀綘鏈SUPER 鏉冮檺锛屽彲浠ョ敤涓嬮潰鐨勮鍙ュ湪杩愯鏃惰缃叏灞鍙橀噺鍊硷細

                mysql> SET GLOBAL time_zone = timezone;

         姣忎釜杩炴帴鐨勬椂鍖恒傛瘡涓鎴风杩炴帴鏈夎嚜宸辩殑鏃跺尯璁剧疆锛岀敤浼氳瘽time_zone鍙橀噺缁欏嚭銆傚叾鍒濅娇鍊间笌鍏ㄥ眬鍙橀噺time_zone鐩稿悓锛屼絾鍙互鐢ㄤ笅闈㈢殑璇彞閲嶈锛

                mysql> SET time_zone = timezone;

鍙互鐢ㄤ笅闈㈢殑鏂规硶鏌ヨ褰撳墠鐨勫叏灞鍙橀噺鍊煎拰姣忎釜杩炴帴鐨勬椂鍖猴細

mysql> SELECT @@global.time_zone, @@session.time_zone;

timezone鍊间负瀛楃涓诧紝琛ㄧずUTC鐨勫亸绉婚噺锛屼緥濡'+10:00''-6:00'銆傚鏋滃凡缁忓垱寤哄苟瑁呭叆mysql鏁版嵁搴撲腑鐨勬椂鍖虹浉鍏宠〃锛屼綘杩樺彲浠ヤ娇鐢ㄥ懡鍚嶇殑鏃跺尯锛屼緥濡'Europe/Helsinki''US/Eastern''MET'銆傚'SYSTEM'璇存槑璇ユ椂鍖哄簲涓庣郴缁熸椂鍖虹浉鍚屻傛椂鍖哄悕瀵瑰ぇ灏忓啓涓嶆晱鎰熴

MySQL瀹夎绋嬪簭鍦mysql鏁版嵁搴撲腑鍒涘缓鏃跺尯琛紝浣嗕笉瑁呰浇銆備綘蹇呴』鎵嬪姩瑁呰浇銆(濡傛灉浣犳浠庝互鍓嶇殑鐗堟湰鍗囩骇鍒MySQL 4.1.3鎴栨洿鏂扮増鏈紝浣犲簲閫氳繃鍗囩骇mysql鏁版嵁搴撴潵鍒涘缓琛ㄣ傚弬瑙2.10.2鑺傦紝鈥滃崌绾ф巿鏉冭〃鈥涓殑璇存槑锛

濡傛灉浣犵殑绯荤粺鏈夎嚜宸辩殑鏃跺尯淇℃伅鏁版嵁搴(鎻忚堪鏃跺尯鐨勪竴绯诲垪鏂囦欢)锛屽簲浣跨敤mysql_tzinfo_to_sql绋嬪簭鏉ュ~鍏呮椂鍖鸿〃銆傜ず渚嬬郴缁熷LinuxFreeBSDSun SolarisMac OS X銆傝繖浜涙枃浠剁殑鍙兘浣嶇疆涓/usr/share/zoneinfo鐩綍銆傚鏋滀綘鐨勭郴缁熸病鏈夋椂鍖轰俊鎭暟鎹簱锛屽彲浠ヤ娇鐢ㄦ湰鑺傚悗闈㈡弿杩扮殑涓嬭浇鐨勮蒋浠跺寘銆

mysql_tzinfo_to_sql绋嬪簭鐢ㄦ潵瑁呰浇鏃跺尯琛ㄣ傚湪鍛戒护琛屼腑锛屽皢鏃跺尯淇℃伅鐩綍璺緞鍚嶄紶閫掑埌mysql_tzinfo_to_sql骞惰緭鍑哄彂閫佸埌mysql绋嬪簭銆備緥濡傦細

shell> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

mysql_tzinfo_to_sql璇诲彇绯荤粺鏃跺尯鏂囦欢骞剁敓鎴SQL璇彞銆mysql澶勭悊杩欎簺璇彞骞惰杞芥椂鍖鸿〃銆

mysql_tzinfo_to_sql杩樺彲浠ョ敤鏉ヨ杞藉崟涓椂鍖烘枃浠讹紝骞剁敓鎴愰棸绉掍俊鎭

瑕佹兂瑁呰浇瀵瑰簲鏃跺尯tz_name鐨勫崟涓椂鍖烘枃浠tz_file锛屽簲杩欐牱璋冪敤mysql_tzinfo_to_sql

shell> mysql_tzinfo_to_sql tz_file tz_name | mysql -u root mysql

濡傛灉浣犵殑鏃跺尯闇瑕佽绠楅棸绉掞紝鎸変笅闈㈡柟娉曞垵浣垮寲闂扮淇℃伅锛屽叾涓tz_file鏄椂鍖烘枃浠跺悕锛

shell> mysql_tzinfo_to_sql --leap tz_file | mysql -u root mysql

濡傛灉浣犵殑绯荤粺娌℃湁鏃跺尯淇℃伅鏁版嵁搴 (渚嬪锛WindowsHP-UX)锛屼綘鍙互浠http://dev.mysql.com/downloads/timezones.html涓嬭浇棰勬瀯寤烘椂鍖鸿〃杞欢鍖呫傝杞欢鍖呭寘鍚MyISAM鏃跺尯琛ㄦ墍鐢ㄧ殑.frm.MYD.MYI鏂囦欢銆傝繖浜涜〃搴斿睘浜mysql鏁版嵁搴擄紝鍥犳搴斿皢杩欎簺鏂囦欢鏀惧埌MySQL鏈嶅姟鍣ㄦ暟鎹洰褰曠殑mysql瀛愮洰褰曘傛搷浣滄椂搴斿叧闂湇鍔″櫒銆

璀﹀憡锛濡傛灉浣犵殑绯荤粺鏈夋椂鍖轰俊鎭暟鎹簱锛岃涓嶈浣跨敤涓嬭浇鐨勮蒋浠跺寘銆傝屽簲浣跨敤mysql_tzinfo_to_sql瀹炵敤宸ュ叿锛佸惁鍒欙紝MySQL鍜岀郴缁熶笂鍏跺畠搴旂敤绋嬪簭澶勭悊鏃ユ湡鏃堕棿鐨勬柟娉曚細鏈夋墍涓嶅悓銆

鍏充簬鍦ㄥ鍒舵椂鏃跺尯璁剧疆鐩稿叧璇锋煡闃6.7鑺傦紝鈥滃鍒剁壒鎬у拰宸茬煡闂鈥

5.11. MySQL鏃ュ織鏂囦欢

MySQL鏈夊嚑涓笉鍚岀殑鏃ュ織鏂囦欢锛屽彲浠ュ府鍔╀綘鎵惧嚭mysqld鍐呴儴鍙戠敓鐨勪簨鎯咃細

鏃ュ織鏂囦欢

璁板叆鏂囦欢涓殑淇℃伅绫诲瀷

閿欒鏃ュ織

璁板綍鍚姩銆佽繍琛屾垨鍋滄mysqld鏃跺嚭鐜扮殑闂銆

鏌ヨ鏃ュ織

璁板綍寤虹珛鐨勫鎴风杩炴帴鍜屾墽琛岀殑璇彞銆

鏇存柊鏃ュ織

璁板綍鏇存敼鏁版嵁鐨勮鍙ャ備笉璧炴垚浣跨敤璇ユ棩蹇椼

浜岃繘鍒舵棩蹇

璁板綍鎵鏈夋洿鏀规暟鎹殑璇彞銆傝繕鐢ㄤ簬澶嶅埗銆

鎱㈡棩蹇

璁板綍鎵鏈夋墽琛屾椂闂磋秴杩long_query_time绉掔殑鎵鏈夋煡璇㈡垨涓嶄娇鐢ㄧ储寮曠殑鏌ヨ銆

榛樿鎯呭喌涓嬶紝鎵鏈夋棩蹇楀垱寤轰簬mysqld鏁版嵁鐩綍涓傞氳繃鍒锋柊鏃ュ織锛屼綘鍙互寮哄埗 mysqld鏉ュ叧闂拰閲嶆柊鎵撳紑鏃ュ織鏂囦欢锛堟垨鑰呭湪鏌愪簺鎯呭喌涓嬪垏鎹㈠埌涓涓柊鐨勬棩蹇楋級銆傚綋浣犳墽琛屼竴涓FLUSH LOGS璇彞鎴栨墽琛mysqladmin flush-logsmysqladmin refresh鏃讹紝鍑虹幇鏃ュ織鍒锋柊銆傚弬瑙13.5.5.2鑺傦紝鈥淔LUSH璇硶鈥

濡傛灉浣犳浣跨敤MySQL澶嶅埗鍔熻兘锛屼粠澶嶅埗鏈嶅姟鍣ㄥ皢缁存姢鏇村鏃ュ織鏂囦欢锛岃绉颁负鎺ユ浛鏃ュ織銆傜浉鍏宠璁哄弬瑙绗6绔狅細MySQL涓殑澶嶅埗

5.11.1. 閿欒鏃ュ織

閿欒鏃ュ織鏂囦欢鍖呭惈浜嗗綋mysqld鍚姩鍜屽仠姝㈡椂锛屼互鍙婃湇鍔″櫒鍦ㄨ繍琛岃繃绋嬩腑鍙戠敓浠讳綍涓ラ噸閿欒鏃剁殑鐩稿叧淇℃伅銆

濡傛灉mysqld鑾悕鍏跺鍦版鎺夊苟涓mysqld_safe闇瑕侀噸鏂板惎鍔ㄥ畠锛mysqld_safe鍦ㄩ敊璇棩蹇椾腑鍐欏叆涓鏉restarted mysqld娑堟伅銆傚鏋mysqld娉ㄦ剰鍒伴渶瑕佽嚜鍔ㄦ鏌ユ垨鐫淇涓涓〃锛屽垯閿欒鏃ュ織涓啓鍏ヤ竴鏉℃秷鎭

鍦ㄤ竴浜涙搷浣滅郴缁熶腑锛屽鏋mysqld姝绘帀锛岄敊璇棩蹇楀寘鍚爢鏍堣窡韪俊鎭傝窡韪俊鎭彲浠ョ敤鏉ョ‘瀹mysqld姝绘帀鐨勫湴鏂广傚弬瑙E.1.4鑺傦紝鈥滀娇鐢ㄥ爢鏍堣窡韪

鍙互鐢--log-error[=file_name]閫夐」鏉ユ寚瀹mysqld淇濆瓨閿欒鏃ュ織鏂囦欢鐨勪綅缃傚鏋滄病鏈夌粰瀹file_name鍊硷紝mysqld浣跨敤閿欒鏃ュ織鍚host_name.err 骞跺湪鏁版嵁鐩綍涓啓鍏ユ棩蹇楁枃浠躲傚鏋滀綘鎵цFLUSH LOGS锛岄敊璇棩蹇楃敤-old閲嶆柊鍛藉悕鍚庣紑骞朵笖mysqld鍒涘缓涓涓柊鐨勭┖鏃ュ織鏂囦欢銆(濡傛灉鏈粰鍑--log-error閫夐」锛屽垯涓嶄細閲嶆柊鍛藉悕锛

濡傛灉涓嶆寚瀹--log-error锛屾垨鑰(Windows)濡傛灉浣犱娇鐢--console閫夐」锛岄敊璇鍐欏叆鏍囧噯閿欒杈撳嚭stderr銆傞氬父鏍囧噯杈撳嚭涓轰綘鐨勭粓绔

Windows涓紝濡傛灉鏈粰鍑--console閫夐」锛岄敊璇緭鍑烘绘槸鍐欏叆.err鏂囦欢銆

5.11.2. 閫氱敤鏌ヨ鏃ュ織

濡傛灉浣犳兂瑕佺煡閬mysqld鍐呴儴鍙戠敓浜嗕粈涔堬紝浣犲簲璇ョ敤--log[=file_name]-l [file_name]閫夐」鍚姩瀹冦傚鏋滄病鏈夌粰瀹file_name鐨勫硷紝 榛樿鍚嶆槸host_name.log鎵鏈夎繛鎺ュ拰璇彞琚褰曞埌鏃ュ織鏂囦欢銆傚綋浣犳鐤戝湪瀹㈡埛绔彂鐢熶簡閿欒骞舵兂纭垏鍦扮煡閬撹瀹㈡埛绔彂閫佺粰mysqld鐨勮鍙ユ椂锛岃鏃ュ織鍙兘闈炲父鏈夌敤

mysqld鎸夌収瀹冩帴鏀剁殑椤哄簭璁板綍璇彞鍒版煡璇㈡棩蹇椼傝繖鍙兘涓庢墽琛岀殑椤哄簭涓嶅悓銆傝繖涓庢洿鏂版棩蹇楀拰浜岃繘鍒舵棩蹇椾笉鍚岋紝瀹冧滑鍦ㄦ煡璇㈡墽琛屽悗锛屼絾鏄换浣曚竴涓攣閲婃斁涔嬪墠璁板綍鏃ュ織銆(鏌ヨ鏃ュ織杩樺寘鍚墍鏈夎鍙ワ紝鑰屼簩杩涘埗鏃ュ織涓嶅寘鍚彧鏌ヨ鏁版嵁鐨勮鍙ワ級

鏈嶅姟鍣ㄩ噸鏂板惎鍔ㄥ拰鏃ュ織鍒锋柊涓嶄細浜х敓鏂扮殑涓鑸煡璇㈡棩蹇楁枃浠(灏界鍒锋柊鍏抽棴骞堕噸鏂版墦寮涓鑸煡璇㈡棩蹇楁枃浠)銆傚湪Unix涓紝浣犲彲浠ラ氳繃涓嬮潰鐨勫懡浠ら噸鏂板懡鍚嶆枃浠跺苟鍒涘缓涓涓柊鏂囦欢锛

shell> mv hostname.log hostname-old.log
shell> mysqladmin flush-logs
shell> cp hostname-old.log to-backup-directory
shell> rm hostname-old.log

Windows涓紝鏈嶅姟鍣ㄦ墦寮鏃ュ織鏂囦欢鏈熼棿浣犱笉鑳介噸鏂板懡鍚嶆棩蹇楁枃浠躲備綘蹇呴』鍏堝仠姝㈡湇鍔″櫒鐒跺悗閲嶆柊鍛藉悕鏃ュ織鏂囦欢銆傜劧鍚庯紝閲嶅惎鏈嶅姟鍣ㄦ潵鍒涘缓鏂扮殑鏃ュ織鏂囦欢銆

5.11.3. 浜岃繘鍒舵棩蹇

浜岃繘鍒舵棩蹇椾互涓绉嶆洿鏈夋晥鐨勬牸寮忥紝骞朵笖鏄簨鍔″畨鍏ㄧ殑鏂瑰紡鍖呭惈鏇存柊鏃ュ織涓彲鐢ㄧ殑鎵鏈変俊鎭

浜岃繘鍒舵棩蹇楀寘鍚簡鎵鏈夋洿鏂颁簡鏁版嵁鎴栬呭凡缁忔綔鍦ㄦ洿鏂颁簡鏁版嵁锛堜緥濡傦紝娌℃湁鍖归厤浠讳綍琛岀殑涓涓DELETE锛夌殑鎵鏈夎鍙ャ傝鍙ヤ互鈥浜嬩欢鈥濈殑褰㈠紡淇濆瓨锛屽畠鎻忚堪鏁版嵁鏇存敼銆

閲婏細浜岃繘鍒舵棩蹇楀凡缁忎唬鏇夸簡鑰佺殑鏇存柊鏃ュ織锛屾洿鏂版棩蹇楀湪MySQL 5.1涓笉鍐嶄娇鐢ㄣ

浜岃繘鍒舵棩蹇楄繕鍖呭惈鍏充簬姣忎釜鏇存柊鏁版嵁搴撶殑璇彞鐨勬墽琛屾椂闂翠俊鎭傚畠涓嶅寘鍚病鏈変慨鏀逛换浣曟暟鎹殑璇彞銆傚鏋滀綘鎯宠璁板綍鎵鏈夎鍙ワ紙渚嬪锛屼负浜嗚瘑鍒湁闂鐨勬煡璇級锛屼綘搴斾娇鐢ㄤ竴鑸煡璇㈡棩蹇椼傚弬瑙5.11.2鑺傦紝鈥滈氱敤鏌ヨ鏃ュ織鈥

浜岃繘鍒舵棩蹇楃殑涓昏鐩殑鏄湪鎭㈠浣胯兘澶熸渶澶у彲鑳藉湴鏇存柊鏁版嵁搴擄紝鍥犱负浜岃繘鍒舵棩蹇楀寘鍚浠藉悗杩涜鐨勬墍鏈夋洿鏂般

浜岃繘鍒舵棩蹇楄繕鐢ㄤ簬鍦ㄤ富澶嶅埗鏈嶅姟鍣ㄤ笂璁板綍鎵鏈夊皢鍙戦佺粰浠庢湇鍔″櫒鐨勮鍙ャ傚弬瑙绗6绔狅細MySQL涓殑澶嶅埗

杩愯鏈嶅姟鍣ㄦ椂鑻ュ惎鐢ㄤ簩杩涘埗鏃ュ織鍒欐ц兘澶х害鎱1%銆備絾鏄紝浜岃繘鍒舵棩蹇楃殑濂藉锛屽嵆鐢ㄤ簬鎭㈠骞跺厑璁歌缃鍒惰秴杩囦簡杩欎釜灏忓皬鐨勬ц兘鎹熷け銆

褰撶敤--log-bin[=file_name]閫夐」鍚姩鏃讹紝mysqld鍐欏叆鍖呭惈鎵鏈夋洿鏂版暟鎹殑SQL鍛戒护鐨勬棩蹇楁枃浠躲傚鏋滄湭缁欏嚭file_name鍊硷紝 榛樿鍚嶄负-bin鍚庨潰鎵璺熺殑涓绘満鍚嶃傚鏋滅粰鍑轰簡鏂囦欢鍚嶏紝浣嗘病鏈夊寘鍚矾寰勶紝鍒欐枃浠惰鍐欏叆鏁版嵁鐩綍銆傚缓璁寚瀹氫竴涓枃浠跺悕锛屽師鍥犲弬瑙A.8.1鑺傦紝鈥淢ySQL涓殑鎵撳紑浜嬪疁鈥

濡傛灉浣犲湪鏃ュ織鍚嶄腑鎻愪緵浜嗘墿灞曞悕(渚嬪锛--log-bin=file_name.extension)锛屽垯鎵╁睍鍚嶈鎮勬倓闄ゆ帀骞跺拷鐣ャ

mysqld鍦ㄦ瘡涓簩杩涘埗鏃ュ織鍚嶅悗闈㈡坊鍔犱竴涓暟瀛楁墿灞曞悕銆傛瘡娆′綘鍚姩鏈嶅姟鍣ㄦ垨鍒锋柊鏃ュ織鏃惰鏁板瓧鍒欏鍔犮傚鏋滃綋鍓嶇殑鏃ュ織澶у皬杈惧埌max_binlog_size锛岃繕浼氳嚜鍔ㄥ垱寤烘柊鐨勪簩杩涘埗鏃ュ織銆傚鏋滀綘姝d娇鐢ㄥぇ鐨勪簨鍔★紝浜岃繘鍒舵棩蹇楄繕浼氳秴杩max_binlog_size锛氫簨鍔″叏鍐欏叆涓涓簩杩涘埗鏃ュ織涓紝缁濆涓嶈鍐欏叆涓嶅悓鐨勪簩杩涘埗鏃ュ織涓

涓轰簡鑳藉鐭ラ亾杩樹娇鐢ㄤ簡鍝釜涓嶅悓鐨勪簩杩涘埗鏃ュ織鏂囦欢锛mysqld杩樺垱寤轰竴涓簩杩涘埗鏃ュ織绱㈠紩鏂囦欢锛屽寘鍚墍鏈変娇鐢ㄧ殑浜岃繘鍒舵棩蹇楁枃浠剁殑鏂囦欢鍚嶃傞粯璁ゆ儏鍐典笅涓庝簩杩涘埗鏃ュ織鏂囦欢鐨勬枃浠跺悕鐩稿悓锛屾墿灞曞悕涓'.index'銆備綘鍙互鐢--log-bin-index[=file_name]閫夐」鏇存敼浜岃繘鍒舵棩蹇楃储寮曟枃浠剁殑鏂囦欢鍚嶃傚綋mysqld鍦ㄨ繍琛屾椂锛屼笉搴旀墜鍔ㄧ紪杈戣鏂囦欢锛涘鏋滆繖鏍峰仛灏嗕細浣mysqld鍙樺緱娣蜂贡銆

鍙互鐢RESET MASTER璇彞鍒犻櫎鎵鏈変簩杩涘埗鏃ュ織鏂囦欢锛屾垨鐢PURGE MASTER LOGS鍙垹闄ら儴鍒嗕簩杩涘埗鏂囦欢銆傚弬瑙13.5.5.5鑺傦紝鈥淩ESET璇硶鈥13.6.1鑺傦紝鈥滅敤浜庢帶鍒朵富鏈嶅姟鍣ㄧ殑SQL璇彞鈥

浜岃繘鍒舵棩蹇楁牸寮忔湁涓浜涘凡鐭ラ檺鍒讹紝浼氬奖鍝嶄粠澶囦唤鎭㈠銆傚弬瑙6.7鑺傦紝鈥滃鍒剁壒鎬у拰宸茬煡闂鈥

淇濆瓨绋嬪簭鍜岃Е鍙戝櫒鐨勪簩杩涘埗鏃ュ織鐨勬弿杩板弬瑙20.4鑺傦紝鈥滃瓨鍌ㄥ瓙绋嬪簭鍜岃Е鍙戠▼搴忕殑浜岃繘鍒舵棩蹇楀姛鑳解

鍙互浣跨敤涓嬮潰鐨mysqld閫夐」鏉ュ奖鍝嶈褰曞埌浜岃繘鍒舵棩蹇楃煡鐨勫唴瀹广傚張瑙侀夐」鍚庨潰鐨勮璁恒

         --binlog-do-db=db_name

鍛婅瘔涓绘湇鍔″櫒锛屽鏋滃綋鍓嶇殑鏁版嵁搴(USE閫夊畾鐨勬暟鎹簱)db_name锛屽簲灏嗘洿鏂拌褰曞埌浜岃繘鍒舵棩蹇椾腑銆傚叾瀹冩墍鏈夋病鏈夋槑鏄炬寚瀹氱殑鏁版嵁搴  琚拷鐣ャ傚鏋滀娇鐢ㄨ閫夐」锛屼綘搴旂‘淇濆彧瀵瑰綋鍓嶇殑鏁版嵁搴撹繘琛屾洿鏂般

瀵逛簬CREATE DATABASEALTER DATABASEDROP DATABASE璇彞锛屾湁涓涓緥澶栵紝鍗抽氳繃鎿嶄綔鐨勬暟鎹簱鏉ュ喅瀹氭槸鍚﹀簲璁板綍璇彞锛岃屼笉鏄敤褰撳墠鐨勬暟鎹簱銆

涓涓笉鑳芥寜鐓ф湡鏈涙墽琛岀殑渚嬪瓙锛氬鏋滅敤binlog-do-db=sales鍚姩鏈嶅姟鍣紝骞朵笖鎵цUSE prices; UPDATE sales.january SET amount=amount+1000锛岃璇彞涓嶅啓鍏ヤ簩杩涘埗鏃ュ織銆

         --binlog-ignore-db=db_name

鍛婅瘔涓绘湇鍔″櫒锛屽鏋滃綋鍓嶇殑鏁版嵁搴(USE閫夊畾鐨勬暟鎹簱)db_name锛屼笉搴斿皢鏇存柊淇濆瓨鍒颁簩杩涘埗鏃ュ織涓傚鏋滀綘浣跨敤璇ラ夐」锛屼綘搴旂‘淇濆彧瀵瑰綋鍓嶇殑鏁版嵁搴撹繘琛屾洿鏂般

涓涓笉鑳芥寜鐓т綘鏈熸湜鐨勬墽琛岀殑渚嬪瓙锛氬鏋滄湇鍔″櫒鐢binlog-ignore-db=sales鍚姩锛屽苟涓旀墽琛USE prices; UPDATE sales.january SET amount=amount+1000锛岃璇彞涓嶅啓鍏ヤ簩杩涘埗鏃ュ織銆

绫讳技浜--binlog-do-db锛屽浜CREATE DATABASEALTER DATABASEDROP DATABASE璇彞锛屾湁涓涓緥澶栵紝鍗抽氳繃鎿嶄綔鐨勬暟鎹簱鏉ュ喅瀹氭槸鍚﹀簲璁板綍璇彞锛岃屼笉鏄敤褰撳墠鐨勬暟鎹簱銆

瑕佹兂璁板綍鎴栧拷瑙嗗涓暟鎹簱锛屼娇鐢ㄥ涓夐」锛屼负姣忎釜鏁版嵁搴撴寚瀹氱浉搴旂殑閫夐」銆

鏈嶅姟鍣ㄦ牴鎹笅闈㈢殑瑙勫垯瀵归夐」杩涜璇勪及锛屼互渚垮皢鏇存柊璁板綍鍒颁簩杩涘埗鏃ュ織涓垨蹇借銆傝娉ㄦ剰瀵逛簬CREATE/ALTER/DROP DATABASE璇彞鏈変竴涓緥澶栥傚湪杩欎簺鎯呭喌涓嬶紝鏍规嵁浠ヤ笅瑙勫垯锛屾墍鍒涘缓銆淇敼鎴栧垹闄ょ殑鏁版嵁搴撳皢浠f浛褰撳墠鐨勬暟鎹簱銆

1.    鏄惁鏈binlog-do-dbbinlog-ignore-db瑙勫垯?

         娌℃湁锛氬皢璇彞鍐欏叆浜岃繘鍒舵棩蹇楀苟閫鍑恒

         鏈夛細鎵ц涓嬩竴姝ャ

2.    鏈変竴浜涜鍒(binlog-do-dbbinlog-ignore-db鎴栦簩鑰呴兘鏈)銆傚綋鍓嶆湁涓涓暟鎹簱(USE鏄惁閫夋嫨浜嗘暟鎹簱?)?

         娌℃湁锛涓嶈鍐欏叆璇彞锛屽苟閫鍑恒

         鏈夛細鎵ц涓嬩竴姝ャ

3.    鏈夊綋鍓嶇殑鏁版嵁搴撱傛槸鍚︽湁binlog-do-db瑙勫垯?

         鏈夛細褰撳墠鐨勬暟鎹簱鏄惁鍖归厤binlog-do-db瑙勫垯?

o        鏈夛細鍐欏叆璇彞骞堕鍑恒

o        娌℃湁锛氫笉瑕佸啓鍏ヨ鍙ワ紝閫鍑恒

         No锛氭墽琛屼笅涓姝ャ

4.    鏈変竴浜binlog-ignore-db瑙勫垯銆傚綋鍓嶇殑鏁版嵁搴撴槸鍚﹀尮閰binlog-ignore-db瑙勫垯?

         鏈夛細涓嶈鍐欏叆璇彞锛屽苟閫鍑恒

         娌℃湁锛氬啓鍏ユ煡璇㈠苟閫鍑恒

渚嬪锛屽彧鐢binlog-do-db=sales杩愯鐨勬湇鍔″櫒涓嶅皢褰撳墠鏁版嵁搴撲笉涓sales鐨勮鍙ュ啓鍏ヤ簩杩涘埗鏃ュ織(鎹㈠彞璇濊锛binlog-do-db鏈夋椂鍙互琛ㄧず鈥蹇借鍏跺畠鏁版嵁搴)

濡傛灉浣犳杩涜澶嶅埗锛屽簲纭繚娌℃湁浠庢湇鍔″櫒鍦ㄤ娇鐢ㄦ棫鐨勪簩杩涘埗鏃ュ織鏂囦欢锛屾柟鍙垹闄ゅ畠浠備竴绉嶆柟娉曟槸姣忓ぉ涓娆℃墽琛mysqladmin flush-logs骞跺垹闄や笁澶╁墠鐨勬墍鏈夋棩蹇椼傚彲浠ユ墜鍔ㄥ垹闄わ紝鎴栨渶濂戒娇鐢PURGE MASTER LOGS(鍙傝13.6.1鑺傦紝鈥滅敤浜庢帶鍒朵富鏈嶅姟鍣ㄧ殑SQL璇彞鈥)锛岃璇彞杩樹細瀹夊叏鍦版洿鏂颁簩杩涘埗鏃ュ織绱㈠紩鏂囦欢(鍙互閲囩敤鏃ユ湡鍙傛暟)

鍏锋湁SUPER鏉冮檺鐨勫鎴风鍙互閫氳繃SET SQL_LOG_BIN=0璇彞绂佹灏嗚嚜宸辩殑璇彞璁板叆浜岃繘鍒惰褰曘傚弬瑙13.5.3鑺傦紝鈥淪ET璇硶鈥

浣犲彲浠ョ敤mysqlbinlog瀹炵敤宸ュ叿妫鏌ヤ簩杩涘埗鏃ュ織鏂囦欢銆傚鏋滀綘鎯宠閲嶆柊澶勭悊鏃ュ織姝㈢殑璇彞锛岃繖寰堟湁鐢ㄣ備緥濡傦紝鍙互浠庝簩杩涘埗鏃ュ織鏇存柊MySQL鏈嶅姟鍣紝鏂规硶濡備笅锛

shell> mysqlbinlog log-file | mysql -h server_name

鍏充簬mysqlbinlog瀹炵敤宸ュ叿鐨勮缁嗕俊鎭互鍙婂浣曚娇鐢ㄥ畠锛屽弬瑙8.6鑺傦紝鈥渕ysqlbinlog锛氱敤浜庡鐞嗕簩杩涘埗鏃ュ織鏂囦欢鐨勫疄鐢ㄥ伐鍏封

濡傛灉浣犳浣跨敤浜嬪姟锛屽繀椤讳娇鐢MySQL浜岃繘鍒舵棩蹇楄繘琛屽浠斤紝鑰屼笉鑳戒娇鐢ㄦ棫鐨勬洿鏂版棩蹇椼

鏌ヨ缁撴潫鍚庛侀攣瀹氳閲婃斁鍓嶆垨鎻愪氦瀹屾垚鍚庡垯绔嬪嵆璁板叆浜岃繘鍒舵棩蹇椼傝繖鏍峰彲浠ョ‘淇濇寜鎵ц椤哄簭璁板叆鏃ュ織銆

瀵归潪浜嬪姟琛ㄧ殑鏇存柊鎵ц瀹屾瘯鍚庣珛鍗充繚瀛樺埌浜岃繘鍒舵棩蹇椾腑銆傚浜庝簨鍔¤〃锛屼緥濡BDBInnoDB琛紝鎵鏈夋洿鏀硅〃鐨勬洿鏂(UPDATEDELETEINSERT) 琚紦瀛樿捣鏉ワ紝鐩村埌鏈嶅姟鍣ㄦ帴鏀跺埌COMMIT璇彞銆傚湪璇ョ偣锛屾墽琛屽畬COMMIT涔嬪墠锛mysqld灏嗘暣涓簨鍔″啓鍏ヤ簩杩涘埗鏃ュ織銆傚綋澶勭悊浜嬪姟鐨勭嚎绋嬪惎鍔ㄦ椂锛屽畠涓虹紦鍐叉煡璇㈠垎閰binlog_cache_size澶у皬鐨勫唴瀛樸傚鏋滆鍙ュぇ浜庤鍊硷紝绾跨▼鍒欐墦寮涓存椂鏂囦欢鏉ヤ繚瀛樹簨鍔°傜嚎绋嬬粨鏉熷悗涓存椂鏂囦欢琚垹闄ゃ

Binlog_cache_use鐘舵佸彉閲忔樉绀轰簡浣跨敤璇ョ紦鍐插尯(涔熷彲鑳芥槸涓存椂鏂囦欢)淇濆瓨璇彞鐨勪簨鍔$殑鏁伴噺銆Binlog_cache_disk_use鐘舵佸彉閲忔樉绀轰簡杩欎簺浜嬪姟涓疄闄呬笂鏈夊灏戝繀椤讳娇鐢ㄤ复鏃舵枃浠躲傝繖涓や釜鍙橀噺鍙互鐢ㄤ簬灏binlog_cache_size璋冭妭鍒拌冻澶熷ぇ鐨勫硷紝浠ラ伩鍏嶄娇鐢ㄤ复鏃舵枃浠躲

max_binlog_cache_size(榛樿4GB)鍙互鐢ㄦ潵闄愬埗鐢ㄦ潵缂撳瓨澶氳鍙ヤ簨鍔$殑缂撳啿鍖烘诲ぇ灏忋傚鏋滄煇涓簨鍔″ぇ浜庤鍊硷紝灏嗕細澶辫触骞 鍥炴粴銆

濡傛灉浣犳浣跨敤鏇存柊鏃ュ織鎴栦簩杩涘埗鏃ュ織锛屽綋浣跨敤CREATE ... SELECT or INSERT ... SELECT鏃讹紝骞惰鎻掑叆琚浆鎹负鏅氭彃鍏ャ傝繖鏍烽氳繃鍦ㄥ浠芥椂浣跨敤鏃ュ織鍙互纭繚閲嶆柊鍒涘缓琛ㄧ殑澶囦唤銆

璇锋敞鎰MySQL 5.1鍊肩殑浜岃繘鍒舵棩蹇楁牸寮忎笌浠ュ墠鐗堟湰鐨MySQL涓嶅悓锛屽洜涓哄鍒舵敼杩涗簡銆傚弬瑙6.5鑺傦紝鈥滀笉鍚孧ySQL鐗堟湰涔嬮棿鐨勫鍒跺吋瀹规р

榛樿鎯呭喌涓嬶紝骞朵笉鏄瘡娆″啓鍏ユ椂閮藉皢浜岃繘鍒舵棩蹇椾笌纭洏鍚屾銆傚洜姝ゅ鏋滄搷浣滅郴缁熸垨鏈哄櫒(涓嶄粎浠呮槸MySQL鏈嶅姟鍣)宕╂簝锛屾湁鍙兘浜岃繘鍒舵棩蹇椾腑鏈鍚庣殑璇彞涓㈠け浜嗐傝鎯抽槻姝㈣繖绉嶆儏鍐碉紝浣犲彲浠ヤ娇鐢sync_binlog鍏ㄥ眬鍙橀噺(1鏄渶瀹夊叏鐨勫硷紝浣嗕篃鏄渶鎱㈢殑)锛屼娇浜岃繘鍒舵棩蹇楀湪姣N娆′簩杩涘埗鏃ュ織鍐欏叆鍚庝笌纭洏鍚屾銆傚弬瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆傚嵆浣sync_binlog璁剧疆涓1,鍑虹幇宕╂簝鏃讹紝涔熸湁鍙兘琛ㄥ唴瀹瑰拰浜岃繘鍒舵棩蹇楀唴瀹逛箣闂村瓨鍦ㄤ笉涓鑷存с備緥濡傦紝濡傛灉浣跨敤InnoDB琛紝MySQL鏈嶅姟鍣ㄥ鐞COMMIT璇彞锛屽畠灏嗘暣涓簨鍔″啓鍏ヤ簩杩涘埗鏃ュ織骞跺皢浜嬪姟鎻愪氦鍒InnoDB濡傛灉鍦ㄤ袱娆℃搷浣滀箣闂村嚭鐜板穿婧冿紝閲嶅惎鏃讹紝浜嬪姟琚InnoDB鍥炴粴锛屼絾浠嶇劧瀛樺湪浜岃繘鍒舵棩蹇椾腑銆傚彲浠ョ敤--innodb-safe-binlog閫夐」瑙e喅璇ラ棶棰橈紝鍙互澧炲姞InnoDB琛ㄥ唴瀹瑰拰浜岃繘鍒舵棩蹇椾箣闂寸殑涓鑷存с(娉ㄩ噴锛氬湪MySQL 5.1涓笉闇瑕--innodb-safe-binlog锛涚敱浜庡紩鍏ヤ簡XA浜嬪姟鏀寔锛岃閫夐」浣滃簾浜嗭級

璇ラ夐」鍙互鎻愪緵鏇村ぇ绋嬪害鐨勫畨鍏紝杩樺簲瀵MySQL鏈嶅姟鍣ㄨ繘琛岄厤缃紝浣挎瘡涓簨鍔$殑浜岃繘鍒舵棩蹇(sync_binlog =1)(榛樿鎯呭喌涓虹湡)InnoDB鏃ュ織涓庣‖鐩樺悓姝ャ傝閫夐」鐨勬晥鏋滄槸宕╂簝鍚庨噸鍚椂锛屽湪婊氬洖浜嬪姟鍚庯紝MySQL鏈嶅姟鍣ㄤ粠浜岃繘鍒舵棩蹇楀壀鍒 鍥炴粴鐨InnoDB浜嬪姟銆傝繖鏍峰彲浠ョ‘淇濅簩杩涘埗鏃ュ織鍙嶉InnoDB琛ㄧ殑纭垏鏁版嵁绛夛紝骞朵娇浠庢湇鍔″櫒淇濇寔涓庝富鏈嶅姟鍣ㄤ繚鎸佸悓姝(涓嶆帴鏀 鍥炴粴鐨勮鍙)

璇锋敞鎰忓嵆浣MySQL鏈嶅姟鍣ㄦ洿鏂板叾瀹冨瓨鍌ㄥ紩鎿庤屼笉鏄InnoDB锛屼篃鍙互浣跨敤--innodb-safe-binlog銆傚湪InnoDB宕╂簝鎭㈠鏃讹紝鍙粠浜岃繘鍒舵棩蹇椾腑鍒犻櫎褰卞搷InnoDB琛ㄧ殑璇彞/浜嬪姟銆傚鏋滃穿婧冩仮澶嶆椂MySQL鏈嶅姟鍣ㄥ彂鐜颁簩杩涘埗鏃ュ織鍙樼煭浜(鍗宠嚦灏戠己灏戜竴涓垚鍔熸彁浜ょ殑InnoDB浜嬪姟)锛屽鏋sync_binlog =1骞朵笖纭洏/鏂囦欢绯荤粺鐨勭‘鑳芥牴鎹渶瑕佽繘琛屽悓姝(鏈変簺涓嶉渶瑕)鍒欎笉浼氬彂鐢燂紝鍒欒緭鍑洪敊璇秷鎭 ("浜岃繘鍒舵棩蹇<>姣旀湡鏈涚殑瑕佸皬")銆傚湪杩欑鎯呭喌涓嬶紝浜岃繘鍒舵棩蹇椾笉鍑嗙‘锛屽鍒跺簲浠庝富鏈嶅姟鍣ㄧ殑鏁版嵁蹇収寮濮嬨

鍐欏叆浜岃繘鍒舵棩蹇楁枃浠跺拰浜岃繘鍒舵棩蹇楃储寮曟枃浠剁殑鏂规硶涓庡啓鍏MyISAM琛ㄧ浉鍚屻傚弬瑙A.4.3鑺傦紝鈥淢ySQL澶勭悊纾佺洏婊$殑鏂瑰紡鈥

5.11.4. 鎱㈤熸煡璇㈡棩蹇

--log-slow-queries[=file_name]閫夐」鍚姩鏃讹紝mysqld鍐欎竴涓寘鍚墍鏈夋墽琛屾椂闂磋秴杩long_query_time绉掔殑SQL璇彞鐨勬棩蹇楁枃浠躲傝幏寰楀垵浣胯〃閿佸畾鐨勬椂闂翠笉绠椾綔鎵ц鏃堕棿銆

濡傛灉娌℃湁缁欏嚭file_name鍊硷紝 榛樿鏈富鏈哄悕锛屽悗缂涓-slow.log銆傚鏋滅粰鍑轰簡鏂囦欢鍚嶏紝浣嗕笉鏄粷瀵硅矾寰勫悕锛屾枃浠跺垯鍐欏叆鏁版嵁鐩綍銆

璇彞鎵ц瀹屽苟涓旀墍鏈夐攣閲婃斁鍚庤鍏ユ參鏌ヨ鏃ュ織銆傝褰曢『搴忓彲浠ヤ笌鎵ц椤哄簭涓嶇浉鍚屻

鎱㈡煡璇㈡棩蹇楀彲浠ョ敤鏉ユ壘鍒版墽琛屾椂闂撮暱鐨勬煡璇紝鍙互鐢ㄤ簬浼樺寲銆備絾鏄紝妫鏌ュ張闀垮張鎱㈢殑鏌ヨ鏃ュ織浼氬緢鍥伴毦銆傝鎯冲鏄撲簺锛屼綘鍙互浣跨敤mysqldumpslow鍛戒护鑾峰緱鏃ュ織涓樉绀虹殑鏌ヨ鎽樿鏉ュ鐞嗘參鏌ヨ鏃ュ織銆

MySQL 5.1鐨勬參鏌ヨ鏃ュ織涓紝涓嶄娇鐢ㄧ储寮曠殑鎱㈡煡璇㈠悓浣跨敤绱㈠紩鐨勬煡璇竴鏍疯褰曘傝鎯抽槻姝笉浣跨敤绱㈠紩鐨勬參鏌ヨ璁板叆鎱㈡煡璇㈡棩蹇楋紝浣跨敤--log-short-format閫夐」銆傚弬瑙5.3.1鑺傦紝鈥mysqld鍛戒护琛岄夐」鈥

MySQL 5.1,閫氳繃--log-slow-admin-statements鏈嶅姟鍣ㄩ夐」锛屼綘鍙互璇锋眰灏嗘參绠$悊璇彞锛屼緥濡OPTIMIZE TABLEANALYZE TABLE ALTER TABLE鍐欏叆鎱㈡煡璇㈡棩蹇椼

鐢ㄦ煡璇㈢紦瀛樺鐞嗙殑鏌ヨ涓嶅姞鍒版參鏌ヨ鏃ュ織涓紝鍥犱负琛ㄦ湁闆惰鎴栦竴琛岃屼笉鑳戒粠绱㈠紩涓彈鐩婄殑鏌ヨ涔熶笉鍐欏叆鎱㈡煡璇㈡棩蹇椼

5.11.5. 鏃ュ織鏂囦欢缁存姢

MySQL鏈嶅姟鍣ㄥ彲浠ュ垱寤哄悇绉嶄笉鍚岀殑鏃ュ織鏂囦欢锛屼粠鑰屽彲浠ュ緢瀹规槗鍦扮湅瑙佹墍杩涜鐨勬搷浣溿傚弬瑙5.11鑺傦紝鈥淢ySQL鏃ュ織鏂囦欢鈥銆備絾鏄紝浣犲繀椤诲畾鏈熸竻鐞嗚繖浜涙枃浠讹紝纭繚鏃ュ織涓嶄細鍗犵敤澶鐨勭‖鐩樼┖闂淬

褰撳惎鐢ㄦ棩蹇椾娇鐢MySQL鏃讹紝浣犲彲鑳芥兂瑕佷笉鏃跺湴澶囦唤骞跺垹闄ゆ棫鐨勬棩蹇楁枃浠讹紝骞跺憡璇MySQL寮濮嬭鍏ユ柊鏂囦欢銆傚弬瑙5.9.1鑺傦紝鈥滄暟鎹簱澶囦唤鈥

Linux (Redhat)鐨勫畨瑁呬笂锛屼綘鍙负姝や娇鐢mysql-log-rotate鑴氭湰銆傚鏋滀綘浠RPM鍒嗗彂瀹夎MySQL锛岃剼鏈簲璇ヨ嚜鍔ㄨ瀹夎浜嗐

鍦ㄥ叾瀹冪郴缁熶笂锛屼綘蹇呴』鑷繁瀹夎鐭剼鏈紝浣犲彲浠cron绛夊叆鎵嬪鐞嗘棩蹇楁枃浠躲

浣犲彲浠ラ氳繃mysqladmin flush-logsSQL璇彞FLUSH LOGS鏉ュ己鍒MySQL寮濮嬩娇鐢ㄦ柊鐨勬棩蹇楁枃浠躲

鏃ュ織娓呯┖鎿嶄綔鍋氫笅鍒椾簨鎯咃細

  • 濡傛灉浣跨敤鏍囧噯鏃ュ織(--log)鎴栨參鏌ヨ鏃ュ織(--log-slow-queries)锛屽叧闂苟閲嶆柊鎵撳紑鏃ュ織鏂囦欢銆(榛樿涓mysql.log`hostname`-slow.log)
  • 濡傛灉浣跨敤鏇存柊鏃ュ織(--log-update)鎴栦簩杩涘埗鏃ュ織(--log-bin)锛屽叧闂棩蹇楀苟涓旀墦寮鏈夋洿楂樺簭鍒楀彿鐨勬柊鏃ュ織鏂囦欢銆

濡傛灉浣犲彧浣跨敤鏇存柊鏃ュ織锛屼綘鍙渶瑕侀噸鏂板懡鍚嶆棩蹇楁枃浠讹紝鐒跺悗鍦ㄥ浠藉墠娓呯┖鏃ュ織銆備緥濡傦紝浣犲彲浠ヨ繖鏍峰仛锛

shell> cd mysql-data-directory
shell> mv mysql.log mysql.old
shell> mysqladmin flush-logs

鐒跺悗鍋氬浠藉苟鍒犻櫎mysql.old

5.12. 鍦ㄥ悓涓鍙版満鍣ㄤ笂杩愯澶氫釜MySQL鏈嶅姟鍣

鍦ㄤ竴浜涙儏鍐典笅锛屼綘鍙兘鎯宠鍦ㄥ悓涓鍙版満鍣ㄤ笂杩愯澶氫釜mysqld鏈嶅姟鍣銆備綘鍙兘鎯宠娴嬭瘯涓涓柊鐨MySQL鍙戝竷锛屽悓鏃朵笉褰卞搷鐜版湁浜у搧鐨勮缃傛垨鑰咃紝浣犲彲鑳芥兂浣夸笉鍚岀殑鐢ㄦ埛璁块棶鏉ヨ闂笉鍚岀殑mysqld鏈嶅姟鍣浠ヤ究浠栦滑鑷繁鏉ョ鐞嗐(渚嬪锛屼綘鍙兘鏄竴涓Internet鏈嶅姟鎻愪緵鍟嗭紝甯屾湜涓轰笉鍚岀殑瀹㈡埛鏉ユ彁渚涚嫭绔嬬殑MySQL瀹夎锛

瑕佹兂鍦ㄤ竴涓崟鐙殑鏈哄櫒涓婅繍琛屽涓湇鍔″櫒锛屾瘡涓湇鍔″櫒蹇呴』鏈夊敮涓鐨勫悇杩愯鍙傛暟鍊笺傝繖浜涘煎彲浠ュ湪鍛戒护琛屼腑璁剧疆鎴栧湪閫夐」鏂囦欢涓缃傚弬瑙4.3鑺傦紝鈥滄寚瀹氱▼搴忛夐」鈥

鑷冲皯涓嬮潰鐨勯夐」瀵规瘡涓湇鍔″櫒蹇呴』鏄笉鍚岀殑锛

         --port=port_num

--port鎺у埗鐫TCP/IP杩炴帴鐨勭鍙e彿銆

         --socket=path

--socket鎺у埗Unix涓殑Unix濂楁帴瀛楁枃浠惰矾寰勫拰鍦Windows涓殑鍛藉悕绠¢亾鍚嶇О銆傚湪Windows涓紝鍙湁鏀寔鍛藉悕绠¢亾杩炴帴鐨勬湇鍔″櫒鎵嶉渶瑕佹槑纭寚瀹氱閬撳悕绉般

         --shared-memory-base-name=name

璇ラ夐」褰撳墠鍙湪Windows涓娇鐢ㄣ傚畠鎸囧畾Windows鏈嶅姟鍣ㄤ娇鐢ㄧ殑銆佸厑璁稿鎴风閫氳繃鍏变韩鍐呭瓨鏉ヨ繛鎺ョ殑鍏变韩鍐呭瓨鍚嶃

         --pid-file=path

璇ラ夐」鍙湪Unix涓娇鐢ㄣ傚畠鎸囧嚭鏈嶅姟鍣ㄥ湪鍏朵腑鍐欏叆杩涚▼ID鐨勬枃浠跺悕銆

濡傛灉浣犱娇鐢ㄤ笅闈㈢殑鏃ュ織鏂囦欢閫夐」锛屽浜庢瘡涓湇鍔″櫒鏉ヨ锛屽畠浠繀椤绘槸涓嶅悓鐨勶細

           --log=path

         --log-bin=path

         --log-update=path

         --log-error=path

         --bdb-logdir=path

鏃ュ織鏂囦欢閫夐」鐨勬弿杩板弬瑙5.11.5鑺傦紝鈥滄棩蹇楁枃浠剁淮鎶も

涓轰簡鎻愰珮鎬ц兘锛屼綘鍙互涓烘瘡涓湇鍔″櫒鎸囧畾涓嬮潰閫夐」鐨勪笉鍚岀殑鍊硷紝浠ヤ究鍦ㄧ墿鐞嗙鐩樹箣闂村钩鍧囧垎閰嶈礋鑽凤細

         --tmpdir=path

         --bdb-tmpdir=path

杩樻帹鑽愪娇鐢ㄤ笉鍚岀殑涓存椂鐩綍锛屼互渚垮鏄撳湴纭畾鍝釜MySQL鏈嶅姟鍣ㄥ垱寤轰簡缁欏畾鐨勪复鏃舵枃浠躲

涓鑸儏鍐碉紝姣忎釜鏈嶅姟鍣ㄥ簲杩樹娇鐢ㄤ笉鍚岀殑鏁版嵁鐩綍锛屽彲浠ラ氳繃--datadir=path閫夐」鏉ユ寚瀹氥

璀﹀憡锛涓鑸儏鍐碉紝浣犲喅涓嶈璁╀袱涓湇鍔″櫒鏇存柊鐩稿悓鏁版嵁搴撲腑鐨勬暟鎹傚惁鍒欙紝濡傛灉浣犵殑鎿嶄綔绯荤粺涓嶆敮鎸佹晠闅滄帓闄ょ郴缁熼攣瀹氾紝璇ュ彲鑳戒細瀵艰嚧闈炲父濂囨殑缁撴灉銆傚鏋滐紙涓嶇悊浼氳璀﹀憡锛夎繍琛岀殑澶氫釜鏈嶅姟鍣ㄤ娇鐢ㄧ浉鍚岀殑鏁版嵁鐩綍骞朵笖鍚敤浜嗘棩蹇楄褰曪紝浣犲繀椤讳娇鐢ㄩ傚綋鐨勯夐」鏉ヤ负姣忎釜鏈嶅姟鍣ㄦ寚瀹氬敮涓鐨勬棩蹇楁枃浠跺悕銆傚惁鍒欙紝鏈嶅姟鍣ㄥ皾璇曠敤鐩稿悓鐨勬枃浠舵潵璁板綍鏃ュ織銆傝娉ㄦ剰杩欑绫诲瀷鐨勮缃彧鑳藉湪MyISAMMERGE琛ㄤ笂宸ヤ綔锛屽鍏跺畠浠讳綍瀛樺偍寮曟搸涓嶈捣浣滅敤銆

澶氫釜鏈嶅姟鍣ㄥ叡浜竴涓暟鎹洰褰曠殑璀﹀憡涔熼傜敤浜NFS鐜銆傚厑璁稿涓MySQL鏈嶅姟鍣ㄩ氳繃NFS璁块棶涓涓叡鍚岀殑鏁版嵁鐩綍鏄竴涓闈炲父涓嶅ソ鐨勪富涔

         涓昏闂鏄NFS瀛樺湪閫熷害鐡堕銆傚畠涓嶆槸鐢ㄤ簬杩欑鐢ㄩ斻

         NFS鐨勫彟涓涓啋闄╂槸浣犲繀椤绘彁鍑轰竴涓柟娉曟潵纭繚涓や釜鎴栧涓湇鍔″櫒涓嶄細鐩镐簰骞叉壈銆NFS鏂囦欢鐨勯攣瀹氶氬父鐢lockd鍚庡彴绋嬪簭澶勭悊锛屼絾鏄洰鍓嶏紝娌℃湁涓涓繍琛屽钩鍙拌兘澶熷湪姣忕鎯呭喌涓100%鍙潬鍦拌繘琛岄攣瀹氥

浣夸綘鏇村姞瀹规槗锛氬繕璁板湪鏈嶅姟鍣ㄤ箣闂撮氳繃NFS鍏变韩鏁版嵁鐩綍銆備竴涓緝濂界殑瑙e喅鏂规鏄娇鐢ㄥ寘鍚嚑涓CPU骞朵笖鍜屼娇鐢ㄦ湁鏁堝鐞嗗绾跨▼鐨勬搷浣滅郴缁熺殑鏈哄櫒銆

濡傛灉鍦ㄤ笉鍚岀殑浣嶇疆鏈夊涓MySQL鐨勫畨瑁咃紝涓鑸儏鍐靛彲浠ョ敤--basedir=path閫夐」涓烘瘡涓湇鍔″櫒鎸囧畾鍩烘湰瀹夎鐩綍锛屼娇姣忎釜鏈嶅姟鍣ㄤ娇鐢ㄤ笉鍚岀殑鏁版嵁鐩綍銆佹棩蹇楁枃浠跺拰PID鏂囦欢銆傦紙鎵鏈夎繖浜涘肩殑 榛樿鍊肩浉瀵逛簬鏍圭洰褰曟潵纭畾锛夈傞偅鏍风殑璇濓紝 浣犲敮涓闇瑕佹寚瀹氱殑鍏跺畠閫夐」鏄--socket--port閫夐」銆備緥濡傦紝鍋囧浣跨敤tar鏂囦欢浜岃繘鍒跺垎鍙戠増瀹夎涓嶅悓鐨MySQL鐗堟湰銆傝繖浜涘畨瑁呭湪涓嶅悓鐨勪綅缃紝鍥犳鍙互浣跨敤鍚勪釜瀹夎鏈嶅姟鍣ㄧ浉搴旂殑鏍圭洰褰曚腑鐨bin/mysqld_safe鍛戒护鍚姩鏈嶅姟鍣ㄣmysqld_safe纭畾姝g‘鐨--basedir閫夐」浼犻掔粰mysqld锛屼綘浠呴渶瑕佷负mysqld_safe鎸囧畾--socket--port閫夐」銆

姝e涓嬮潰鍑犺妭鎵璁ㄨ鐨勯偅鏍凤紝鍙互閫氳繃璁剧疆鐜鍙橀噺鎴栫敤鎸囧畾鐨勫懡浠よ閫夐」鏉ュ惎鍔ㄦ洿澶氱殑鏈嶅姟鍣ㄣ備絾鏄紝濡傛灉浣犻渶瑕佸湪涓涓洿绋冲畾鐨勫熀纭涓婅繍琛屽涓湇鍔″櫒锛屼竴涓洿鏂逛究鐨勬柟娉曟槸浣跨敤閫夐」鏂囦欢鏉ヤ负姣忎釜鏈嶅姟鍣ㄦ寚瀹氶偅浜涢夐」鍊硷紝瀹冨姣忎釜鏈嶅姟鍣ㄥ繀椤绘槸鍞竴鐨勩

5.12.1. 鍦╓indows涓嬭繍琛屽涓湇鍔″櫒

Windows涓紝鍙互浠庡懡浠よ鎵嬪姩鍚姩鏉ヨ繍琛屽涓湇鍔″櫒锛屾瘡涓湇鍔″櫒浣跨敤鍚堥傜殑鎿嶄綔鍙傛暟銆傚湪鍩轰簬Windows NT鐨勭郴缁熶腑锛屽畨瑁呭嚑涓湇鍔″櫒鏃讹紝浣犺繕鏈夊皢澶氫釜鏈嶅姟鍣ㄥ畨瑁呬负Windows鏈嶅姟骞惰繍琛岀殑閫夐」銆傚叧浜庝粠鍛戒护琛岃繍琛MySQL鏈嶅姟鍣ㄦ垨浣滀负鏈嶅姟杩愯鐨勪竴鑸鏄庡湪 2.3鑺傦紝鈥滃湪Windows涓婂畨瑁匨ySQL鈥涓粰鍑恒傛湰鑺傛弿杩版庢牱纭繚浣犵敤涓嶅悓鐨勫惎鍔ㄩ夐」鍊硷紙瀵逛簬姣忎釜鏈嶅姟鍣ㄥ繀椤绘槸鍞竴鐨勶紝渚嬪鏁版嵁鐩綍锛夊惎鍔ㄥ悇涓湇鍔″櫒銆傝繖浜涢夐」鐨勬弿杩拌5.12鑺傦紝鈥滃湪鍚屼竴鍙版満鍣ㄤ笂杩愯澶氫釜MySQL鏈嶅姟鍣ㄢ

5.12.1.1. 鍦ㄥ懡浠よ涓惎鍔ㄥ涓猈indows鏈嶅姟鍣

涓轰簡浠庡懡浠よ鎵嬪姩鍚姩澶氫釜鏈嶅姟鍣紝鍙互鍦ㄥ懡浠よ涓垨鍦ㄩ夐」鏂囦欢涓寚瀹氶傚綋鐨勯夐」銆傛妸閫夐」鏀惧湪閫夐」鏂囦欢涓瘮杈冩柟渚匡紝浣嗘槸闇瑕佺‘淇濇瘡涓湇鍔″櫒鍙互鑾峰緱鑷繁鐨勯夐」銆備负浜嗗疄鐜帮紝涓烘瘡涓垱寤轰竴涓夐」鏂囦欢锛屽苟涓旇繍琛屾湇鍔℃椂閫氳繃--defaults-file閫夐」鍛婅瘔鏈嶅姟鍣ㄩ夐」鏂囦欢鍚嶃

鍋囪浣犳兂瑕佸湪绔彛3307浣跨敤鏁版嵁鐩綍C:\mydata1杩愯mysqld锛屽苟涓旀兂鍦ㄧ鍙3308浣跨敤鏁版嵁鐩綍C:\mydata1杩愯mysqld-max(瑕佹兂杩欐牱鍋氾紝鍚姩鏈嶅姟鍣ㄤ箣鍓嶈纭繚锛屾瘡涓暟鎹洰褰曞瓨鍦ㄥ苟涓旀湁鑷繁鐨mysql鏁版嵁搴撴嫹璐濓紝瀹冨寘鍚 鎺堟潈琛級

鐒跺悗鍒涘缓涓や釜閫夐」鏂囦欢銆備緥濡傦紝鍒涘缓涓涓枃浠跺悕涓C:\my-opts1.cnf鐨勯厤缃枃浠讹紝瀹冪湅璧锋潵璞¤繖涓牱瀛愶細

[mysqld]
datadir = C:/mydata1
port = 3307

鍒涘缓绗簩涓枃浠跺悕涓C:\my-opts1.cnf鐨勯厤缃枃浠讹紝瀹冪湅璧锋潵璞¤繖涓牱瀛愶細

mysqld]
datadir = C:/mydata2
port = 3308

鐒跺悗锛岀敤瀹冧滑鑷繁鐨勯夐」鏂囦欢鍚姩姣忎釜鏈嶅姟鍣細

C:\> C:\mysql\bin\mysqld --defaults-file=C:\my-opts1.cnf
C:\> C:\mysql\bin\mysqld-max --defaults-file=C:\my-opts2.cnf

NT涓紝姣忎釜鏈嶅姟鍣ㄥ湪鍓嶅彴鍚姩锛堟湇鍔″櫒閫鍑哄墠锛屼笉浼氭樉绀烘柊鐨勬彁绀虹锛夛紱闇瑕佸湪涓や釜鎺у埗鍙扮獥鍙d腑鎵ц杩欎袱涓懡浠ゃ

瑕佹兂鍏抽棴鏈嶅姟鍣紝蹇呴』杩炴帴鍒扮浉搴旂殑绔彛鍙凤細

C:\> C:\mysql\bin\mysqladmin --port=3307 shutdown

C:\> C:\mysql\bin\mysqladmin --port=3308 shutdown

濡傚垰鎵嶆墍璁ㄨ鐨勶紝鏈嶅姟鍣ㄩ厤缃厑璁稿鎴风閫氳繃TCP/IP鏉ヨ繛鎺ャ傚鏋滀綘鐨Windows鐗堟湰鏀寔鍛藉悕绠¢亾骞朵笖浣犳兂鍏佽鍛藉悕绠¢亾杩炴帴锛屼娇鐢mysqld-ntmysqld-max-nt鏈嶅姟鍣ㄥ苟鎸囧畾鍚敤鍛藉悕绠¢亾骞朵笖鎸囧畾绠¢亾鍚嶇殑閫夐」銆傛敮鎸佸懡鍚嶇閬撹繛鎺ョ殑姣忎釜鏈嶅姟鍣ㄥ繀椤讳娇鐢ㄤ竴涓敮涓鐨勭閬撳悕銆備緥濡傦紝C:\my-opts1.cnf鏂囦欢鍙兘璞¤繖鏍锋潵涔﹀啓锛

[mysqld]
datadir = C:/mydata1
port = 3307
enable-named-pipe
socket = mypipe1

鐒跺悗锛岃繖鏍峰惎鍔ㄦ湇鍔″櫒锛

C:\> C:\mysql\bin\mysqld-nt --defaults-file=C:\my-opts1.cnf

鍚屾牱淇敼绗2涓湇鍔″櫒浣跨敤鐨C:\my-opts2.cnf鏂囦欢銆

5.12.1.2. 鍋氫负鏈嶅姟鍚姩澶氫釜Windows鏈嶅姟鍣

鍦ㄥ熀浜NT鐨勭郴缁熶腑锛MySQL鏈嶅姟鍣ㄥ彲浠ヤ互Windows鏈嶅姟鐨勬柟寮忔潵杩愯銆傚畨瑁呫佹帶鍒跺拰鍒犻櫎鍗曚釜MySQL鏈嶅姟鐨勮繃绋嬫弿杩拌2.3.12鑺傦紝鈥滀互Windows鏈嶅姟鏂瑰紡鍚姩MySQL鈥

浣犺繕鍙互浠ユ湇鍔$殑鏂瑰紡瀹夎澶氫釜MySQL鏈嶅姟鍣ㄣ傛鏃讹紝闄や簡鎵鏈夊弬鏁板姣忎釜鏈嶅姟鍣ㄥ繀椤绘槸鍞竴鐨勶紝浣犺繕蹇呴』纭繚姣忎釜鏈嶅姟鍣ㄤ娇鐢ㄤ笉鍚岀殑鏈嶅姟鍚嶃

鍦ㄤ笅闈㈢殑璇存槑涓紝鍋囪浣犳兂瑕佽繍琛mysqld-nt鏈嶅姟鍣ㄧ殑涓や釜涓嶅悓鐨勭増鏈紝瀹冧滑鍒嗗埆瀹夎鍦C:\mysql-4.1.8C:\mysql-5.1.2-alpha鐩綍涓(鍙兘瀛樺湪杩欑鎯呭喌锛屽鏋滀綘姝e湪杩愯鐗堟湰4.1.8浣滀负浣犵殑浜у搧鏈嶅姟鍣紝杩樻兂浣跨敤5.1.2-alpha鐗堟湰鏉ヨ繘琛屾祴璇曪級

褰撶敤--install--install-manual閫夐」瀹夎涓涓MySQL鏈嶅姟鏃讹紝搴旈伒浠庝互涓嬪師鍒欙細

         濡傛灉浣犳病鏈夋寚瀹氭湇鍔″悕锛屾湇鍔″櫒浣跨敤榛樿鐨MySQL鏈嶅姟鍚嶏紝浠庢爣鍑嗛夐」鏂囦欢鐨[mysqld]缁勪腑璇诲彇閫夐」銆

         濡傛灉浣犲湪--install閫夐」鍚庢寚瀹氫簡鏈嶅姟鍚嶏紝鏈嶅姟鍣ㄥ拷鐣[mysqld]閫夐」缁勶紝浠庡叿鏈夌浉鍚屽悕鐨勭粍涓鍙栭夐」浣滀负鏈嶅姟鍚嶃傛湇鍔″櫒浠庢爣鍑嗛夐」鏂囦欢涓鍙栭夐」銆

         濡傛灉浣犲湪鏈嶅姟鍚嶅悗闈㈡寚瀹氫竴涓--defaults-file閫夐」锛屾湇鍔″櫒蹇界暐鏍囧噯閫夐」鏂囦欢锛屽彧浠庡懡鍚嶇殑鏂囦欢鐨[mysqld]缁勮鍙栭夐」銆

閲婏細MySQL 4.0.17涔嬪墠锛屽彧鏈変娇鐢ㄩ粯璁ゆ湇鍔″悕锛MySQL瀹夎鐨勪竴涓湇鍔″櫒鎴栦娇鐢ㄦ湇鍔″悕mysqld鏄惧紡瀹夎鐨勪竴涓湇鍔″櫒浠庢爣鍑嗛夐」鏂囦欢璇[mysqld]缁勩傚埌4.0.17鏃讹紝濡傛灉鏈嶅姟鍣ㄨ鏍囧噯閫夐」鏂囦欢锛屽垯瀹冧滑鍧囪[mysqld]缁勶紝鍗充娇瀹冧滑瀹夎鏃朵娇鐢ㄤ簡鍙︿竴涓湇鍔″悕銆傝繖鏍峰厑璁镐綘涓洪夐」浣跨敤[mysqld]缁勶紝鐢ㄤ簬鎵鏈MySQL鏈嶅姟鍣紝骞跺皢鏍规嵁姣忎釜鏈嶅姟鍣ㄥ懡鍚嶇殑閫夐」缁勭敤浜庤鏈嶅姟鍣锛屽嵆浣跨敤閭d釜鏈嶅姟鍚嶅畨瑁呯殑鏈嶅姟鍣ㄣ

鏍规嵁鍓嶉潰鍙欒堪锛屼綘鍙互閫氳繃鍑犱釜鏂规硶鏉ヨ缃涓湇鍔″櫒銆備笅闈㈢殑璇存槑鎻忚堪浜嗕竴浜涚ず渚嬨傚湪灏濊瘯涔嬪墠锛屽簲纭繚浣犻鍏堝叧闂苟涓斿嵏杞戒簡鎵鏈夊凡鏈夌殑MySQL鏈嶅姟鍣ㄣ

         鏂规硶1鍦ㄤ竴涓爣鍑嗛夐」鏂囦欢涓寚瀹氭墍鏈夋湇鍔″櫒閫夐」銆傝鎯宠繖鏍峰仛锛屼负姣忎釜鏈嶅姟鍣ㄤ娇鐢ㄤ笉鍚岀殑鏈嶅姟鍚嶃傚亣璁句綘鎯充娇鐢ㄦ湇鍔″悕mysqld1杩愯4.1.8鐗堢殑mysqld-nt浣跨敤鏈嶅姟鍚mysqld2杩愯5.1.2-alpha鐗堢殑mysqld-nt銆傚湪杩欑鎯呭喌涓嬶紝浣犲彲浠ヤ负4.1.8浣跨敤[mysqld1]缁勶紝涓5.1.2-alpha浣跨敤[mysqld2]缁勩備緥濡傦紝浣犲彲浠ヨ薄杩欐牱寤虹珛 C:\my.cnf鏂囦欢锛

                # options for mysqld1 service
                [mysqld1]
                basedir = C:/mysql-4.1.8
                port = 3307
                enable-named-pipe
                socket = mypipe1
                 
                # options for mysqld2 service
                [mysqld2]
                basedir = C:/mysql-5.1.2-alpha
                port = 3308
                enable-named-pipe
                socket = mypipe2

濡備笅闈㈡墍绀哄畨瑁呮湇鍔″櫒锛屼娇鐢ㄦ湇鍔″櫒鐨勫叏璺緞鍚嶆潵纭繚Windows涓烘瘡涓湇鍔℃敞鍐屾纭殑鍙墽琛岀▼搴忥細

C:\> C:\mysql-4.1.8\bin\mysqld-nt --install mysqld1
C:\> C:\mysql-5.1.2-alpha\bin\mysqld-nt --install mysqld2

涓轰簡鍚姩鏈嶅姟鍣紝浣跨敤鏈嶅姟绠$悊鍣紝鎴栫敤甯︽湁閫傚綋鐨勬湇鍔″悕鐨NET START

C:\> NET START mysqld1

C:\> NET START mysqld2

瑕佹兂鍋滄鏈嶅姟锛屼娇鐢ㄦ湇鍔$鐞嗗櫒锛屾垨鐢ㄥ甫鏈夐傚綋鐨勬湇鍔″悕鐨NET STOP

C:\> NET STOP mysqld1
C:\> NET STOP mysqld2

         鏂规硶2涓烘瘡涓湇鍔″櫒鐢ㄤ笉鍚岀殑鏂囦欢鎸囧畾閫夐」锛屽綋浣犲畨瑁呮湇鍔℃椂浣跨敤--defaults-file鍛婅瘔姣忎釜鏈嶅姟鍣ㄤ娇鐢ㄤ粈涔堟枃浠躲傛鏃讹紝姣忎釜鏂囦欢搴旂敤涓涓[mysqld]缁勫垪鍑洪夐」銆

浣跨敤杩欑鏂规硶涓4.1.8鐗堟湰鐨mysqld-nt鎸囧畾閫夐」锛屽簲璞¤繖鏍峰垱寤轰竴涓C:\my-opts1.cnf鏂囦欢锛

[mysqld]
basedir = C:/mysql-4.1.8
port = 3307
enable-named-pipe
socket = mypipe1

瀵逛簬5.1.2-alpha鐗堢殑mysqld-nt锛岃薄杩欐牱鍒涘缓涓涓C:\my-opts2.cnf鏂囦欢锛

[mysqld]
basedir = C:/mysql-5.1.2-alpha port = 3308
enable-named-pipe
socket = mypipe2

瀹夎鏈嶅姟濡備笅锛堝湪涓涓崟涓琛屼腑杈撳叆姣忎釜鍛戒护锛夛細

C:\> C:\mysql-4.1.8\bin\mysqld-nt -- installmysqld1
           --defaults-file=C:\my-opts1.cnf
C:\> C:\mysql-5.1.2-alpha\bin\mysqld-nt -- installmysqld2
           --defaults-file=C:\my-opts2.cnf

褰撲綘浣滀负鏈嶅姟瀹夎涓涓MySQL鏈嶅姟鍣ㄦ椂锛岃鎯充娇鐢--defaults-file閫夐」锛屼綘蹇呴』鍦ㄦ閫夐」涔嬪墠鍔犳湇鍔″悕銆

瀹夎鏈嶅姟鍚庯紝鎸夌収涓庡墠闈㈢殑绀轰緥鐩稿悓鐨勬柟娉曞惎鍔ㄥ拰鍋滄銆

瑕佹兂鍗歌浇澶氫釜鏈嶅姟锛屽姣忎釜鏈嶅姟浣跨敤mysqld --remove锛屽湪--remove閫夐」鍚庢寚瀹氭湇鍔″悕銆傚鏋滄湇鍔″悕鏄 榛樿鐨(MySQL)锛屼綘鍙互涓嶆寚瀹氥

5.12.2. 鍦║nix涓繍琛屽涓湇鍔″櫒

Unix涓繍琛屽涓湇鍔″櫒鏈瀹规槗鐨勬柟娉曟槸浣跨敤涓嶅悓鐨TCP/IP绔彛sUnix濂楁帴瀛楁枃浠剁紪璇戯紝鍥犳姣忎釜瀹炰緥鍦ㄤ笉鍚岀殑缃戠粶鎺ュ彛渚﹀惉銆傚彟澶栵紝姣忎釜瀹夎搴斿湪涓嶅悓鐨勫熀纭鐩綍涓紪璇戯紝閭e皢鑷姩涓轰綘鐨勬瘡涓湇鍔″櫒浜х敓浣跨敤涓嶅悓鐨勭紪璇戣繘鏉ョ殑鏁版嵁鐩綍銆佹棩蹇楁枃浠跺拰PID鏂囦欢浣嶇疆銆

鍋囪涓涓幇鏈夌殑4.1.8鐗堟湰鏈嶅姟鍣ㄩ厤缃负榛樿TCP/IP绔彛鍙(3306)Unix濂楁帴瀛楁枃浠(/tmp/mysql.sock)銆傝鎯抽厤缃竴涓柊鐨5.1.2-alpha鐗堢殑鏈嶅姟鍣ㄦ潵浣跨敤涓嶅悓鐨勬搷浣滃弬鏁帮紝浣跨敤涓涓configure鍛戒护锛屽ぇ姒傝薄杩欐牱浣跨敤锛

shell> ./configure --with-tcp-port=port_number \
             --with-unix-socket-path=file_name \
             --prefix=/usr/local/mysql-5.1.2-alpha

杩欓噷锛port_numberfile_name蹇呴』涓嶅悓浜庨粯璁TCP/IP绔彛鍙峰拰Unix濂楁帴瀛楁枃浠惰矾寰勫悕锛屽苟涓--prefix鍊煎簲鎸囧畾涓涓笉鍚屼簬鐜版湁MySQL瀹夎鐩綍鐨勫畨瑁呯洰褰曘

濡傛灉浣犳湁涓涓MySQL鏈嶅姟鍣ㄦ渚﹀惉涓涓粰瀹氱殑绔彛鍙凤紝浣犲彲浠ヤ娇鐢ㄤ笅闈㈢殑鍛戒护鏉ユ壘鍑洪拡瀵逛竴浜涢噸瑕侀厤缃彉閲忓畠浣跨敤浜嗛偅浜涙搷浣滃弬鏁帮紝鍖呮嫭鍩虹鐩綍鍜Unix濂楁帴瀛楁枃浠跺悕锛

shell> mysqladmin --host=host_name --port=port_number variables

閫氳繃璇ュ懡浠ゆ樉绀虹殑淇℃伅锛屽綋閰嶇疆鍏跺畠鏈嶅姟鍣ㄦ椂锛屼綘鍙互鍛婅瘔鏈嶅姟鍣ㄨ閫夐」娌℃湁浣跨敤鐨勫笺

璇锋敞鎰忥紝濡傛灉浣犳寚瀹localhost浣滀负涓涓富鏈哄悕锛mysqladmin榛樿浣跨敤Unix濂楁帴瀛楁枃浠惰繛鎺ワ紝鑰屼笉鏄TCP/IP銆備粠 MySQL 4.1寮濮嬶紝閫氳繃--protocol= TCP | SOCKET | PIPE | MEMORY}閫夐」锛屼綘鍙互鏄剧ず鍦版寚瀹氳繛鎺ュ崗璁

濡傛灉鍙槸鐢ㄤ竴涓笉鍚岀殑Unix濂楁帴瀛楁枃浠跺拰TCP/IP绔彛鍙峰惎鍔紝涓嶅繀缂栬瘧鏂扮殑MySQL鏈嶅姟鍣ㄣ傝繕鍙互鍦ㄨ繍琛屾椂鎸囧畾杩欎簺鍊笺傝繖鏍峰仛鐨勪竴涓柟娉曟槸浣跨敤鍛戒护琛岄夐」锛

shell> mysqld_safe --socket=file_name --port=port_number

瑕佸惎鍔ㄧ浜屼釜鏈嶅姟鍣紝鎻愪緵涓嶅悓鐨--socket--port閫夐」鍊硷紝骞朵笖浼犻掍竴涓--datadir=path閫夐」缁mysqld_safe锛屼互渚挎湇鍔″櫒浣跨敤涓涓笉鍚岀殑鏁版嵁鐩綍銆

杈惧埌鐩镐技鏁堟灉鐨勫彟涓涓柟娉曟槸浣跨敤鐜鍙橀噺鏉ヨ缃 Unix濂楁帴瀛楁枃浠跺悕鍜TCP/IP绔彛鍙凤細

shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
shell> MYSQL_TCP_PORT=3307
shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
shell> mysql_install_db --user=mysql
shell> mysqld_safe --datadir=/path/to/datadir &

杩欐槸涓涓揩閫熷惎鍔ㄧ浜屼釜鏈嶅姟鍣ㄤ互鐢ㄤ簬娴嬭瘯鐨勬柟娉曘傝鏂规硶鐨勬渶澶уソ澶勬槸鐜鍙橀噺璁惧畾鍊奸傜敤浜庝綘浠庣浉鍚岀殑shell璋冪敤鐨勪换浣曞鎴风绋嬪簭銆傚洜鑰岋紝閭d簺瀹㈡埛绔繛鎺ヨ嚜鍔ㄦ寚鍚戠浜屼釜鏈嶅姟鍣紒

闄勫綍F锛鐜鍙橀噺鍖呮嫭浣犲彲浠ヤ娇鐢ㄧ殑褰卞搷mysqld鐨勫叾瀹冪幆澧冨彉閲忓垪琛

瀵逛簬鑷姩鏈嶅姟鍣ㄥ惎鍔紝瀵逛簬姣忎釜鏈嶅姟鍣紝鏈哄櫒寮曞鏃舵墽琛岀殑鍚姩鑴氭湰搴旀墽琛屼笅闈㈢殑鍛戒护锛屾瘡涓懡浠ょ敤涓涓浉搴旂殑閫夐」鏂囦欢璺緞锛

mysqld_safe --defaults-file=path

姣忎釜閫夐」鏂囦欢搴斿寘鍚竴涓粰瀹氭湇鍔″櫒鐗瑰畾鐨勯夐」鍊笺

Unix涓紝mysqld_multi鑴氭湰鏄惎鍔ㄥ涓湇鍔″櫒鐨勫彟涓涓柟娉曘傚弬瑙5.1.5鑺傦紝鈥渕ysqld_multi锛氱鐞嗗涓狹ySQL鏈嶅姟鍣ㄧ殑绋嬪簭鈥

5.12.3. 鍦ㄥ鏈嶅姟鍣ㄧ幆澧冧腑浣跨敤瀹㈡埛绔▼搴

褰撲綘鎯宠鐢ㄤ竴涓鎴风绋嬪簭杩炴帴涓涓MySQL鏈嶅姟鍣ㄦ椂锛岃鏈嶅姟鍣ㄤ睛鍚笉鍚岀殑缃戠粶鎺ュ彛锛岃屼笉鏄紪璇戝埌浣犵殑瀹㈡埛绔殑缃戠粶鎺ュ彛锛屼綘鍙互浣跨敤涓嬮潰鐨勬柟娉曪細

         鍚姩瀹㈡埛绔紝鐢--host=host_name --port=port_number閫氳繃TCP/IP鏉ヨ繛鎺ヤ竴涓繙绋嬫湇鍔″櫒锛岀敤--host=127.0.0.1 --port=port_number閫氳繃TCP/IP鏉ヨ繛鎺ヤ竴涓湰鍦版湇鍔″櫒锛屾垨鑰呯敤--host=localhost --socket=file_name閫氳繃涓涓Unix濂楁帴瀛楁枃浠舵垨涓涓Windows鍛藉悕绠¢亾鏉ヨ繛鎺ヤ竴涓湰鍦版湇鍔″櫒銆

         MySQL 4.1璧凤紝鍚姩瀹㈡埛绔椂鐢--protocol=tcp閫氳繃TCP/IP鏉ヨ繛鎺ワ紝鐢--protocol=socket閫氳繃涓涓Unix濂楁帴瀛楁枃浠舵潵杩炴帴锛岀敤--protocol=pipe閫氳繃涓涓懡鍚嶇閬撴潵杩炴帴锛屾垨鐢--protocol=memory閫氳繃鍏变韩鍐呭瓨鏉ヨ繛鎺ャ傚浜TCP/IP杩炴帴锛屼綘鍙兘杩橀渶瑕佹寚瀹--host--port閫夐」銆傚浜庡叾瀹冪被鍨嬬殑杩炴帴锛屼綘鍙兘闇瑕佹寚瀹氫竴涓--socket閫夐」鏉ユ寚瀹氫竴涓Unix濂楁帴瀛楁枃浠舵垨鍛藉悕绠¢亾鍚嶏紝鎴栬呬竴涓--shared-memory-base-name閫夐」鏉ユ寚瀹氬叡浜唴瀛樺悕銆傚叡浜唴瀛樿繛鎺ヤ粎鍦Windows涓敮鎸併

         Unix涓紝鍦ㄤ綘鍚姩瀹㈡埛绔箣鍓嶏紝璁剧疆MYSQL_UNIX_PORTMYSQL_TCP_PORT鐜鍙橀噺鏉ユ寚瀹Unix濂楁帴瀛楁枃浠跺拰TCP/IP绔彛鍙枫傚鏋滀綘缁忓父浣跨敤鍏蜂綋鐨勫鎺ュ瓧鏂囦欢鎴栫鍙e彿锛屼綘鍙互鍦.login鏂囦欢涓斁缃懡浠ゆ潵璁剧疆鐜鍙橀噺浠ヤ究浣犳瘡娆$櫥褰曟椂璇ュ懡浠よ捣浣滅敤銆傚弬瑙闄勫綍F锛鐜鍙橀噺

         鍦ㄤ竴涓夐」鏂囦欢鐨[client]缁勪腑鎸囧畾榛樿Unix濂楁帴瀛楁枃浠跺拰TCP/IP绔彛鍙枫備緥濡傦紝浣犲彲浠ュ湪Windows涓娇鐢C:\my.cnf鏂囦欢锛屾垨鍦Unix涓富鐩綍鍐呬娇鐢.my.cnf鏂囦欢銆傚弬瑙4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥

         C绋嬪簭涓紝鍦mysql_real_connect()璋冪敤鏃讹紝浣犲彲浠ユ寚瀹氬鎺ュ瓧鏂囦欢鎴栫鍙e彿鍙傛暟銆傞氳繃璋冪敤mysql_options()浣犺繕鍙互鏈夌▼搴忚閫夐」鏂囦欢銆傚弬瑙25.2.3鑺傦紝鈥淐 API鍑芥暟鎻忚堪鈥

         濡傛灉浣犳鍦ㄤ娇鐢Perl DBD::mysql妯″潡锛屼綘鍙互浠MySQL閫夐」鏂囦欢涓鍙栭夐」銆備緥濡傦細

                $dsn = "DBI:mysql:test;mysql_read_default_group=client;"
                        . "mysql_read_default_file=/usr/local/mysql/data/my.cnf";
                    $dbh = DBI->connect($dsn, $user, $password);

鍙傝25.4鑺傦紝鈥淢ySQL Perl API鈥

鍏跺畠绋嬪簭鎺ュ彛鍙互涓鸿閫夐」鏂囦欢鎻愪緵鐩镐技鐨勫姛鑳姐

5.13. MySQL鏌ヨ楂橀熺紦鍐

鏌ヨ缂撳瓨瀛樺偍SELECT鏌ヨ鐨勬枃鏈互鍙婂彂閫佺粰瀹㈡埛绔殑鐩稿簲缁撴灉銆傚鏋滈殢鍚庢敹鍒颁竴涓浉鍚岀殑鏌ヨ锛屾湇鍔″櫒浠庢煡璇㈢紦瀛樹腑閲嶆柊寰楀埌鏌ヨ缁撴灉锛岃屼笉鍐嶉渶瑕佽В鏋愬拰鎵ц鏌ヨ銆

濡傛灉浣犳湁涓涓笉缁忓父鏀瑰彉鐨勮〃骞朵笖鏈嶅姟鍣ㄦ敹鍒拌琛ㄧ殑澶ч噺鐩稿悓鏌ヨ锛屾煡璇㈢紦瀛樺湪杩欐牱鐨勫簲鐢ㄧ幆澧冧腑鍗佸垎鏈夌敤銆傚浜庤澶Web鏈嶅姟鍣ㄦ潵璇村瓨鍦ㄨ繖绉嶅吀鍨嬫儏鍐碉紝瀹冩牴鎹暟鎹簱鍐呭鐢熸垚澶ч噺鐨勫姩鎬侀〉闈€

閲婏細鏌ヨ缂撳瓨涓嶈繑鍥炴棫鐨勬暟鎹傚綋琛ㄦ洿鏀瑰悗锛屾煡璇㈢紦瀛樺肩殑鐩稿叧鏉$洰琚竻绌恒

閲婏細濡傛灉浣犳湁璁稿mysqld鏈嶅姟鍣ㄦ洿鏂扮浉鍚岀殑MyISAM琛紝鍦ㄨ繖绉嶆儏鍐典笅鏌ヨ缂撳瓨涓嶈捣浣滅敤銆

閲婏細鏌ヨ缂撳瓨涓嶉傜敤浜庢湇鍔″櫒鏂圭紪鍐欑殑璇彞銆傚鏋滄鍦ㄤ娇鐢ㄦ湇鍔″櫒鏂圭紪鍐欑殑璇彞锛岃鑰冭檻鍒拌繖浜涜鍙ュ皢涓嶄細搴旂敤鏌ヨ缂撳瓨銆傚弬瑙 25.2.4鑺傦紝鈥淐 API棰勫鐞嗚鍙モ

涓嬮潰鏄煡璇㈢紦瀛樼殑涓浜涙ц兘鏁版嵁銆傝繖浜涚粨鏋滄槸鍦Linux Alpha 2 x 500MHz绯荤粺锛2GB RAM64MB鏌ヨ缂撳瓨锛変笂杩愯MySQL鍩哄噯缁勪欢浜х敓鐨勩

         濡傛灉鎵ц鐨勬墍鏈夋煡璇㈡槸绠鍗曠殑(濡備粠鍙湁涓琛屾暟鎹殑琛ㄤ腑閫夊彇涓琛)锛屼絾鏌ヨ鏄笉鍚岀殑锛屾煡璇笉鑳借缂撳瓨锛屾煡璇㈢紦瀛樻縺娲荤巼鏄13%銆傝繖鍙互鐪嬩綔鏄渶鍧忕殑鎯呭舰銆傚湪瀹為檯搴旂敤涓紝鏌ヨ瑕佸鏉傚緱澶氾紝鍥犳锛屾煡璇㈢紦瀛樹娇鐢ㄧ巼涓鑸細寰堜綆銆

         浠庡彧鏈変竴琛岀殑琛ㄤ腑鏌ユ壘涓琛屾暟鎹椂锛屼娇鐢ㄦ煡璇㈢紦瀛樻瘮涓嶄娇鐢ㄩ熷害蹇238%銆傝繖鍙互鐪嬩綔鏌ヨ浣跨敤缂撳瓨鏃堕熷害鎻愰珮鏈灏忕殑鎯呭喌銆

鏈嶅姟鍣ㄥ惎鍔ㄦ椂瑕佺鐢ㄦ煡璇㈢紦瀛橈紝璁剧疆query_cache_size绯荤粺鍙橀噺涓0銆傜鐢ㄦ煡璇㈢紦瀛樹唬鐮佸悗锛娌℃湁鏄庢樉鐨勯熷害鎻愰珮銆缂栬瘧MySQL鏃讹紝閫氳繃鍦configure浣跨敤--without-query-cache閫夐」锛屽彲浠ヤ粠鏈嶅姟鍣ㄤ腑褰诲簳鍘婚櫎鏌ヨ缂撳瓨鑳藉姏銆

5.13.1. 鏌ヨ楂橀熺紦鍐插浣曞伐浣

鏈妭鎻忚堪鏌ヨ缂撳瓨鐨勫伐浣滃師鐞嗐5.13.3鑺傦紝鈥滄煡璇㈤珮閫熺紦鍐查厤缃鎻忚堪浜嗘庢牱鎺у埗鏄惁浣跨敤鏌ヨ缂撳瓨銆

鏌ヨ瑙f瀽涔嬪墠杩涜姣旇緝锛屽洜姝や笅闈㈢殑涓や釜鏌ヨ琚煡璇㈢紦瀛樿涓烘槸涓嶇浉鍚岀殑锛

SELECT * FROM tbl_name
Select * from tbl_name

鏌ヨ蹇呴』鏄畬鍏ㄧ浉鍚岀殑(閫愬瓧鑺傜浉鍚)鎵嶈兘澶熻璁や负鏄浉鍚岀殑銆傚彟澶栵紝鍚屾牱鐨勬煡璇㈠瓧绗︿覆鐢变簬鍏跺畠鍘熷洜鍙兘璁や负鏄笉鍚岀殑銆備娇鐢ㄤ笉鍚岀殑鏁版嵁搴撱佷笉鍚岀殑鍗忚鐗堟湰鎴栬呬笉鍚 榛樿瀛楃闆嗙殑鏌ヨ琚涓烘槸涓嶅悓鐨勬煡璇㈠苟涓斿垎鍒繘琛岀紦瀛樸

浠庢煡璇㈢紦瀛樹腑鎻愬彇涓涓煡璇箣鍓嶏紝MySQL妫鏌ョ敤鎴峰鎵鏈夌浉鍏虫暟鎹簱鍜岃〃鐨SELECT鏉冮檺銆濡傛灉娌℃湁鏉冮檺锛涓嶄娇鐢ㄧ紦瀛樼粨鏋溿

濡傛灉浠庢煡璇㈢紦瀛樹腑杩斿洖涓涓煡璇㈢粨鏋滐紝鏈嶅姟鍣ㄦ妸Qcache_hits鐘舵佸彉閲忕殑鍊煎姞涓锛岃屼笉鏄Com_select鍙橀噺銆傚弬瑙5.13.4鑺傦紝鈥滄煡璇㈤珮閫熺紦鍐茬姸鎬佸拰缁存姢鈥

濡傛灉涓涓〃琚洿鏀逛簡锛岄偅涔堜娇鐢ㄩ偅涓〃鐨勬墍鏈夌紦鍐叉煡璇㈠皢涓嶅啀鏈夋晥锛屽苟涓斾粠缂撳啿鍖轰腑绉诲嚭銆傝繖鍖呮嫭閭d簺鏄犲皠鍒版敼鍙樹簡鐨勮〃鐨勪娇鐢MERGE琛ㄧ殑鏌ヨ銆備竴涓〃鍙互琚澶氱被鍨嬬殑璇彞鏇存敼锛屼緥濡INSERTUPDATEDELETETRUNCATEALTER TABLEDROP TABLEDROP DATABASE

COMMIT鎵ц瀹屽悗锛岃鏇存敼鐨勪簨鍔InnoDB琛ㄤ笉鍐嶆湁鏁堛

浣跨敤InnoDB琛ㄦ椂锛屾煡璇㈢紦瀛樹篃鍦ㄤ簨鍔′腑宸ヤ綔锛屼娇鐢ㄨ琛ㄧ殑鐗堟湰鍙锋潵妫娴嬪叾鍐呭鏄惁浠嶆棫鏄綋鍓嶇殑銆

MySQL 5.1涓紝瑙嗗浘浜х敓鐨勬煡璇㈣缂撳瓨銆

SELECT SQL_CALC_FOUND_ROWS ...SELECT FOUND_ROWS() type绫诲瀷鐨勬煡璇娇鐢ㄦ煡璇㈢紦瀛樸傚嵆浣垮洜鍒涘缓鐨勮鏁颁篃琚繚瀛樺湪缂撳啿鍖哄唴锛屽墠闈㈢殑鏌ヨ浠庣紦瀛樹腑鎻愬彇锛FOUND_ROWS()涔熻繑鍥炴纭殑鍊笺

濡傛灉涓涓煡璇㈠寘鍚笅闈㈠嚱鏁颁腑鐨勪换浣曚竴涓紝瀹冧笉浼氳缂撳瓨锛

BENCHMARK()

CONNECTION_ID()

CURDATE()

CURRENT_DATE()

CURRENT_TIME()

CURRENT_TIMESTAMP()

CURTIME()

DATABASE()

甯︿竴涓弬鏁扮殑ENCRYPT()

FOUND_ROWS()

GET_LOCK()

LAST_INSERT_ID()

LOAD_FILE()

MASTER_POS_WAIT()

NOW()

RAND()

RELEASE_LOCK()

SYSDATE()

涓嶅甫鍙傛暟鐨UNIX_TIMESTAMP()

USER()

 

鍦ㄤ笅闈㈢殑杩欎簺鏉′欢涓嬶紝鏌ヨ涔熶笉浼氳缂撳瓨锛

         寮曠敤鑷畾涔夊嚱鏁(UDFs)

         寮曠敤鑷畾涔夊彉閲忋

         寮曠敤mysql绯荤粺鏁版嵁搴撲腑鐨勮〃銆

         涓嬮潰鏂瑰紡涓殑浠讳綍涓绉嶏細

SELECT ...IN SHARE MODE
SELECT ...FOR UPDATE
SELECT ...INTO OUTFILE ...
SELECT ...INTO DUMPFILE ...
SELECT * FROM ...WHERE autoincrement_col IS NULL

鏈鍚庝竴绉嶆柟寮忎笉鑳借缂撳瓨鏄洜涓哄畠琚敤浣滀负ODBC宸ヤ綔鍖烘潵鑾峰彇鏈杩戞彃鍏ョ殑ID鍊笺傚弬瑙26.1.14.1鑺傦紝鈥滃浣曞湪ODBC涓幏鍙朅UTO_INCREMENT鍒楃殑鍊

          琚綔涓虹紪鍐欏ソ鐨勮鍙ワ紝鍗充娇娌℃湁浣跨敤鍗犱綅绗︺備緥濡傦紝涓嬮潰浣跨敤鐨勬煡璇細

char *my_sql_stmt = "SELECT ab FROM table_c";
   /* ...*/
mysql_stmt_prepare(stmtmy_sql_stmtstrlen(my_sql_stmt));

涓嶈缂撳瓨銆傚弬瑙25.2.4鑺傦紝鈥淐 API棰勫鐞嗚鍙モ

         浣跨敤TEMPORARY琛ㄣ

         涓嶄娇鐢ㄤ换浣曡〃銆

         鐢ㄦ埛鏈夋煇涓〃鐨勫垪绾ф潈闄愩

5.13.2. 鏌ヨ楂橀熺紦鍐睸ELECT閫夐」

鍙互鍦SELECT璇彞涓寚瀹氭煡璇㈢紦瀛樼浉鍏抽夐」锛

          SQL_CACHE

濡傛灉query_cache_type绯荤粺鍙橀噺鐨勫兼槸ONDEMAND鏌ヨ缁撴灉琚紦瀛樸

          SQL_NO_CACHE

鏌ヨ缁撴灉涓嶈缂撳瓨銆

绀轰緥锛

SELECT SQL_CACHE id, name FROM customer;
SELECT SQL_NO_CACHE id, name FROM customer;

5.13.3. 鏌ヨ楂橀熺紦鍐查厤缃

閫氳繃have_query_cache鏈嶅姟鍣ㄧ郴缁熷彉閲忔寚绀烘煡璇㈢紦瀛樻槸鍚﹀彲鐢細

mysql> SHOW VARIABLES LIKE 'have_query_cache';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| have_query_cache | YES   |
+------------------+-------+

鍗充娇绂佺敤鏌ヨ缂撳瓨锛屽綋浣跨敤鏍囧噯 MySQL浜岃繘鍒舵椂锛岃繖涓兼绘槸YES

鍏跺畠鍑犱釜绯荤粺鍙橀噺鎺у埗鏌ヨ缂撳瓨鎿嶄綔銆傚綋鍚姩mysqld鏃讹紝杩欎簺鍙橀噺鍙互鍦ㄩ夐」鏂囦欢鎴栬呭懡浠よ涓缃傛墍鏈夋煡璇㈢紦瀛樼郴缁熷彉閲忓悕浠query_cache_ 寮澶淬傚畠浠殑璇︾粏鎻忚堪瑙5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥锛岃繕缁欏嚭浜嗛澶栫殑閰嶇疆淇℃伅銆

涓轰簡璁剧疆鏌ヨ缂撳瓨澶у皬锛岃缃query_cache_size绯荤粺鍙橀噺銆傝缃负0琛ㄧず绂佺敤鏌ヨ缂撳瓨銆 榛樿缂撳瓨澶у皬璁剧疆涓0锛涗篃灏辨槸绂佺敤鏌ヨ缂撳瓨銆

褰撹缃query_cache_size鍙橀噺涓洪潪闆跺兼椂锛屽簲璁颁綇鏌ヨ缂撳瓨鑷冲皯澶х害闇瑕40KB鏉ュ垎閰嶅叾鏁版嵁缁撴瀯銆(鍏蜂綋澶у皬鍙栧喅浜庣郴缁熺粨鏋勶級濡傛灉浣犳妸璇ュ艰缃殑澶皬锛屽皢浼氬緱鍒颁竴涓鍛婏紝濡傛湰渚嬫墍绀猴細

mysql> SET GLOBAL query_cache_size = 40000;

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

mysql> SHOW WARNINGS\G

*************************** 1. row ***************************

  Level: Warning

   Code: 1282

Message: Query cache failed to set size 39936; new query cache size is 0

 

mysql> SET GLOBAL query_cache_size = 41984;

Query OK, 0 rows affected (0.00 sec)

 

mysql> SHOW VARIABLES LIKE 'query_cache_size';

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| query_cache_size | 41984 |

+------------------+-------+

濡傛灉鏌ヨ缂撳瓨澶у皬璁剧疆涓哄ぇ浜0query_cache_type鍙橀噺褰卞搷鍏跺伐浣滄柟寮忋傝繖涓彉閲忓彲浠ヨ缃负涓嬮潰鐨勫硷細

         0OFF灏嗛樆姝㈢紦瀛樻垨鏌ヨ缂撳瓨缁撴灉銆

         1ON灏嗗厑璁哥紦瀛橈紝浠SELECT SQL_NO_CACHE寮濮嬬殑鏌ヨ璇彞闄ゅ銆

         2DEMAND锛屼粎瀵逛互SELECT SQL_CACHE寮濮嬬殑閭d簺鏌ヨ璇彞鍚敤缂撳瓨銆

璁剧疆query_cache_type鍙橀噺鐨GLOBAL鍊煎皢鍐冲畾鏇存敼鍚庢墍鏈夎繛鎺ュ鎴风鐨勭紦瀛樿涓恒傚叿浣撳鎴风鍙互閫氳繃璁剧疆query_cache_type鍙橀噺鐨勪細璇濆兼帶鍒跺畠浠湰韬繛鎺ョ殑缂撳瓨琛屼负銆備緥濡傦紝涓涓鎴峰彲浠ョ鐢ㄨ嚜宸辩殑鏌ヨ缂撳瓨锛屾柟娉曞涓嬶細

mysql> SET SESSION query_cache_type = OFF;

瑕佹帶鍒跺彲浠ヨ缂撳瓨鐨勫叿浣撴煡璇㈢粨鏋滅殑鏈澶у硷紝搴旇缃query_cache_limit鍙橀噺銆 榛樿鍊兼槸1MB

褰撲竴涓煡璇㈢粨鏋滐紙杩斿洖缁欏鎴风鐨勬暟鎹級浠庢煡璇㈢紦鍐蹭腑鎻愬彇鏈熼棿锛屽畠鍦ㄦ煡璇㈢紦瀛樹腑鎺掑簭銆傚洜姝わ紝鏁版嵁閫氬父涓嶅湪澶х殑鏁版嵁鍧椾腑澶勭悊銆傛煡璇㈢紦瀛樻牴鎹暟鎹帓搴忚姹傚垎閰嶆暟鎹潡锛屽洜姝わ紝褰撲竴涓暟鎹潡鐢ㄥ畬鍚庡垎閰嶄竴涓柊鐨勬暟鎹潡銆傚洜涓哄唴瀛樺垎閰嶆搷浣滄槸鏄傝吹鐨(璐规椂鐨)锛屾墍浠ラ氳繃query_cache_min_res_unit绯荤粺鍙橀噺缁欐煡璇㈢紦瀛樺垎閰嶆渶灏忓笺傚綋鏌ヨ鎵ц鏃讹紝鏈鏂扮殑缁撴灉鏁版嵁鍧楁牴鎹疄闄呮暟鎹ぇ灏忔潵纭畾锛屽洜姝ゅ彲浠ラ噴鏀句笉浣跨敤鐨勫唴瀛樸傛牴鎹綘鐨勬湇鍔″櫒鎵ц鏌ヨ鐨勭被鍨嬶紝浣犱細鍙戠幇璋冩暣query_cache_min_res_unit鍙橀噺鐨勫兼槸鏈夌敤鐨勶細

         query_cache_min_res_unit榛樿鍊兼槸4KB銆傝繖搴旇閫傚悎澶ч儴鍒嗘儏鍐点

         濡傛灉浣犳湁澶ч噺杩斿洖灏忕粨鏋滄暟鎹殑鏌ヨ锛岄粯璁ゆ暟鎹潡澶у皬鍙兘浼氬鑷村唴瀛樼鐗囷紝鏄剧ず涓哄ぇ閲忕┖闂插唴瀛樺潡銆傜敱浜庣己灏戝唴瀛橈紝鍐呭瓨纰庣墖浼氬己鍒舵煡璇㈢紦瀛樹粠缂撳瓨鍐呭瓨涓慨鏁达紙鍒犻櫎锛夋煡璇€傝繖鏃讹紝浣犲簲璇ュ噺灏query_cache_min_res_unit鍙橀噺鐨勫笺傜┖闂插潡鍜岀敱浜庝慨鏁磋岀Щ鍑虹殑鏌ヨ鐨勬暟閲忛氳繃Qcache_free_blocksQcache_lowmem_prunes鍙橀噺鐨勫肩粰鍑恒

          濡傛灉澶ч噺鏌ヨ杩斿洖澶х粨鏋滐紙妫鏌 Qcache_total_blocksQcache_queries_in_cache鐘舵佸彉閲忥級锛屼綘鍙互閫氳繃澧炲姞query_cache_min_res_unit鍙橀噺鐨勫兼潵鎻愰珮鎬ц兘銆備絾鏄紝娉ㄦ剰涓嶈浣垮畠鍙樺緱澶ぇ锛堝弬瑙佸墠闈㈢殑鏉$洰锛夈

5.13.4. 鏌ヨ楂橀熺紦鍐茬姸鎬佸拰缁存姢

鍙互浣跨敤涓嬮潰鐨勮鍙ユ鏌MySQL鏈嶅姟鍣ㄦ槸鍚︽彁渚涙煡璇㈢紦瀛樺姛鑳斤細

mysql> SHOW VARIABLES LIKE 'have_query_cache';

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| have_query_cache | YES   |

+------------------+-------+

鍙互浣跨敤FLUSH QUERY CACHE璇彞鏉ユ竻鐞嗘煡璇㈢紦瀛樼鐗囦互鎻愰珮鍐呭瓨浣跨敤鎬ц兘銆傝璇彞涓嶄粠缂撳瓨涓Щ鍑轰换浣曟煡璇€

RESET QUERY CACHE璇彞浠庢煡璇㈢紦瀛樹腑绉诲嚭鎵鏈夋煡璇€FLUSH TABLES璇彞涔熸墽琛屽悓鏍风殑宸ヤ綔銆

涓轰簡鐩戣鏌ヨ缂撳瓨鎬ц兘锛屼娇鐢SHOW STATUS鏌ョ湅缂撳瓨鐘舵佸彉閲忥細

mysql> SHOW STATUS LIKE 'Qcache%';
+-------------------------+--------+
|鍙橀噺鍚                   | |
+-------------------------+--------+
| Qcache_free_blocks      | 36     |
| Qcache_free_memory      | 138488 |
| Qcache_hits             | 79570  |
| Qcache_inserts          | 27087  |
| Qcache_lowmem_prunes    | 3114   |
| Qcache_not_cached       | 22989  |
| Qcache_queries_in_cache | 415    |
| Qcache_total_blocks     | 912    |
+-------------------------+--------+

杩欎簺鍙橀噺鐨勬弿杩拌5.3.4鑺傦紝鈥滄湇鍔″櫒鐘舵佸彉閲忊銆傝繖閲屾弿杩板畠浠殑涓浜涘簲鐢ㄣ

SELECT鏌ヨ鐨勬绘暟閲忕瓑浠蜂簬锛

Com_select
+ Qcache_hits
+ queries with errors found by parser

Com_select鐨勫肩瓑浠蜂簬锛

Qcache_inserts
+ Qcache_not_cached
+ queries with errors found during columns/rights check

鏌ヨ缂撳瓨浣跨敤闀垮害鍙彉鍧楋紝鍥犳Qcache_total_blocksQcache_free_blocks鍙互鏄剧ず鏌ヨ缂撳瓨鍐呭瓨纰庣墖銆傛墽琛FLUSH QUERY CACHE鍚庯紝鍙繚鐣欎竴涓┖闂插潡銆

姣忎釜缂撳瓨鏌ヨ鑷冲皯闇瑕佷袱涓潡锛堜竴涓潡鐢ㄤ簬鏌ヨ鏂囨湰锛屼竴涓垨澶氫釜鍧楃敤浜庢煡璇㈢粨鏋滐級銆傚苟涓旓紝姣忎竴涓煡璇娇鐢ㄧ殑姣忎釜琛ㄩ渶瑕佷竴涓潡銆備絾鏄紝濡傛灉涓や釜鎴栧涓煡璇娇鐢ㄧ浉鍚岀殑琛紝浠呴渶瑕佸垎閰嶄竴涓潡銆

Qcache_lowmem_prunes鐘舵佸彉閲忔彁渚涚殑淇℃伅鑳藉甯姪浣犱綘璋冩暣鏌ヨ缂撳瓨鐨勫ぇ灏忋傚畠璁$畻涓轰簡缂撳瓨鏂扮殑鏌ヨ鑰屼粠鏌ヨ缂撳啿鍖轰腑绉诲嚭鍒拌嚜鐢卞唴瀛樹腑鐨勬煡璇㈢殑鏁扮洰銆傛煡璇㈢紦鍐插尯浣跨敤鏈杩戞渶灏戜娇鐢(LRU)绛栫暐鏉ョ‘瀹氬摢浜涙煡璇粠缂撳啿鍖轰腑绉诲嚭銆傝皟鏁翠俊鎭湪5.13.3鑺傦紝鈥滄煡璇㈤珮閫熺紦鍐查厤缃涓粰鍑恒


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