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

Chapter聽8.聽Client and Utility Programs - MySQL 5.1参考手册中文版

绗8绔狅細瀹㈡埛绔拰瀹炵敤宸ュ叿绋嬪簭

鏈夎澶氫笉鍚岀殑MySQL瀹㈡埛绔▼搴忓彲浠ヨ繛鎺ユ湇鍔″櫒浠ヨ闂暟鎹簱鎴栨墽琛岀鐞嗕换鍔°備篃鍙互浣跨敤鍏跺畠宸ュ叿銆傝繖浜涚▼搴忎笉涓庢湇鍔″櫒杩涜閫氳浣嗗彲浠ユ墽琛MySQL鐩稿叧鐨勬搷浣溿

鏈珷绠杩颁簡杩欎簺绋嬪簭鐒跺悗璇︾粏鎻忚堪浜嗘瘡涓▼搴忋傛弿杩颁簡濡備綍璋冪敤杩欎簺绋嬪簭鍜屽畠浠悊瑙g殑閫夐」銆傝皟鐢ㄧ▼搴忓拰鎸囧畾绋嬪簭閫夐」鐨勬讳俊鎭弬瑙绗4绔狅細MySQL绋嬪簭姒傝堪

8.1. 瀹㈡埛绔剼鏈拰瀹炵敤宸ュ叿姒傝堪

涓嬮潰绠鍗曞垪鍑轰簡MySQL瀹㈡埛绔▼搴忓拰瀹炵敤宸ュ叿锛

         myisampack

鍘嬬缉MyISAM琛ㄤ互浜х敓鏇村皬鐨勫彧璇昏〃鐨勪竴涓伐鍏枫傚弬瑙8.2鑺傦紝鈥渕yisampack锛氱敓鎴愬帇缂┿佸彧璇籑yISAM琛ㄢ

         mysql

浜や簰寮忚緭鍏SQL璇彞鎴栦粠鏂囦欢浠ユ壒澶勭悊妯″紡鎵ц瀹冧滑鐨勫懡浠よ宸ュ叿銆傚弬瑙8.3鑺傦紝鈥渕ysql锛歁ySQL鍛戒护琛屽伐鍏封

         mysqlaccess

妫鏌ヨ闂富鏈哄悕銆佺敤鎴峰悕鍜屾暟鎹簱缁勫悎鐨勬潈闄愮殑鑴氭湰銆

         mysqladmin

鎵ц绠$悊鎿嶄綔鐨勫鎴风▼搴忥紝渚嬪鍒涘缓鎴栧垹闄ゆ暟鎹簱锛岄噸杞芥巿鏉冭〃锛屽皢琛ㄥ埛鏂板埌纭洏涓婏紝浠ュ強閲嶆柊鎵撳紑鏃ュ織鏂囦欢銆mysqladmin杩樺彲浠ョ敤鏉ユ绱㈢増鏈佽繘绋嬶紝浠ュ強鏈嶅姟鍣ㄧ殑鐘舵佷俊鎭傚弬瑙8.5鑺傦紝鈥渕ysqladmin锛氱敤浜庣鐞哅ySQL鏈嶅姟鍣ㄧ殑瀹㈡埛绔

         mysqlbinlog

浠庝簩杩涘埗鏃ュ織璇诲彇璇彞鐨勫伐鍏枫傚湪浜岃繘鍒舵棩蹇楁枃浠朵腑鍖呭惈鐨勬墽琛岃繃鐨勮鍙ョ殑鏃ュ織鍙敤鏉ュ府鍔╀粠宕╂簝涓仮澶嶃傚弬瑙8.6鑺傦紝鈥渕ysqlbinlog锛氱敤浜庡鐞嗕簩杩涘埗鏃ュ織鏂囦欢鐨勫疄鐢ㄥ伐鍏封

         mysqlcheck

妫鏌ャ佷慨澶嶃佸垎鏋愪互鍙婁紭鍖栬〃鐨勮〃缁存姢瀹㈡埛绋嬪簭銆傚弬瑙8.7鑺傦紝鈥渕ysqlcheck锛氳〃缁存姢鍜岀淮淇▼搴忊

         mysqldump

MySQL鏁版嵁搴撹浆鍌ㄥ埌涓涓枃浠讹紙渚嬪SQL璇彞鎴tab鍒嗛殧绗︽枃鏈枃浠讹級鐨勫鎴风▼搴忋傚寮虹増鍏嶈垂杞欢棣栧厛鐢Igor Romanenko鎻愪緵銆傚弬瑙8.8鑺傦紝鈥渕ysqldump锛氭暟鎹簱澶囦唤绋嬪簭鈥

         mysqlhotcopy

褰撴湇鍔″櫒鍦ㄨ繍琛屾椂锛屽揩閫熷浠MyISAMISAM琛ㄧ殑宸ュ叿銆傚弬瑙8.9鑺傦紝鈥渕ysqlhotcopy锛氭暟鎹簱澶囦唤绋嬪簭鈥

         mysql import

浣跨敤LOAD DATA INFILE灏嗘枃鏈枃浠跺鍏ョ浉鍏宠〃鐨勫鎴风▼搴忋傚弬瑙8.10鑺傦紝鈥渕ysqlimport锛氭暟鎹鍏ョ▼搴忊

         mysqlshow

鏄剧ず鏁版嵁搴撱佽〃銆佸垪浠ュ強绱㈠紩鐩稿叧淇℃伅鐨勫鎴风▼搴忋傚弬瑙8.11鑺傦紝鈥渕ysqlshow锛氭樉绀烘暟鎹簱銆佽〃鍜屽垪淇℃伅鈥

         perror

鏄剧ず绯荤粺鎴MySQL閿欒浠g爜鍚箟鐨勫伐鍏枫傚弬瑙8.13鑺傦紝鈥減error锛氳В閲婇敊璇唬鐮佲

         replace

鏇存敼鏂囦欢涓垨鏍囧噯杈撳叆涓殑瀛楃涓茬殑瀹炵敤宸ュ叿銆傚弬瑙8.14鑺傦紝鈥渞eplace锛氬瓧绗︿覆鏇挎崲瀹炵敤宸ュ叿鈥

MySQL AB杩樻彁渚涗簡澶ч噺GUI宸ュ叿鐢ㄤ簬绠$悊鍜MySQL鏈嶅姟鍣ㄧ殑鍏跺畠宸ヤ綔銆傜浉鍏冲熀鏈俊鎭弬瑙绗4绔狅細MySQL绋嬪簭姒傝堪

姣忎釜MySQL绋嬪簭鏈夎澶氫笉鍚岀殑閫夐」銆備絾姣忎釜MySQL绋嬪簭鍧囨彁渚涗竴涓---help閫夐」锛屽彲浠ョ敤鏉ュ叏闈㈡弿杩扮▼搴忎笉鍚岀殑閫夐」銆備緥濡傦紝鍙互璇曡瘯mysql---help

浣跨敤mysqlclient搴撳悓鏈嶅姟鍣ㄨ繘琛岄氳鐨MySQL瀹㈡埛浣跨敤涓嬮潰鐨勭幆澧冨彉閲忥細

MYSQL_UNIX_PORT

榛樿Unix濂楁帴瀛楁枃浠讹紱鐢ㄤ簬杩炴帴localhost

MYSQL_TCP_PORT

榛樿绔彛鍙凤紱鐢ㄤ簬TCP/IP杩炴帴

MYSQL_PWD

榛樿瀵嗙爜

MYSQL_DEBUG

璋冭瘯杩囩▼涓殑璋冭瘯璺熻釜閫夐」

TMPDIR

鍒涘缓涓存椂琛ㄥ拰鏂囦欢鐨勭洰褰

浣跨敤MYSQL_PWD涓嶅畨鍏ㄣ傚弬瑙5.8.6鑺傦紝鈥滀娇浣犵殑瀵嗙爜瀹夊叏鈥

鍙互鍦ㄩ夐」鏂囦欢涓垨鍦ㄥ懡浠よ涓寚瀹氶夐」鏉ユ浛鎹㈡墍鏈夋爣鍑嗙▼搴忕殑榛樿閫夐」鍊兼垨鎸囧畾鐨勭幆澧冨彉閲忕殑鍊笺傚弬瑙4.3鑺傦紝鈥滄寚瀹氱▼搴忛夐」鈥

8.2. myisampack锛氱敓鎴愬帇缂┿佸彧璇籑yISAM琛

myisampack宸ュ叿鍙互鍘嬬缉MyISAM.MYIsampack鍒嗗埆鍘嬬缉琛ㄤ腑鐨勬瘡涓鍒椼傞氬父锛myisampack鍙互灏嗘暟鎹枃浠跺帇缂╁埌40%-70%

褰撲互鍚庝娇鐢ㄨ〃鏃讹紝瑙e帇缂╁垪闇瑕佺殑淇℃伅琚鍏ュ唴瀛樸傚綋璁块棶鍏蜂綋鐨勮褰曟椂鎬ц兘浼氭洿濂斤紝鍥犱负浣犲彧闇瑕佽В鍘嬬缉涓涓褰曘

MySQL浣跨敤mmap()瀵瑰帇缂╃殑琛ㄨ繘琛屽唴瀛樻槧灏勩傚鏋mmap()涓嶅伐浣滐紝MySQL杩斿洖鍒版櫘閫氳/鍐欐枃浠舵搷浣溿

璇锋敞鎰忥細

         濡傛灉鐢--skip-external-locking閫夐」璋冪敤mysqld鏈嶅姟鍣紝濡傛灉鍦ㄥ帇缂╄繃绋嬩腑琛ㄥ彲鑳借鏇存柊锛岃皟鐢myisampack涓嶆槸涓涓ソ娉ㄦ剰銆

         琛ㄥ帇缂╁悗锛屽畠鍙樹负鍙銆傝繖鏄晠鎰忕殑(渚嬪褰撹闂CD涓婄殑鍘嬬缉鐨勮〃鏃)銆傚厑璁稿啓鍏ュ埌鍘嬬缉鐨勮〃浣嶄簬鎴戜滑鐨TODO鍒楄〃涓紝浣嗕紭鍏堢骇杈冧綆銆

         myisampack鍙互鍘嬬缉BLOBTEXT鍒椼傛棫鐗堟湰ISAM琛ㄧ殑pack_isam绋嬪簭涓嶅彲浠ャ

璋冪敤myisampack鐨勬柟娉曪細

shell> myisampack [options] filename ...

鏂囦欢鍚嶅簲涓虹储寮(.MYI)鏂囦欢鐨勬枃浠跺悕銆傚鏋滀笉鍦ㄦ暟鎹簱鐩綍锛屽簲鎸囧畾鏂囦欢鐨勮矾寰勫悕銆傚厑璁稿拷鐣.MYI鎵╁睍鍚嶃

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

         --help-

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

         --backup-b

浣跨敤tbl_name.OLD鍚嶅浠借〃鏁版嵁鏂囦欢銆

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父涓'd:t:o,file_name'

         --force-f

浜х敓涓涓帇缂╃殑琛紝鍗充娇瀹冩瘮鍘熷琛ㄥぇ锛屾垨濡傛灉浠ュ墠璋冪敤myisampack鐨勪腑闂存枃浠跺瓨鍦ㄣ(myisampack鍘嬬缉琛ㄦ椂鍦ㄦ暟鎹簱鐩綍涓垱寤轰竴涓悕涓tbl_name.TMD鐨勪腑闂存枃浠躲傚鏋滄潃鎺myisampack.TMD鏂囦欢浼氳鍒犻櫎锛閫氬父鎯呭喌锛屽鏋myisampack鍙戠幇tbl_name.TMD瀛樺湪鍒欓鍑哄苟鎻愮ず閿欒銆傜敤--forcemyisampack鍒欎竴瀹氬帇缂╄〃銆

         -join=big_tbl_name-j big_tbl_name

灏嗗懡浠よ涓殑鎵鏈夎〃鑱旀帴涓轰竴涓〃big_tbl_name銆傚皢瑕佽繛鎺ョ殑鎵鏈夎〃蹇呴』鏈夌浉绛夌殑缁撴瀯(鐩稿悓鐨勫垪鍚嶅拰绫诲瀷锛岀浉鍚岀殑绱㈠紩绛夌瓑)

         --pack length=len-p len

鎸囧畾璁板綍闀垮害瀛樺偍澶у皬锛屼互瀛楄妭璁°傚煎簲涓12鎴栬3myisampack淇濆瓨鎵鏈夐暱搴︽寚閽堜负12鎴栬3瀛楄妭鐨勮銆傚湪澶у鏁版甯告儏鍐典笅锛myisampack鍦ㄥ紑濮嬪帇缂╂枃浠跺墠鍙互纭畾鍑嗙‘鐨勯暱搴﹀硷紝浣嗗湪鍘嬬缉杩囩▼涓畠鍙互鎻愮ず瀹冨彲鑳藉凡缁忎娇鐢ㄤ簡涓涓煭鐨勯暱搴︺傚湪杩欑鎯呭喌涓嬶紝myisampack杈撳嚭涓鏉℃彁绀猴紝涓嬫浣犲帇缂╁悓涓鏂囦欢鏃讹紝浣犲彲浠ヤ娇鐢ㄦ洿鐭殑璁板綍闀垮害銆

         --silent-s

娌夐粯妯″紡銆傚彧鏈夊彂鐢熼敊璇椂鎵嶅啓杈撳嚭銆

         --test-t

娌℃湁瀹為檯鍦板帇缂╄〃锛屽彧鏄祴璇曞帇缂┿

         --tmpdir=path-T path

浣跨敤myisamchk鍒涘缓涓存椂鏂囦欢鐨勭洰褰曘

         --verbose-v

鍐楅暱妯″紡銆傚啓鍘嬬缉鎿嶄綔杩囩▼鐩稿叧淇℃伅鍜屽叾缁撴灉銆

         --version-V

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

         --wait-w

濡傛灉琛ㄦ浣跨敤鍒欑瓑寰呭苟閲嶈瘯銆傚鏋滅敤--skip-external-locking閫夐」璋冪敤浜mysqld鏈嶅姟鍣紝濡傛灉鍦ㄥ帇缂╄繃绋嬩腑琛ㄥ彲鑳借鏇存柊锛岃皟鐢myisampack涓嶆槸涓涓ソ娉ㄦ剰銆

涓嬮潰鐨勯『搴忓懡浠よ鏄庝簡鍏稿瀷鐨勮〃鍘嬬缉浼氳瘽锛

shell> ls -l station.*
-rw-rw-r--   1 monty    my         994128 Apr 17 19:00 station.MYD
-rw-rw-r--   1 monty    my          53248 Apr 17 19:00 station.MYI
-rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
 
shell> myisamchk -dvv station
 
MyISAM file:     station
Isam-version:  2
Creation time: 1996-03-13 10:08:58
Recover time:  1997-02-02  3:06:43
Data records:              1192  Deleted blocks:              0
Datafile parts:            1192  Deleted data:                0
Datafile pointer (bytes):     2  Keyfile pointer (bytes):     2
Max datafile length:   54657023  Max keyfile length:   33554431
Recordlength:               834
Record format: Fixed length
 
table description:
Key Start Len Index   Type                 Root  Blocksize    Rec/key
1   2     4   unique  unsigned long        1024       1024          1
2   32    30  multip. text                10240       1024          1
 
Field Start Length Type
1     1     1
2     2     4
3     6     4
4     10    1
5     11    20
6     31    1
7     32    30
8     62    35
9     97    35
10    132   35
11    167   4
12    171   16
13    187   35
14    222   4
15    226   16
16    242   20
17    262   20
18    282   20
19    302   30
20    332   4
21    336   4
22    340   1
23    341   8
24    349   8
25    357   8
26    365   2
27    367   2
28    369   4
29    373   4
30    377   1
31    378   2
32    380   8
33    388   4
34    392   4
35    396   4
36    400   4
37    404   1
38    405   4
39    409   4
40    413   4
41    417   4
42    421   4
43    425   4
44    429   20
45    449   30
46    479   1
47    480   1
48    481   79
49    560   79
50    639   79
51    718   79
52    797   8
53    805   1
54    806   1
55    807   20
56    827   4
57    831   4
 
shell> myisampack station.MYI
Compressing station.MYI: (1192 records)
- Calculating statistics
 
normal:     20  empty-space:   16  empty-zero:     12  empty-fill:  11
pre-space:   0  end-space:     12  table-lookups:   5  zero:         7
Original trees:  57  After join: 17
- Compressing file
87.14%
Remember to run myisamchk -rq on compressed tables
 
shell> ls -l station.*
-rw-rw-r--   1 monty    my         127874 Apr 17 19:00 station.MYD
-rw-rw-r--   1 monty    my          55296 Apr 17 19:04 station.MYI
-rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
 
shell> myisamchk -dvv station
 
MyISAM file:     station
Isam-version:  2
Creation time: 1996-03-13 10:08:58
Recover time:  1997-04-17 19:04:26
Data records:               1192  Deleted blocks:              0
Datafile parts:             1192  Deleted data:                0
Datafile pointer (bytes):      3  Keyfile pointer (bytes):     1
Max datafile length:    16777215  Max keyfile length:     131071
Recordlength:                834
Record format: Compressed
 
table description:
Key Start Len Index   Type                 Root  Blocksize    Rec/key
1   2     4   unique  unsigned long       10240       1024          1
2   32    30  multip. text                54272       1024          1
 
Field Start Length Type                         Huff tree  Bits
1     1     1      constant                             1     0
2     2     4      zerofill(1)                          2     9
3     6     4      no zeros, zerofill(1)                2     9
4     10    1                                           3     9
5     11    20     table-lookup                         4     0
6     31    1                                           3     9
7     32    30     no endspace, not_always              5     9
8     62    35     no endspace, not_always, no empty    6     9
9     97    35     no empty                             7     9
10    132   35     no endspace, not_always, no empty    6     9
11    167   4      zerofill(1)                          2     9
12    171   16     no endspace, not_always, no empty    5     9
13    187   35     no endspace, not_always, no empty    6     9
14    222   4      zerofill(1)                          2     9
15    226   16     no endspace, not_always, no empty    5     9
16    242   20     no endspace, not_always              8     9
17    262   20     no endspace, no empty                8     9
18    282   20     no endspace, no empty                5     9
19    302   30     no endspace, no empty                6     9
20    332   4      always zero                          2     9
21    336   4      always zero                          2     9
22    340   1                                           3     9
23    341   8      table-lookup                         9     0
24    349   8      table-lookup                        10     0
25    357   8      always zero                          2     9
26    365   2                                           2     9
27    367   2      no zeros, zerofill(1)                2     9
28    369   4      no zeros, zerofill(1)                2     9
29    373   4      table-lookup                        11     0
30    377   1                                           3     9
31    378   2      no zeros, zerofill(1)                2     9
32    380   8      no zeros                             2     9
33    388   4      always zero                          2     9
34    392   4      table-lookup                        12     0
35    396   4      no zeros, zerofill(1)               13     9
36    400   4      no zeros, zerofill(1)                2     9
37    404   1                                           2     9
38    405   4      no zeros                             2     9
39    409   4      always zero                          2     9
40    413   4      no zeros                             2     9
41    417   4      always zero                          2     9
42    421   4      no zeros                             2     9
43    425   4      always zero                          2     9
44    429   20     no empty                             3     9
45    449   30     no empty                             3     9
46    479   1                                          14     4
47    480   1                                          14     4
48    481   79     no endspace, no empty               15     9
49    560   79     no empty                             2     9
50    639   79     no empty                             2     9
51    718   79     no endspace                         16     9
52    797   8      no empty                             2     9
53    805   1                                          17     1
54    806   1                                           3     9
55    807   20     no empty                             3     9
56    827   4      no zeros, zerofill(2)                2     9
57    831   4      no zeros, zerofill(1)                2     9

myisampack鏄剧ず涓嬮潰鐨勫悇绉嶄俊鎭細

         normal

涓嶉渶瑕佽繘琛岄澶栧帇缂╃殑鍒楃殑鏁伴噺銆

         empty-space

鍙寘鍚┖鏍肩殑鍒楃殑鏁伴噺锛涘崰涓涓瘮鐗广

         empty-zero

鍙寘鍚簩杩涘埗闆剁殑鍒楃殑鏁伴噺锛涘崰涓涓瘮鐗广

         empty-fill

涓嶅崰璇ョ被鍏ㄥ瓧鑺傝寖鍥寸殑鏁存暟鍒楃殑鏁伴噺锛涜繖浜涘垪琚敼涓鸿緝灏忕殑绫诲瀷銆備緥濡傦紝濡傛灉鎵鏈夊肩殑鑼冨洿涓轰粠-128127BIGINT(8涓瓧鑺)鍙互淇濆瓨涓TINYINT(1涓瓧鑺)

         pre-space

鐢ㄥ紩瀵肩┖鏍间繚瀛樼殑鍗佽繘鍒跺垪鐨勬暟閲忋傚湪杩欑鎯呭喌涓嬶紝姣忎釜鍊煎寘鍚竴涓紩瀵肩┖鏍肩殑鏁伴噺璁℃暟銆

         end-space

鏈夊ぇ閲忕粨灏剧┖鏍肩殑鍒楃殑鏁伴噺銆傚湪杩欑鎯呭喌涓嬶紝姣忎釜鍊煎寘鍚竴涓粨灏剧┖鏍肩殑鏁伴噺璁℃暟銆

         table-lookup

璇ュ垪鍙湁灏戦噺鐨勪笉鍚岀殑鍊硷紝鍦ㄨ繘琛屽搱澶浖鍘嬬缉鍓嶈杞崲涓轰竴涓ENUM

         zero

鎵鏈夊间负闆剁殑鍒楃殑鏁伴噺銆

         Original trees

鍝堝か鏇兼爲鐨勬渶鍒濇暟閲忋

         After join

鑱旀帴鏍戜互鑺傜渷涓浜涘ご绌洪棿涔嬪悗鐣欎笅鐨勫搱澶浖鏍戠殑鏁伴噺銆

琛ㄨ鍘嬬缉鍚庯紝myisamchk -dvv涓烘瘡鍒楄緭鍑鸿缁嗕俊鎭細

         Type

鍒楃殑绫诲瀷銆傝鍊煎彲浠ュ寘鍚笅闈㈢殑浠讳綍鎻忚堪绗︼細

o        constant

鎵鏈夎鍏锋湁鐩稿悓鐨勫笺

o        no endspace

涓嶄繚瀛樼粨灏剧┖鏍笺

o        no endspacenot_always

涓嶄繚瀛樼粨灏剧┖鏍煎苟涓斿浜庢墍鏈夌殑鍊间笉鍘嬬缉缁撳熬绌烘牸銆

o        no endspaceno empty

涓嶄繚瀛樼粨灏剧┖鏍笺備笉淇濆瓨绌哄笺

o        table-lookup

鍒楄杞崲涓轰竴涓ENUM

o        zerofill(n)

鍊间腑鏈鏈夋剰涔夌殑n瀛楄妭鎬讳负0锛屽苟涓斾笉淇濆瓨銆

o        no zeros

涓嶄繚瀛橀浂銆

o        always zeros

鐢ㄤ竴涓綅淇濆瓨闆跺笺

         Huff tree

鍒楃浉鍏崇殑鍝堝か鏇兼爲鐨勬暟閲忋

         Bits

鍝堝か鏇兼爲浣跨敤鐨勪綅鏁般

杩愯myisampack鍚庯紝蹇呴』杩愯myisamchk浠ラ噸鏂板垱寤虹储寮曘傛鏃讹紝浣犱篃鍙互鎺掑簭绱㈠紩鍧楀苟鍒涘缓MySQL浼樺寲鍣ㄩ渶瑕佺殑缁熻淇℃伅浠ユ洿鏈夋晥鍦板伐浣滐細

shell> myisamchk -rq --sort-index --analyze tbl_name.MYI

灏嗗帇缂╃殑琛ㄥ畨瑁呭埌MySQL鏁版嵁搴撶洰褰曚腑鍚庯紝搴旀墽琛mysqladmin flush-tables浠ュ己鍒mysqld浣跨敤鏂扮殑琛ㄣ

瑕佹兂瑙e帇缂╀竴涓帇缂╃殑琛紝浣跨敤myisamchkisamchk--unpack閫夐」銆

8.3. mysql锛歁ySQL鍛戒护琛屽伐鍏

mysql鏄竴涓畝鍗曠殑SQL澶栧3(GNU readline鍔熻兘)銆傚畠鏀寔浜や簰寮忓拰闈炰氦浜掑紡浣跨敤銆傚綋浜や簰浣跨敤鏃讹紝鏌ヨ缁撴灉閲囩敤ASCII琛ㄦ牸寮忋傚綋閲囩敤闈炰氦浜掑紡(渚嬪锛岀敤浣滆繃婊ゅ櫒)妯″紡鏃讹紝缁撴灉涓tab鍒嗗壊绗︽牸寮忋傚彲浠ヤ娇鐢ㄥ懡浠よ閫夐」鏇存敼杈撳嚭鏍煎紡銆

濡傛灉鐢变簬缁撴灉杈冨ぇ鑰屽唴瀛樹笉瓒抽亣鍒伴棶棰橈紝浣跨敤--quick閫夐」銆傝繖鏍峰彲浠ュ己鍒mysql浠庢湇鍔″櫒姣忔涓琛屾悳绱㈢粨鏋滐紝鑰屼笉鏄绱㈡暣涓粨鏋滈泦骞跺湪鏄剧ず涔嬪墠涓嶅緱涓嶅皢瀹冧繚瀛樺埌鍐呭瓨涓備娇鐢mysql_use_result()鑰屼笉鏄mysql_store_result()鏉ユ悳绱㈢粨鏋滈泦銆

浣跨敤mysql寰堢畝鍗曘備粠鍛戒护瑙i噴绗︽彁绀烘潵璋冪敤瀹冿細

shell> mysql db_name

鎴栵細

shell> mysql --user=user_name --password=your_password db_name

杩欐牱杈撳叆涓涓SQL璇彞锛岀敤鈥鈥欍\g鎴栬\G缁撳熬骞舵寜鍥炶溅閿

浣犲彲浠ヨ繖鏍疯繍琛屼竴涓剼鏈細

shell> mysql db_name < script.sql > output.tab

8.3.1. 閫夐」

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

         ---help-

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

         --batch-B

鎵撳嵃缁撴灉锛屼娇鐢tab浣滀负鍒楅棿闅旂锛屾瘡涓鍗犵敤鏂扮殑涓琛屻備娇鐢ㄨ閫夐」锛屽垯mysql涓嶄娇鐢ㄥ巻鍙叉枃浠躲

         --character-sets -dir=path

瀛楃闆嗙殑瀹夎鐩綍銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --compress-C

鍘嬬缉鍦ㄥ鎴风鍜屾湇鍔″櫒涔嬮棿鍙戦佺殑鎵鏈変俊鎭紙濡傛灉浜岃呭潎鏀寔鍘嬬缉锛夈

         ---database=db_name-D db_name

瑕佷娇鐢ㄧ殑鏁版嵁搴撱備富瑕佸湪閫夐」鏂囦欢涓湁鐢ㄣ

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父涓'd:t:o,file_name'銆 榛樿涓'd:t:o,/tmp/mysql.trace'

         ---debug-info-T

褰撶▼搴忛鍑烘椂杈撳嚭閮ㄥ垎璋冭瘯淇℃伅銆

         --default-character-set=charset

浣跨敤charsetas浣滀负榛樿瀛楃闆嗐傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --execute=statement, -e statement

鎵ц璇彞骞堕鍑恒傞粯璁よ緭鍑烘牸寮忎笌鐢--batch浜х敓鐨勭浉鍚屻4.3.1鑺傦紝鈥滃湪鍛戒护琛屼笂浣跨敤閫夐」鈥涓彁渚涗簡涓浜涗緥瀛愩

         --force-f

鍗充娇鍑虹幇涓涓SQL閿欒浠嶇户缁

         --host=host_name-h host_name

杩炴帴缁欏畾涓绘満涓婄殑MySQL鏈嶅姟鍣ㄣ

         --html-H

浜х敓HTML杈撳嚭銆

         --ignore-space-i

蹇借鍑芥暟鍚嶅悗闈㈢殑绌烘牸銆傚叾缁撴灉鎻忚堪鍙傝5.3.2鑺傦紝鈥淪QL鏈嶅姟鍣ㄦā寮忊涓殑IGNORE_SPACE鐨勮璁恒

         --local-infile[={0|1}]

LOAD DATA INFILE鍚敤鎴栫鐢LOCAL鍔熻兘銆傛病鏈夊硷紝璇ラ夐」鍚敤LOCAL銆傝繕鍙互閲囩敤--local-infile=0--local-infile=1浠ユ樉寮忕鐢ㄦ垨鍚敤LOCAL銆傚鏋滄湇鍔″櫒涓嶆敮鎸侊紝鍚敤LOCAL涓嶄細鐢熸晥銆

         --named-commands-G

鍛藉悕鐨勫懡浠よ鍚敤銆傚厑璁搁暱鏍煎紡鍛戒护鍜岀煭鏍煎紡\*鍛戒护銆備緥濡傦紝quit\q鍧囪璇嗗埆銆

         --no-auto-rehash-A

涓嶈嚜鍔ㄩ噸鏂拌繘琛屽搱甯岃繍绠椼傝閫夐」浣mysql鍚姩寰楁洿蹇紝浣嗘灉浣犳兂瑕佸畬鎴愯〃鍜屽垪鍚嶏紝浣犲繀椤诲彂鍑rehash鍛戒护銆

         --no-beep-b

褰撳彂鐢熼敊璇椂涓嶈淇濇寔銆

         --no-named-commands-g

鍛藉悕鐨勫懡浠よ绂佺敤銆傚彧浣跨敤\*褰㈠紡锛屾垨鑰呭彧浣跨敤琛屽紑澶寸殑鍛藉悕鐢ㄥ垎鍙()缁撴潫鐨勭殑鍛戒护銆傚浜MySQL 3.23.22锛岄粯璁ゆ儏鍐mysql鍚姩鏃跺惎鐢ㄨ閫夐」銆傜劧鑰岋紝鍗充娇浣跨敤璇ラ夐」锛岄暱鏍煎紡鍛戒护浠嶇劧浠庣1琛屽伐浣溿

         --no-pager

涓嶄娇鐢ㄥ垎椤靛櫒鏉ユ樉绀烘煡璇㈣緭鍑恒傚湪8.3.2鑺傦紝鈥mysql鍛戒护鈥涓缁嗚璁轰簡杈撳嚭鍒嗛〉銆

         --no-tee

涓嶅皢杈撳嚭澶嶅埗鍒版枃浠朵腑銆傚湪8.3.2鑺傦紝鈥mysql鍛戒护鈥涓缁嗚璁轰簡Tee鏂囦欢銆

         --one--database-O

蹇借闄や簡涓哄懡浠よ涓懡鍚嶇殑榛樿鏁版嵁搴撶殑璇彞銆傚彲浠ュ府鍔╄烦杩囧浜岃繘鍒舵棩蹇椾腑鐨勫叾瀹冩暟鎹簱鐨勬洿鏂般

         --pager[=command]

浣跨敤缁欏嚭鐨勫懡浠ゆ潵鍒嗛〉鏌ヨ杈撳嚭銆傚鏋滆鍛戒护琚垹闄わ紝榛樿鍒嗛〉鍣ㄤ负PAGER鐜鍙橀噺鐨勫笺傚悎娉pagerslessmorecat [>filename]绛夌瓑銆傝閫夐」鍙湪Unix涓伐浣溿備笉鑳戒互鎵瑰鐞嗘ā寮忓伐浣溿傚湪8.3.2鑺傦紝鈥mysql鍛戒护鈥涓缁嗚璁轰簡杈撳嚭鍒嗛〉銆

         --password[=password]-p[password]

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑瀵嗙爜銆傚鏋滀娇鐢ㄧ煭閫夐」褰㈠紡(-p)锛岄夐」鍜 瀵嗙爜涔嬮棿涓嶈兘鏈夌┖鏍笺傚鏋滃湪鍛戒护琛屼腑--password-p閫夐」鍚庨潰娌℃湁 瀵嗙爜鍊硷紝鍒欐彁绀鸿緭鍏ヤ竴涓瘑鐮併傚湪SysV-based UNIX绯荤粺涓簲鐪佺暐瀵嗙爜锛屽洜涓哄瘑鐮佸彲浠ユ樉绀哄湪ps鐨勮緭鍑轰腑銆

         --port=port_num-P port_num

鐢ㄤ簬杩炴帴鐨TCP/IP绔彛鍙枫

         --prompt=format_str

灏嗘彁绀鸿缃负鎸囧畾鐨勬牸寮忋傞粯璁や负mysql>銆傚湪8.3.2鑺傦紝鈥mysql鍛戒护鈥涓弿杩颁簡鎻愮ず涓彲浠ュ寘鍚殑鍏蜂綋椤哄簭銆

         --protocol={TCP | SOCKET | PIPE | MEMORY}

浣跨敤鐨勮繛鎺ュ崗璁

         --quick-q

涓嶇紦瀛樻瘡涓煡璇㈢殑缁撴灉锛屾寜鐓ф帴鏀堕『搴忔墦鍗版瘡涓琛屻傚鏋滆緭鍑鸿鎸傝捣锛屾湇鍔″櫒浼氭參涓嬫潵銆備娇鐢ㄨ閫夐」锛mysql涓嶄娇鐢ㄥ巻鍙叉枃浠躲

         --raw-r

鍐欏垪鐨勫艰屼笉杞箟杞崲銆傞氬父缁撳悎--batch閫夐」浣跨敤銆

         --reconnect

濡傛灉涓庢湇鍔″櫒涔嬮棿鐨勮繛鎺ユ柇寮锛岃嚜鍔ㄥ皾璇曢噸鏂拌繛鎺ャ傛瘡娆¤繛鎺ユ柇寮鍚庡垯灏濊瘯涓娆¢噸鏂拌繛鎺ャ傝鎯崇姝㈤噸鏂拌繛鎺ワ紝浣跨敤--skip-reconnect

         --safe-updates--i-am-a-dummy-U

鍙厑璁搁偅浜涗娇鐢ㄩ敭鍊兼寚瀹氳鐢熸晥鐨UPDATEDELETE璇彞銆傚鏋滃凡缁忓湪閫夐」鏂囦欢涓缃簡璇ラ夐」锛屽彲浠ョ敤鍛戒护琛屼腑鐨--safe-updates瑕嗙洊瀹冦傚叧浜庤閫夐」鐨勮缁嗕俊鎭弬瑙8.3.4鑺傦紝鈥mysql鎶宸р

         --secure-auth

涓嶅悜鏃(pre-4.1.1)鏍煎紡鐨勬湇鍔″櫒鍙戦佸瘑鐮併傝繖鏍峰彲浠ラ槻姝笉浣跨敤鏂板瘑鐮佹牸寮忕殑鏈嶅姟鍣ㄧ殑杩炴帴銆

         --show-warnings

濡傛灉姣忎釜璇彞鍚庢湁璀﹀憡鍒欐樉绀恒傝閫夐」閫傜敤浜庝氦浜掑紡鍜屾壒澶勭悊妯″紡銆

         --sigint-ignore

蹇借SIGINT绗﹀彿(涓鑸负Control-C鐨勭粨鏋)

         --silent-s

娌夐粯妯″紡銆備骇鐢熷皯鐨勮緭鍑恒傚彲浠ュ娆′娇鐢ㄨ閫夐」浠ヤ骇鐢熸洿灏戠殑杈撳嚭銆

         --skip-column-names-N

鍦ㄧ粨鏋滀腑涓嶅啓鍒楀悕銆

         --skip-line-numbers-L

鍦ㄩ敊璇俊鎭腑涓嶅啓琛屽彿銆傚綋浣犳兂瑕佹瘮杈冨寘鎷敊璇秷鎭殑缁撴灉鏂囦欢鏃舵湁鐢ㄣ

         --socket=path-S path

鐢ㄤ簬杩炴帴鐨勫鎺ュ瓧鏂囦欢銆

         --tables-t

鐢ㄨ〃鏍煎紡鏄剧ず杈撳嚭銆傝繖鏄氦浜掑紡搴旂敤鐨勯粯璁よ缃紝浣嗗彲鐢ㄦ潵浠ユ壒澶勭悊妯″紡浜х敓琛ㄨ緭鍑恒

         --tee=file_name

灏嗚緭鍑烘嫹璐濇坊鍔犲埌缁欏畾鐨勬枃浠朵腑銆傝閫夐」鍦ㄦ壒澶勭悊妯″紡涓嶅伐浣溿傚湪8.3.2鑺傦紝鈥mysql鍛戒护鈥涓缁嗚璁轰簡Tee鏂囦欢銆

         --unbuffered-n

姣忔鏌ヨ鍚庡埛鏂扮紦瀛樺尯銆

         --user=user_name-u user_name

褰撹繛鎺ユ湇鍔″櫒鏃MySQL浣跨敤鐨勭敤鎴峰悕銆

         --verbose-v

鍐楅暱妯″紡銆備骇鐢熸洿澶氱殑杈撳嚭銆傚彲浠ュ娆′娇鐢ㄨ閫夐」浠ヤ骇鐢熸洿澶氱殑杈撳嚭銆(渚嬪锛-v -v -v鐢氳嚦鍙互鍦ㄦ壒澶勭悊妯″紡浜х敓琛ㄨ緭鍑烘牸寮忥級

         --version-V

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

         --vertical-E

鍨傜洿杈撳嚭鏌ヨ杈撳嚭鐨勮銆傛病鏈夎閫夐」锛屽彲浠ョ敤\G缁撳熬鏉ユ寚瀹氬崟涓鍙ョ殑鍨傜洿杈撳嚭銆

         --wait-w

濡傛灉涓嶈兘寤虹珛杩炴帴锛岀瓑寰呭苟閲嶈瘯鑰屼笉鏄斁寮冦

         --xml-X

浜х敓XML杈撳嚭銆

浣犺繕鍙互浣跨敤--var_name=value閫夐」璁剧疆涓嬮潰鐨勫彉閲忥細

         connect_timeout

杩炴帴瓒呮椂鍓嶇殑绉掓暟銆(榛樿鍊兼槸0

         max_allowed_packet

浠庢湇鍔″櫒鍙戦佹垨鎺ユ敹鐨勬渶澶у寘闀垮害銆(榛樿鍊兼槸16MB

         max_join_size

褰撲娇鐢--safe-updates鏃惰仈鎺ヤ腑鐨勮鐨勮嚜鍔ㄩ檺鍒躲(榛樿鍊兼槸1,000,000

         net_buffer_length

TCP/IP鍜屽鎺ュ瓧閫氫俊缂撳啿鍖哄ぇ灏忋(榛樿鍊兼槸16KB

         select_limit

褰撲娇鐢--safe-updatesSELECT璇彞鐨勮嚜鍔ㄩ檺鍒躲(榛樿鍊兼槸1,000

涔熷彲浠ヤ娇鐢--set-variable=var_name=value or -O var_name=value璇硶鏉ヨ缃彉閲忋涓嶈禐鎴愪娇鐢璇ヨ娉

Unix涓紝mysql瀹㈡埛绋嬪簭鍚鍘嗗彶鏂囦欢涓啓鍏ュ凡鎵ц璇彞鐨勪竴鏉¤褰曘傞粯璁ゆ儏鍐碉紝鍘嗗彶鏂囦欢鍚嶄负.mysql_history骞跺湪鏍圭洰褰曚腑閲嶅缓銆傝鎯虫寚瀹氫笉鍚岀殑鏂囦欢锛屽簲璁剧疆MYSQL_HISTFILE鐜鍙橀噺鐨勫笺

濡傛灉涓嶆兂瑕佸巻鍙叉枃浠讹紝棣栧厛鍒犻櫎.mysql_history锛堝鏋滄湁锛夛紝鐒跺悗浣跨敤涓嬮潰鐨勪换浣曚竴绉嶆柟娉曪細

         MYSQL_HISTFILE鍙橀噺璁惧埌/dev/null銆傝鎯冲湪姣忔鐧诲綍鏃惰璇ヨ缃敓鏁堬紝灏嗚璁剧疆鏀惧叆澶栧3鐨勪竴涓惎鍔ㄦ枃浠朵腑銆

         鍒涘缓.mysql_history锛屼綔涓轰竴涓鍙烽摼鎺ユ寚鍚/dev/null

                shell> ln -s /dev/null $HOME/.mysql_history

鍙渶瑕佹墽琛屼竴娆°

8.3.2.聽mysql鍛戒护

mysql灏嗗彂鍑虹殑SQL璇彞鍙戦佸埌寰呮墽琛岀殑鏈嶅姟鍣ㄣ傝繕鏈変竴绯诲垪鍛戒护mysql鍙互鑷繁瑙i噴銆傝鏌ョ湅杩欎簺鍛戒护锛屽湪mysql>鎻愮ず涓嬭緭鍏help\h

mysql> help

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear command.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute a SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

姣忎釜鍛戒护鏈夐暱褰㈠紡鍜岀煭褰㈠紡銆傞暱褰㈠紡瀵瑰ぇ灏忓啓涓嶆晱鎰燂紱鐭舰寮忔晱鎰熴傞暱褰㈠紡鍚庨潰鍙互鍔犱竴涓垎鍙风粨鏉熺锛屼絾鐭舰寮忎笉鍙互銆

delimiter鍛戒护涓紝搴旈伩鍏嶄娇鐢ㄥ弽鏂滅嚎(\)锛屽洜涓鸿繖鏄MySQL鐨勮浆涔夌銆

Editnopagerpagersystem鍛戒护鍙湪Unix涓伐浣溿

status鍛戒护鎻愪緵杩炴帴鍜屼娇鐢ㄧ殑鏈嶅姟鍣ㄧ浉鍏崇殑閮ㄥ垎淇℃伅銆傚鏋滅敤--safe-updates妯″紡杩愯锛status涔熸墦鍗板奖鍝嶆煡璇㈢殑MySQL鍙橀噺鐨勫笺

瑕佹兂璁板綍鏌ヨ鍙婂叾杈撳嚭锛屽簲浣跨敤tee鍛戒护銆傚睆骞曚笂鏄剧ず鐨勬墍鏈夋暟鎹杩藉姞鍒扮粰瀹氱殑鏂囦欢鍚庨潰銆傝繖瀵逛簬璋冭瘯涔熷緢鏈夌敤銆傚彲浠ョ敤--tee閫夐」鍦ㄥ懡浠よ涓惎鐢ㄨ鐗规э紝鎴栬呯敤tee鍛戒护浜や簰寮忓惎鐢ㄣ傚彲浠ョ敤notee鍛戒护浜や簰寮忕鐢tee鏂囦欢銆傚啀娆℃墽琛tee鍙互閲嶆柊鍚敤鏃ュ織銆傚墠闈㈢殑鏂囦欢浣跨敤鏃朵笉甯︿换浣曞弬鏁般傝娉ㄦ剰鎵ц瀹屾瘡涓鍙ュ悗tee鍙互灏嗘煡璇㈢粨鏋滃埛鏂板埌涓涓枃浠朵腑锛屽苟涓斿湪mysql鎵撳嵃涓嬩竴涓彁绀哄墠鍒锋柊銆

--pager閫夐」锛屽彲浠ョ敤浜や簰寮忔ā寮忎娇鐢Unix绋嬪簭锛屼緥濡lessmore鎴栬呭叾瀹冪被浼肩殑绋嬪簭锛屾潵娴忚鎴栨悳绱㈡煡璇㈢粨鏋溿傚鏋滄湭鎸囧畾璇ラ夐」鐨勫硷紝mysql妫鏌PAGER鐜鍙橀噺鐨勫煎苟灏PAGER璁句负璇ュ笺傚彲浠ョ敤pager鍛戒护浜や簰寮忓惎鐢ㄨ緭鍑哄垎椤碉紝骞剁敤nopager绂佺敤銆傝鍛戒护閲囩敤鍙夊弬閲忥紱濡傛灉缁欏嚭锛屽垎椤电▼搴忚缃负璇ュ笺傚鏋滄病鏈夌粰鍑哄弬閲忥紝鍒嗛〉鍣ㄨ璁剧疆涓哄湪鍛戒护琛屼腑璁剧疆鐨勫垎椤靛櫒鐨勫硷紝濡傛灉鏈寚瀹氬垎椤靛櫒锛屽垯璁剧疆涓stdout

杈撳嚭鍒嗛〉鍙傚悎Unix锛屽洜涓哄畠浣跨敤popen()鍑芥暟锛岃鍑芥暟鍦Windows涓笉瀛樺湪銆傚湪Windows涓紝鍙互浣跨敤tee閫夐」鏉ヤ繚瀛樻煡璇㈣緭鍑猴紝灏界鍦ㄦ煇浜涙儏鍐典笅娴忚杈撳嚭鏃朵笉濡pager鏂逛究銆

鍏充簬pager鍛戒护鐨勪竴浜涙妧宸э細

         鍙互浣跨敤瀹冨啓鍏ヤ竴涓枃浠讹紝灏嗙粨鏋滃彧杈撳嚭鍒拌鏂囦欢涓細

                mysql> pager cat > /tmp/log.txt

涔熷彲浠ヤ负灏嗙敤浣滃垎椤靛櫒鐨勭▼搴忎紶閫掗夐」锛

mysql> pager less -n -i -S

         娉ㄦ剰鍓嶉潰渚嬪瓙涓殑-S閫夐」銆傚畠鍙互甯姪娴忚骞胯寖鍥寸殑鏌ヨ缁撴灉銆傛湁鏃跺お骞跨殑缁撴灉寰堥毦鍦ㄥ睆骞曚笂璇诲嚭鏉ャless-S閫夐」鍙互浣跨粨鏋滄洿鏄撲簬璇伙紝鍥犱负鍙互鐢ㄥ乏銆佸彸绠ご姘村钩婊氬姩瀹冦傝繕鍙互鍦less涓氦浜掑紡浣跨敤-S锛屼互鍏抽棴鎴栨墦寮姘村钩娴忚妯″紡銆傝缁嗕俊鎭闃呰鎵嬪唽涓殑less椤碉細

                shell> man less

         鍙互鎸囧畾寰堝鏉傜殑pager鍛戒护鏉ュ鐞嗘煡璇㈣緭鍑猴細

                mysql> PAGER cat | tee /dr1/tmp/res.txt \
                          | tee /dr2/tmp/res2.txt | less -n -i -S

鍦ㄨ渚嬪瓙涓紝璇ュ懡浠ゅ皢鏌ヨ缁撴灉鍙戦佸埌浣嶄簬/dr1/dr2涓婂畨瑁呯殑涓や釜涓嶅悓鐨勬枃浠剁郴缁熶腑鐨勪袱涓笉鍚岀洰褰曚腑鐨勪袱涓枃浠朵腑锛屼絾浠嶇劧鍙互閫氳繃less灏嗙粨鏋滄樉绀哄湪灞忓箷涓娿

杩樺彲浠ョ粨鍚堜娇鐢teepager鍑芥暟銆傚惎鐢ㄤ竴涓tee鏂囦欢骞跺皢pager璁剧疆涓less锛岃兘澶熶娇鐢less 绋嬪簭娴忚缁撴灉锛屽苟涓斾粛鐒跺彲浠ュ悓鏃跺皢鍐呭娣诲姞鍒颁竴涓枃浠朵腑銆傜粨鍚pager鍛戒护浣跨敤鐨Unix teemysql宓屽叆寮tee鍛戒护鐨勫樊鍒槸鍗充娇娌℃湁鍙敤鐨Unix tee锛屽祵鍏ュ紡tee浠嶇劧鍙互宸ヤ綔銆傚祵鍏ュ紡tee杩樺彲浠ヨ褰曞湪灞忓箷涓婅緭鍑虹殑鍐呭锛岃岀粨鍚pager鍛戒护浣跨敤鐨Unix tee涓嶈兘璁板綍閭d箞澶氱殑鍐呭銆傚苟涓旓紝鍙互浠MySQL涓氦浜掑紡鎵撳紑鎴栧叧闂tee鏂囦欢鏃ュ織銆傚綋浣犳兂瑕佸皢閮ㄥ垎鏌ヨ璁板綍鍒颁竴涓枃浠朵腑鏃跺緢鏈夌敤锛屼絾鍏跺畠涓嶉傚悎銆

榛樿mysql>鎻愮ず绗﹀彲浠ラ噸鏂伴厤缃傚畾涔夋彁绀虹鐨勫瓧绗︿覆鍙互鍖呭惈涓嬮潰鐨勭壒娈婂簭鍒楋細

閫夐」

鎻忚堪

\v

鏈嶅姟鍣ㄧ増鏈

\d

褰撳墠鐨勬暟鎹簱

\h

鏈嶅姟鍣ㄤ富鏈

\p

褰撳墠鐨TCP/IP绔彛鎴栧鎺ュ瓧鏂囦欢

\u

浣犵殑鐢ㄦ埛鍚

\U

浣犵殑鍏user_name@host_name璐︽埛鍚

\\

\鈥欏弽鏂滅嚎瀛楃

\n

鏂拌瀛楃

\t

Tab瀛楃

\

绌烘牸(鍙嶆枩绾垮悗闈㈢殑绌烘牸)

\_

绌烘牸

\R

褰撳墠鐨勬椂闂达紝24-灏忔椂鍐涚敤鏃堕棿(0-23)

\r

褰撳墠鐨勬椂闂达紝鏍囧噯12-灏忔椂(1-12)

\m

褰撳墠鏃堕棿鐨勫垎閽

\y

褰撳墠鐨勫勾锛屼袱浣

\Y

褰撳墠鐨勫勾锛屽洓浣

\D

褰撳墠鐨勬棩鏈

\s

褰撳墠鏃堕棿鐨勭

\w

褰撳墠鍛ㄧ殑澶╋紝3瀛楃鏍煎紡(MonTue...)

\P

am/pm

\o

褰撳墠鐨勬湀锛屾暟瀛楁牸寮

\O

褰撳墠鐨勬湀锛3瀛楃鏍煎紡(JanFeb...)

\c

闅忓彂鍑虹殑姣忎釜璇彞閫掑鐨勮鏁

\S

鍒嗗彿

\'

鍗曞紩鍙

\"

鍙屽紩鍙

\鈥欏悗闈㈣窡闅忕殑鍏跺畠瀛楁瘝鍒欏彉涓鸿瀛楁瘝銆

濡傛灉涓嶇敤浠讳綍鍙傞噺鎸囧畾鎻愮ず鍛戒护锛mysql灏嗘彁绀洪噸鏂拌缃綅榛樿mysql>

鍙互鐢ㄥ嚑绉嶆柟寮忚缃彁绀猴細

         浣跨敤鐜鍙橀噺

鍙互鐢MYSQL_PS1鐜鍙橀噺鏉ヨ缃彁绀哄瓧绗︿覆銆備緥濡傦細

shell> export MYSQL_PS1="(\u@\h) [\d]> "

         浣跨敤閫夐」鏂囦欢

鍙互鍦MySQL閫夐」鏂囦欢涓殑[mysql]缁勮缃彁绀猴紝渚嬪鏍圭洰褰曚腑鐨/etc/my.cnf.my.cnf鏂囦欢銆備緥濡傦細

[mysql]
prompt=(\\u@\\h) [\\d]>\\_

鍦ㄨ渚嬪瓙涓紝璇锋敞鎰忓弽鏂滅嚎鏄弻绾裤傚鏋滀娇鐢ㄩ夐」鏂囦欢涓殑prompt閫夐」鏉ヨ缃彁绀猴紝褰撲娇鐢ㄧ壒娈婃彁绀洪夐」鏃讹紝寤鸿浣跨敤鍙屽弽鏂滅嚎銆傚湪鍏佽鐨勬彁绀洪夐」鍜岄夐」鏂囦欢涓彲璇嗗埆鐨勭壒娈婅浆涔夊簭鍒椾腑鏈夐儴鍒嗛噸鍙犮(杩欎簺搴忓垪鍒椾簬4.3.2鑺傦紝鈥滀娇鐢ㄩ夐」鏂囦欢鈥濡傛灉浣跨敤鍗曞弽鏂滅嚎锛屼細閬囧埌闂銆備緥濡傦紝\s琚В閲婁负绌烘牸鑰屼笉鏄綋鍓嶇殑绉掑笺備笅闈㈢殑渚嬪瓙鏄剧ず浜嗗浣曞湪閫夐」鏂囦欢涓畾涔夋彁绀轰互鍖呮嫭褰撳墠鐨勬椂闂达紝鏍煎紡涓HH:MM:SS>

[mysql]
prompt="\\r:\\m:\\s> "

         浣跨敤鍛戒护琛岄夐」

鍙互鍦mysql鐨勫懡浠よ涓缃--prompt閫夐」銆備緥濡傦細

shell> mysql --prompt="(\u@\h) [\d]> "
(user@host) [database]>

         浜や簰寮

浣犲彲浠ヤ娇鐢prompt(\R)鍛戒护浜や簰鍦版洿鏀规彁绀恒備緥濡傦細

mysql> prompt (\u@\h) [\d]>\_
PROMPT set to '(\u@\h) [\d]>\_'
(user@host) [database]>
(user@host) [database]> prompt
Returning to default PROMPT of mysql>
mysql>

8.3.3. 鎬庢牱浠庢枃鏈枃浠舵墽琛孲QL璇彞

mysql瀹㈡埛绋嬪簭涓鑸氦浜掍娇鐢細

shell> mysql db_name

杩樺彲浠ュ皢SQL璇彞鏀惧埌涓涓枃浠朵腑鐒跺悗鍛婅瘔mysql浠庤鏂囦欢璇诲彇杈撳叆銆傝鎯冲疄鐜帮紝鍒涘缓涓涓枃鏈枃浠text_file锛屽苟鍖呭惈浣犳兂瑕佹墽琛岀殑璇彞銆傜劧鍚庢寜濡備笅鎵绀鸿皟鐢mysql

shell> mysql db_name < text_file

杩樺彲浠ョ敤涓涓USE db_name璇彞鍚姩鏂囨湰鏂囦欢銆傚湪杩欑鎯呭喌涓嬶紝涓嶉渶瑕佸湪鍛戒护琛屼腑鎸囧畾鏁版嵁搴撳悕锛

shell> mysql < text_file

濡傛灉姝h繍琛mysql锛屽彲浠ヤ娇鐢source\.鍛戒护鎵цSQL鑴氭湰鏂囦欢锛

mysql> source filename
mysql> \. filename

鏈夋椂鎯宠浣跨敤鑴氭湰鏉ュ悜鐢ㄦ埛鏄剧ず杩涘害淇℃伅锛涗负姝ゅ彲浠ユ彃鍏ヤ笅杩拌锛

SELECT '<info_to_display>' AS ' '

灏嗚緭鍑<info_to_display>

鍏充簬鎵瑰鐞嗘ā寮忕殑璇︾粏淇℃伅锛屽弬瑙3.5鑺傦紝鈥滃湪鎵瑰鐞嗘ā寮涓嬩娇鐢╩ysql鈥

8.3.4.聽mysql鎶宸

璇ヨ妭鎻忚堪浜嗗彲浠ュ府鍔╀綘鏇存湁鏁堜娇鐢mysql鐨勪竴浜鎶鏈

8.3.4.1. 鍨傜洿鏄剧ず鏌ヨ缁撴灉

涓浜涙煡璇㈢粨鏋滃鏋滃瀭鐩存樉绀鸿屼笉鐢ㄩ氬父鐨勬按骞宠〃鏍煎紡鏄剧ず锛屽垯鏇村鏄撹鍙栥傜敤\G鑰屼笉鐢ㄥ垎鍙风粨鏉熸煡璇㈠彲浠ュ瀭鐩存樉绀烘煡璇€備緥濡傦紝鍖呮嫭鏂拌鐨勬洿闀跨殑鏂囨湰鍊煎瀭鐩磋緭鍑烘椂閫氬父鏇村鏄撹鍙栵細

mysql> SELECT * FROM mails WHERE LENGTH(txt) < 300 LIMIT 300,1\G
*************************** 1. row ***************************
  msg_nro: 3068
     date: 2000-03-01 23:29:50
time_zone: +0200
mail_from: Monty
    reply: monty@no.spam.com
  mail_to: "Thimble Smith" <tim@no.spam.com>
      sbj: UTF-8
      txt: >>>>> "Thimble" == Thimble Smith writes:

Thimble> Hi.  I think this is a good idea.  Is anyone familiar
Thimble> with UTF-8 or Unicode? Otherwise, I'll put this on my
Thimble> TODO list and see what happens.

Yes, please do that.

Regards,
Monty
     file: inbox-jani-1
     hash: 190402944
1 row in set (0.09 sec)

8.3.4.2. 浣跨敤--safe-updates閫夐」

瀵逛簬鏂版墜锛屾湁涓涓湁鐢ㄧ殑鍚姩閫夐」--safe-updates(--i-am-a-dummy锛屽叿鏈夌浉鍚岀殑鏁堟灉)銆傚綋浣犲凡缁忓彂鍑轰竴涓DELETE FROM tbl_name璇彞浣嗗繕璁颁簡WHERE瀛愬彞鏃跺緢鏈夌敤銆傞氬父鎯呭喌锛岃繖鏍风殑璇彞浠庤〃涓垹闄ゆ墍鏈夎銆傜敤--safe-updates锛屽彲浠ラ氳繃鎸囧畾鍙互璇嗗埆瀹冧滑鐨勯敭鍊煎彧鍒犻櫎鏌愪簺琛屻傝繖鏍峰彲浠ュ府鍔╅槻姝簨鏁呫

鑻ヤ娇鐢--safe-updates閫夐」锛mysql杩炴帴MySQL鏈嶅姟鍣ㄦ椂鍙戝嚭涓嬮潰鐨勮鍙ワ細

SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=1000, SQL_MAX_JOIN_SIZE=1000000;

鍙傝13.5.3鑺傦紝鈥淪ET璇硶鈥

SET璇彞鏈変笅闈㈢殑鏁堟灉锛

         涓嶅厑璁镐綘鎵цUPDATEDELETE璇彞锛岄櫎闈炲湪WHERE瀛愬彞涓寚瀹氫竴涓敭鍊肩害鏉熸垨鎻愪緵涓涓LIMIT瀛愬彞(鎴栦簩鑰呯殕浣跨敤)銆備緥濡傦細

                UPDATE tbl_name SET not_key_column=val WHERE key_column=val;
                 
                UPDATE tbl_name SET not_key_column=val LIMIT 1;

         鎵鏈夊ぇ鐨SELECT缁撴灉鑷姩闄愬埗鍒1,000琛岋紝闄ら潪璇彞鍖呮嫭涓涓LIMIT瀛愬彞銆

         鏀惧純鍙兘闇瑕佹鏌1,000,000澶氳缁勫悎鐨勫琛SELECT璇彞銆

瑕佸皢闄愬埗鎸囧畾涓1,0001,000,000涔嬪鐨勫硷紝鍙互浣跨敤--select_limit--max_join_size閫夐」瑕嗙洊榛樿鍊硷細

shell> mysql --safe-updates --select_limit=500 --max_join_size=10000

8.3.4.3. 绂佺敤mysql鑷姩杩

濡傛灉mysql瀹㈡埛绋嬪簭鍙戦佹煡璇㈡椂鏂紑涓庢湇鍔″櫒鐨勮繛鎺ワ紝瀹冪珛鍗冲苟鑷姩灏濊瘯閲嶆柊杩炴帴鏈嶅姟鍣ㄥ苟鍐嶆鍙戦佹煡璇€傜劧鑰岋紝鍗充娇mysql閲嶆柊杩炴帴鎴愬姛锛屼綘鐨勭1涓繛鎺ヤ篃宸茬粡缁撴潫锛屽苟涓斾互鍓嶇殑浼氳瘽瀵硅薄鍜岃瀹氬艰涓㈠け锛氬寘鎷复鏃惰〃銆佽嚜鍔ㄦ彁浜ゆā寮忥紝浠ュ強鐢ㄦ埛鍜屼細璇濆彉閲忋傝琛屼负寰堝嵄闄╋紝濡備笅闈㈢殑渚嬪瓙鎵绀猴紝鏈嶅姟鍣ㄥ皢鍦ㄤ綘涓嶇煡閬撶殑鎯呭喌涓嬪叧闂苟閲嶅惎锛

mysql> SET @a=1;
Query OK, 0 rows affected (0.05 sec)
 
mysql> INSERT INTO t VALUES(@a);
ERROR 2006: MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1
Current database: test
 
Query OK, 1 row affected (1.30 sec)
 
mysql> SELECT * FROM t;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.05 sec)

@a鐢ㄦ埛鍙橀噺宸茬粡闅忚繛鎺ヤ涪澶憋紝骞朵笖閲嶆柊杩炴帴鍚庡畠涔熸病鏈夊畾涔夈傚鏋滄湁蹇呰鍦ㄨ繛鎺ユ柇寮鏃剁粓姝mysql骞舵彁绀洪敊璇紝浣犲彲浠ョ敤--skip-reconnect閫夐」鍚姩mysql瀹㈡埛绋嬪簭銆

8.4. mysqlaccess锛氱敤浜庢鏌ヨ闂潈闄愮殑瀹㈡埛绔

mysqlaccessYves CarlierMySQL鍒嗗彂鎻愪緵鐨勪竴涓瘖鏂伐鍏枫傚畠妫鏌ヨ闂潈闄愮殑涓绘満鍚嶃佺敤鎴峰悕鍜屾暟鎹簱缁勫悎銆傝娉ㄦ剰 mysqlaccess妫鏌ュ彧浣跨敤userdbhost琛ㄧ殑璁块棶銆傚畠涓嶆鏌ュ湪tables_privcolumns_privprocs_priv琛ㄤ腑鎸囧畾鐨勮〃銆佸垪鎴栬呯▼搴忕殑鏉冮檺銆

璋冪敤mysqlaccess鐨勬柟娉曪細

shell> mysqlaccess [host_name [user_name [db_name]]] [options]

mysqlaccess鐞嗚В涓嬮潰鐨勯夐」锛

         ---help-

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

         --brief-b

鐢熸垚鍗曡琛ㄦ牸寮忕殑鎶ュ憡銆

         --commit

浠庝复鏃惰〃灏嗘柊璁块棶鏉冮檺澶嶅埗鍒板師鎺堟潈琛ㄣ傚繀椤讳负鏂扮殑鏉冮檺鍒锋柊鎺堟潈琛ㄤ互浣垮叾鐢熸晥銆(渚嬪锛屾墽琛mysqladmin RELOAD鍛戒护锛

         --copy

浠庡師鎺堟潈琛ㄩ噸杞戒复鏃舵巿鏉冭〃銆

         --db=db_name-d db_name

鎸囧畾鏁版嵁搴撳悕銆

         ---debug=N

鎸囧畾璋冭瘯绾у埆銆N鍙互涓轰粠03鐨勪竴涓暣鏁般

         --host=host_name-h host_name

鍦ㄨ闂潈闄愪腑浣跨敤鐨勪富鏈哄悕銆

         --howto

鏄剧ず涓浜涗緥瀛愭樉绀哄浣曚娇鐢mysqlaccess

         --old_server

鍋囧畾鏈嶅姟鍣ㄦ槸涓涓棫鐗堟湰鐨MySQL鏈嶅姟鍣(MySQL 3.21涔嬪墠)锛岃繕涓嶇煡閬撳浣曞鐞嗗叏WHERE瀛愬彞銆

         --password[=password]-p[password]

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑瀵嗙爜銆傚鏋滀綘鍦ㄥ懡浠よ涓湪--password-p閫夐」鍚庨潰鐪佺暐 瀵嗙爜鍊硷紝灏嗘彁绀轰綘杈撳叆瀵嗙爜銆

         --plan

鏄剧ず灏嗘潵鍙戝竷鐨勫缓璁拰鎬濇兂銆

         --preview

鏇存敼涓存椂鎺堟潈琛ㄥ悗鏄剧ず鏉冮檺鐨勪笉鍚屻

         --relnotes

鏄剧ず鍙戝竷娉ㄨВ銆

         --rhost=host_name-H host_name

杩炴帴缁欏畾涓绘満鐨MySQL鏈嶅姟鍣ㄣ

         --rollback

鍙栨秷瀵逛复鏃舵巿鏉冭〃鐨勬渶鏂扮殑鏇存敼銆

         --spassword[=password]-P[password]

super鐢ㄦ埛杩炴帴鏈嶅姟鍣ㄦ椂浣跨敤鐨勫瘑鐮併傚鏋滃湪鍛戒护琛屼腑鍦--password-p閫夐」鍚庨潰鐪佺暐浜 瀵嗙爜鍊硷紝灏嗘彁绀轰綘杈撳叆瀵嗙爜銆

         --superuser=user_name-U user_name

鎸囧畾浠super鐢ㄦ埛杩炴帴鏃剁殑鐢ㄦ埛鍚嶃

         --tables-t

鐢熸垚琛ㄦ牸寮忕殑鎶ュ憡銆

         --user=user_name-u user_name

鍦ㄨ闂潈闄愪腑浣跨敤鐨勪富鏈哄悕銆

         --version-v

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

濡傛灉浣犵殑MySQL鍒嗗彂瀹夎鍦ㄦ煇涓潪鏍囧噯浣嶇疆锛屽繀椤昏繘鍏mysqlaccess鏈熸湜鎵惧埌mysql瀹㈡埛鐨勭洰褰曘傜紪杈戝ぇ绾﹀湪18琛屽鐨mysqlaccess鑴氭湰銆傛悳绱㈢被浼间笅闈㈢殑涓琛岋細

$MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable

灏嗚矾寰勬洿鏀逛负mysql瀹為檯鍦ㄧ郴缁熶腑淇濆瓨鐨勪綅缃傚鏋滀笉杩欐牱鍋氾紝褰撹繍琛mysqlaccess鏃朵細鍙戠敓Broken pipe閿欒銆

8.5. mysqladmin锛氱敤浜庣鐞哅ySQL鏈嶅姟鍣ㄧ殑瀹㈡埛绔

mysqladmin鏄竴涓墽琛岀鐞嗘搷浣滅殑瀹㈡埛绋嬪簭銆傚彲浠ョ敤瀹冩潵妫鏌ユ湇鍔″櫒鐨勯厤缃拰褰撳墠鐨勭姸鎬侊紝鍒涘缓骞跺垹闄ゆ暟鎹簱绛夌瓑銆

杩欐牱璋冪敤mysqladmin

shell> mysqladmin [options] command [command-options] [command [command-options]] ...

mysqladmin鏀寔涓嬮潰鐨勫懡浠わ細

         create db_name

鍒涘缓涓涓悕涓db_name鐨勬柊鏁版嵁搴撱

         debug

鍛婅瘔鏈嶅姟鍣ㄥ悜閿欒鏃ュ織鍐欏叆璋冭瘯淇℃伅銆

         drop db_name

鍒犻櫎鍚嶄负db_nam鐨勬暟鎹簱鍜屾墍鏈夎〃銆

         extended-status

鏄剧ず鏈嶅姟鍣ㄧ姸鎬佸彉閲忓強鍏跺笺

         flush-hosts

鍒锋柊涓绘満缂撳瓨涓殑鎵鏈変俊鎭

         flush-logs

鍒锋柊鎵鏈夋棩蹇椼

         flush-privileges

閲嶈浇鎺堟潈琛(绫讳技reload)

         flush-status

娓呴櫎鐘舵佸彉閲忋

         flush-tables

鍒锋柊鎵鏈夎〃銆

         flush-threads

鍒锋柊绾跨▼缂撳瓨銆

         kill id,id,...

鏉鎺夋湇鍔″櫒绾跨▼銆

         old-password new-password

绫讳技password浣嗕娇鐢ㄦ棫鐨(pre-4.1)瀵嗙爜鍝堝笇鏍煎紡淇濆瓨 瀵嗙爜銆(鍙傝5.7.9鑺傦紝鈥淢ySQL 4.1涓殑瀵嗙爜鍝堝笇澶勭悊鈥

         password new-password

璁剧疆涓涓柊瀵嗙爜銆傚皢鐢mysqladmin杩炴帴鏈嶅姟鍣ㄤ娇鐢ㄧ殑 璐︽埛鐨勫瘑鐮佹洿鏀逛负new-password

濡傛灉new-password鍖呭惈绌烘牸鎴栧叾瀹冨懡浠よВ閲婄鐨勭壒娈婂瓧绗︼紝闇瑕佺敤寮曞彿灏嗗畠寮曡捣鏉ャ傚湪Windows涓紝涓瀹氳浣跨敤鍙屽紩鍙疯屼笉瑕佺敤鍗曞紩鍙凤紱鍗曞紩鍙蜂笉浼氫粠 瀵嗙爜涓墺绂诲嚭鏉ワ紝鑰屾槸瑙i噴涓哄瘑鐮佺殑涓閮ㄥ垎銆備緥濡傦細

shell> mysqladmin password "my new password"

         ping

妫鏌ユ湇鍔″櫒鏄惁浠嶆椿鍔ㄣ傚鏋滄湇鍔″櫒鍦ㄨ繍琛mysqladmin杩斿洖鐘舵0锛屽鏋滀笉杩愯杩斿洖1銆傚嵆浣垮嚭鐜伴敊璇緥濡Access denied涔熶负0锛屽洜涓鸿繖璇存槑鏈嶅姟鍣ㄥ湪杩愯浣嗘嫆缁濅簡杩炴帴锛屼笌鏈嶅姟鍣ㄤ笉鍦ㄨ繍琛屼笉鍚屻

         processlist

鏄剧ず娲诲姩鏈嶅姟鍣ㄧ嚎绋嬬殑鍒楄〃銆傜被浼SHOW PROCESSLIST璇彞鐨勮緭鍑恒傚鏋滅粰鍑轰簡--verbose閫夐」锛岃緭鍑虹被浼SHOW FULL PROCESSLIST(鍙傝13.5.4.16鑺傦紝鈥淪HOW PROCESSLIST璇硶鈥

         reload

閲嶈浇鎺堟潈琛ㄣ

         refresh

鍒锋柊鎵鏈夎〃骞跺叧闂拰鎵撳紑鏃ュ織鏂囦欢銆

         shutdown

鍋滄鏈嶅姟鍣ㄣ

         start-slave

寮濮嬩粠鏈嶅姟鍣ㄤ笂鐨勫鍒躲

         status

鏄剧ず鐭湇鍔″櫒鐘舵佹秷鎭

         stop-slave

鍋滄浠庢湇鍔″櫒涓婄殑澶嶅埗銆

         variables

鏄剧ず鏈嶅姟鍣ㄧ郴缁熷彉閲忓強鍏跺笺

         version

鏄剧ず鏈嶅姟鍣ㄧ殑鐗堟湰淇℃伅銆

鎵鏈夊懡浠ゅ彲浠ョ畝鍖栦负浠讳綍鍞竴鐨勫墠缂銆備緥濡傦細

shell> mysqladmin proc stat
+----+-------+-----------+----+---------+------+-------+------------------+
| Id | User  | Host      | db | Command | Time | State | Info             |
+----+-------+-----------+----+---------+------+-------+------------------+
| 51 | monty | localhost |    | Query   | 0    |       | show processlist |
+----+-------+-----------+----+---------+------+-------+------------------+
Uptime: 1473624  Threads: 1  Questions: 39487  
Slow queries: 0  Opens: 541  Flush tables: 1  
Open tables: 19  Queries per second avg: 0.0268
 

mysqladmin status鍛戒护鐨勭粨鏋滄樉绀轰笅闈㈢殑鍊硷細

         Uptime

MySQL鏈嶅姟鍣ㄥ凡缁忚繍琛岀殑绉掓暟銆

         Threads

娲诲姩绾跨▼(瀹㈡埛)鐨勬暟鐩

         Questions

鏈嶅姟鍣ㄥ惎鍔ㄤ互鏉ュ鎴风殑闂(鏌ヨ)鏁扮洰銆

         Slow queries

鎵ц鏃堕棿瓒呰繃long_query_time绉掔殑鏌ヨ鐨勬暟閲忋傚弬瑙5.11.4鑺傦紝鈥滄參閫熸煡璇㈡棩蹇椻

         Opens

鏈嶅姟鍣ㄥ凡缁忔墦寮鐨勬暟鎹簱琛ㄧ殑鏁伴噺銆

         Flush tables

鏈嶅姟鍣ㄥ凡缁忔墽琛岀殑flush ...refreshreload鍛戒护鐨勬暟閲忋

         Open tables

鐩墠鎵撳紑鐨勮〃鐨勬暟閲忋

         Memory in use

mysqld浠g爜鐩存帴鍒嗛厤鐨勫唴瀛樻暟閲忋傚彧鏈夌敤--with--debug=full缂栬瘧浜MySQL璇ュ兼墠鏄剧ず銆

         Maximum memory used

mysqld浠g爜鐩存帴鍒嗛厤鐨勬渶澶у唴瀛樻暟閲忋傚彧鏈夌敤--with--debug=full缂栬瘧浜MySQL璇ュ兼墠鏄剧ず銆

濡傛灉褰撲娇鐢Unix濂楁帴瀛楁枃浠惰繛鎺ユ湰鍦版湇鍔″櫒鏃舵墽琛mysqladmin shutdownmysqladmin灏嗙瓑寰呯洿鍒版湇鍔″櫒鐨勮繘绋ID鏂囦欢琚垹闄わ紝浠ョ‘淇濇湇鍔″櫒姝g‘鍋滄銆

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

         ---help-

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

         --character-sets-dir=path

瀛楃闆嗙殑瀹夎鐩綍銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --compress-C

鍘嬬缉瀹㈡埛鍜屾湇鍔″櫒涔嬮棿鍙戦佺殑鎵鏈変俊鎭紙濡傛灉浜岃呭潎鏀寔鍘嬬缉锛夈

         --count=num-c num

杩唬鏁扮洰銆傝閫夐」鍙湁缁撳悎--sleep (-i)鎵嶈兘宸ヤ綔銆

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父涓'd:t:o,file_name'銆 榛樿涓'd:t:o,/tmp/mysqladmin.trace'

         --default-character-set=charset

浣跨敤charsetas浣滀负榛樿瀛楃闆嗐傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --force-f

涓嶅啀涓drop database鍛戒护杩涜纭銆傚浜庡涓懡浠わ紝鍗充娇鍑虹幇閿欒涔熺户缁

         --host=host_name-h host_name

杩炴帴缁欏畾涓绘満涓婄殑MySQL鏈嶅姟鍣ㄣ

         --password[=password]-p[password]

杩炴帴鏈嶅姟鍣ㄤ娇鐢ㄧ殑瀵嗙爜銆傚鏋滀娇鐢ㄧ煭閫夐」褰㈠紡(-p)锛岃閫夐」鍜 瀵嗙爜涔嬮棿涓嶈兘鏈夌┖鏍笺傚鏋滀綘鍦ㄥ懡浠よ涓湪--password-p閫夐」鍚庨潰鐪佺暐 瀵嗙爜鍊硷紝灏嗘彁绀轰綘杈撳叆瀵嗙爜銆

         --port=port_num-P port_num

鐢ㄤ簬杩炴帴鐨TCP/IP绔彛鍙枫

         --protocol={TCP | SOCKET | PIPE | MEMORY}

浣跨敤鐨勮繛鎺ュ崗璁

         --relative-r

褰撳甫-I浣跨敤鏃舵樉绀哄綋鍓嶅拰鍓嶉潰鍊肩殑宸埆銆傜洰鍓嶏紝璇ラ夐」鍙敤浜extended-status鍛戒护銆

         --silent-s

濡傛灉涓嶈兘寤虹珛涓庢湇鍔″櫒鐨勮繛鎺ュ垯浠ユ矇榛樻柟寮忛鍑恒

         --sleep=delay-i delay

姣忕潯鐪delay绉掑悗鎵ц涓娆″懡浠ゃ

         --socket=path-S path

鐢ㄤ簬杩炴帴鐨勫鎺ュ瓧鏂囦欢銆

         --user=user_name-u user_name

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑MySQL鐢ㄦ埛鍚嶃

         --verbose-v

鍐楅暱妯″紡銆傛墦鍗板嚭绋嬪簭鎿嶄綔鐨勮缁嗕俊鎭

         --version-V

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

         --vertical-E

鍨傜洿鎵撳嵃杈撳嚭銆傜被浼间簬--relative锛屼絾鍨傜洿鎵撳嵃杈撳嚭銆

         --wait[=count]-w[count]

濡傛灉杩炴帴涓嶈兘寤虹珛锛岀瓑寰呭苟閲嶈瘯鑰屼笉鏄斁寮冦傚鏋滅粰鍑轰竴涓夐」鍊硷紝鍒欐寚绀洪噸璇曠殑娆℃暟銆傞粯璁ゆ槸涓娆°

涔熷彲浠ヤ娇鐢--var_name=value閫夐」璁剧疆涓嬮潰鐨勫彉閲忥細

         connect_timeout

杩炴帴瓒呮椂涔嬪墠鐨勬渶澶х鏁般傞粯璁ゅ间负43200(12灏忔椂)

         shutdown_timeout

绛夊欏叧闂殑鏈澶х鏁般傞粯璁ゅ间负3600(1灏忔椂)

涔熷彲浠ヤ娇鐢--set-variable=var_name=value-O var_name=value璇硶鏉ヨ缃彉閲忋傜劧鑰岋紝鐜板湪涓嶈禐鎴愯璇硶锛屽苟涓斾笉鍐嶄娇鐢ㄣ

8.6. mysqlbinlog锛氱敤浜庡鐞嗕簩杩涘埗鏃ュ織鏂囦欢鐨勫疄鐢ㄥ伐鍏

鏈嶅姟鍣ㄧ敓鎴愮殑浜岃繘鍒舵棩蹇楁枃浠跺啓鎴愪簩杩涘埗鏍煎紡銆傝鎯虫鏌ヨ繖浜涙枃鏈牸寮忕殑鏂囦欢锛屽簲浣跨敤mysqlbinlog瀹炵敤宸ュ叿銆

搴旇繖鏍疯皟鐢mysqlbinlog

shell> mysqlbinlog [options] log-files...

渚嬪锛岃鎯虫樉绀轰簩杩涘埗鏃ュ織binlog.000003鐨勫唴瀹癸紝浣跨敤涓嬮潰鐨勫懡浠わ細

shell> mysqlbinlog binlog.0000003

杈撳嚭鍖呮嫭鍦binlog.000003涓寘鍚殑鎵鏈夎鍙ワ紝浠ュ強鍏跺畠淇℃伅渚嬪姣忎釜璇彞鑺辫垂鐨勬椂闂淬佸鎴峰彂鍑虹殑绾跨▼ID銆佸彂鍑虹嚎绋嬫椂鐨勬椂闂存埑绛夌瓑銆

閫氬父鎯呭喌锛屽彲浠ヤ娇鐢mysqlbinlog鐩存帴璇诲彇浜岃繘鍒舵棩蹇楁枃浠跺苟灏嗗畠浠敤浜庢湰鍦MySQL鏈嶅姟鍣ㄣ備篃鍙互浣跨敤--read-from-remote-server閫夐」浠庤繙绋嬫湇鍔″櫒璇诲彇浜岃繘鍒舵棩蹇椼

褰撹鍙栬繙绋嬩簩杩涘埗鏃ュ織鏃讹紝鍙互閫氳繃杩炴帴鍙傛暟閫夐」鏉ユ寚绀哄浣曡繛鎺ユ湇鍔″櫒锛屼絾瀹冧滑缁忓父琚拷鐣ユ帀锛岄櫎闈炰綘杩樻寚瀹氫簡--read-from-remote-server閫夐」銆傝繖浜涢夐」鏄--host--password--port--protocol--socket--user

杩樺彲浠ヤ娇鐢mysqlbinlog鏉ヨ鍙栧湪澶嶅埗杩囩▼涓粠鏈嶅姟鍣ㄦ墍鍐欑殑涓户鏃ュ織鏂囦欢銆備腑缁ф棩蹇楁牸寮忎笌浜岃繘鍒舵棩蹇楁枃浠剁浉鍚屻

5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥涓缁嗚璁轰簡浜岃繘鍒舵棩蹇椼

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

         ---help-

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

         ---database=db_name-d db_name

鍙垪鍑鸿鏁版嵁搴撶殑鏉$洰(鍙敤鏈湴鏃ュ織)

         --force-read-f

浣跨敤璇ラ夐」锛屽鏋mysqlbinlog璇诲畠涓嶈兘璇嗗埆鐨勪簩杩涘埗鏃ュ織浜嬩欢锛屽畠浼氭墦鍗拌鍛婏紝蹇界暐璇ヤ簨浠跺苟缁х画銆傛病鏈夎閫夐」锛屽鏋mysqlbinlog璇诲埌姝ょ被浜嬩欢鍒欏仠姝€

         --hexdump-H

鍦ㄦ敞閲婁腑鏄剧ず鏃ュ織鐨勫崄鍏繘鍒惰浆鍌ㄣ傝杈撳嚭鍙互甯姪澶嶅埗杩囩▼涓殑璋冭瘯銆傚湪MySQL 5.1.2涓坊鍔犱簡璇ラ夐」銆

         --host=host_name-h host_name

鑾峰彇缁欏畾涓绘満涓婄殑MySQL鏈嶅姟鍣ㄧ殑浜岃繘鍒舵棩蹇椼

         --local-load=path-l pat

涓烘寚瀹氱洰褰曚腑鐨LOAD DATA INFILE棰勫鐞嗘湰鍦颁复鏃舵枃浠躲

         --offset=N-o N

璺宠繃鍓N涓潯鐩

         --password[=password]-p[password]

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑瀵嗙爜銆傚鏋滀娇鐢ㄧ煭閫夐」褰㈠紡(-p)锛岄夐」鍜 瀵嗙爜涔嬮棿涓嶈兘鏈夌┖鏍笺傚鏋滃湪鍛戒护琛屼腑--password-p閫夐」鍚庨潰娌℃湁 瀵嗙爜鍊硷紝鍒欐彁绀鸿緭鍏ヤ竴涓瘑鐮併

         --port=port_num-P port_num

鐢ㄤ簬杩炴帴杩滅▼鏈嶅姟鍣ㄧ殑TCP/IP绔彛鍙枫

         --position=N-j N

涓嶈禐鎴愪娇鐢紝搴斾娇鐢--start-position

         --protocol={TCP | SOCKET | PIPE | -position

浣跨敤鐨勮繛鎺ュ崗璁

         --read-from-remote-server-R

MySQL鏈嶅姟鍣ㄨ浜岃繘鍒舵棩蹇椼傚鏋滄湭缁欏嚭璇ラ夐」锛屼换浣曡繛鎺ュ弬鏁伴夐」灏嗚蹇界暐銆傝繖浜涢夐」鏄--host--password--port--protocol--socket--user

         --result-file=name, -r name

灏嗚緭鍑烘寚鍚戠粰瀹氱殑鏂囦欢銆

         --short-form-s

鍙樉绀烘棩蹇椾腑鍖呭惈鐨勮鍙ワ紝涓嶆樉绀哄叾瀹冧俊鎭

         --socket=path-S path

鐢ㄤ簬杩炴帴鐨勫鎺ュ瓧鏂囦欢銆

         --start-datetime=datetime

浠庝簩杩涘埗鏃ュ織涓1涓棩鏈熸椂闂寸瓑浜庢垨鏅氫簬datetime鍙傞噺鐨勪簨浠跺紑濮嬭鍙栥datetime鍊肩浉瀵逛簬杩愯mysqlbinlog鐨勬満鍣ㄤ笂鐨勬湰鍦版椂鍖鍊兼牸寮忓簲绗﹀悎DATETIMETIMESTAMP鏁版嵁绫诲瀷銆備緥濡傦細

shell> mysqlbinlog --start-datetime="2004-12-25 11:25:56" binlog.000003

璇ラ夐」鍙互甯姪鐐瑰鐐规仮澶嶃

         --stop-datetime=datetime

浠庝簩杩涘埗鏃ュ織涓1涓棩鏈熸椂闂寸瓑浜庢垨鏅氫簬datetime鍙傞噺鐨勪簨浠惰捣鍋滄璇汇傚叧浜datetime鍊肩殑鎻忚堪鍙傝--start-datetime閫夐」銆傝閫夐」鍙互甯姪鍙婃椂鎭㈠銆

         --start-position=N

浠庝簩杩涘埗鏃ュ織涓1涓綅缃瓑浜N鍙傞噺鏃剁殑浜嬩欢寮濮嬭銆

         --stop-position=N

浠庝簩杩涘埗鏃ュ織涓1涓綅缃瓑浜庡拰澶т簬N鍙傞噺鏃剁殑浜嬩欢璧峰仠姝㈣銆

         --to-last-logs-t

MySQL鏈嶅姟鍣ㄤ腑璇锋眰鐨勪簩杩涘埗鏃ュ織鐨勭粨灏惧涓嶅仠姝紝鑰屾槸缁х画鎵撳嵃鐩村埌鏈鍚庝竴涓簩杩涘埗鏃ュ織鐨勭粨灏俱傚鏋滃皢杈撳嚭鍙戦佺粰鍚屼竴鍙MySQL鏈嶅姟鍣紝浼氬鑷存棤闄愬惊鐜傝閫夐」瑕佹眰--read-from-remote-server

         --disable-logs-bin-D

绂佺敤浜岃繘鍒舵棩蹇椼傚鏋滀娇鐢--to-last-logs閫夐」灏嗚緭鍑哄彂閫佺粰鍚屼竴鍙MySQL鏈嶅姟鍣紝鍙互閬垮厤鏃犻檺寰幆銆傝閫夐」鍦ㄥ穿婧冩仮澶嶆椂涔熷緢鏈夌敤锛屽彲浠ラ伩鍏嶅鍒跺凡缁忚褰曠殑璇彞銆娉ㄩ噴锛璇ラ夐」瑕佹眰鏈SUPER鏉冮檺銆

         --user=user_name-u user_name

杩炴帴杩滅▼鏈嶅姟鍣ㄦ椂浣跨敤鐨MySQL鐢ㄦ埛鍚嶃

         --version-V

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

杩樺彲浠ヤ娇鐢--var_name=value閫夐」璁剧疆涓嬮潰鐨勫彉閲忥細

         open_files_limit

鎸囧畾瑕佷繚鐣欑殑鎵撳紑鐨勬枃浠舵弿杩扮鐨勬暟閲忋

鍙互灏mysqlbinlog鐨勮緭鍑轰紶鍒mysql瀹㈡埛绔互鎵ц鍖呭惈鍦ㄤ簩杩涘埗鏃ュ織涓殑璇彞銆傚鏋滀綘鏈変竴涓棫鐨勫浠斤紝璇ラ夐」鍦ㄥ穿婧冩仮澶嶆椂涔熷緢鏈夌敤(鍙傝5.9.1鑺傦紝鈥滄暟鎹簱澶囦唤鈥)

shell> mysqlbinlog hostname-bin.000001 | mysql

鎴栵細

shell> mysqlbinlog hostname-bin.[0-9]* | mysql

濡傛灉浣犻渶瑕佸厛淇敼鍚鍙ョ殑鏃ュ織锛岃繕鍙互灏mysqlbinlog鐨勮緭鍑洪噸鏂版寚鍚戜竴涓枃鏈枃浠躲(渚嬪锛屾兂鍒犻櫎鐢变簬鏌愮鍘熷洜鑰屼笉鎯虫墽琛岀殑璇彞)銆傜紪杈戝ソ鏂囦欢鍚庯紝灏嗗畠杈撳叆鍒mysql绋嬪簭骞舵墽琛屽畠鍖呭惈鐨勮鍙ャ

mysqlbinlog鏈変竴涓--position閫夐」锛屽彧鎵撳嵃閭d簺鍦ㄤ簩杩涘埗鏃ュ織涓殑鍋忕Щ閲忓ぇ浜庢垨绛変簬鏌愪釜缁欏畾浣嶇疆鐨勮鍙(缁欏嚭鐨勪綅缃繀椤诲尮閰嶄竴涓簨浠剁殑寮濮)銆傚畠杩樻湁鍦ㄧ湅瑙佺粰瀹氭棩鏈熷拰鏃堕棿鐨勪簨浠跺悗鍋滄鎴栧惎鍔ㄧ殑閫夐」銆傝繖鏍峰彲浠ヤ娇鐢--stop-datetime閫夐」杩涜鐐瑰鐐规仮澶(渚嬪锛岃兘澶熻鈥滃皢鏁版嵁搴撳墠婊氬姩鍒颁粖澶10:30 AM鐨勪綅缃)

濡傛灉MySQL鏈嶅姟鍣ㄤ笂鏈夊涓鎵ц鐨勪簩杩涘埗鏃ュ織锛屽畨鍏ㄧ殑鏂规硶鏄湪涓涓繛鎺ヤ腑澶勭悊瀹冧滑銆備笅闈㈡槸涓涓鏄庝粈涔堟槸涓嶅畨鍏鐨勪緥瀛愶細

shell> mysqlbinlog hostname-bin.000001 | mysql # DANGER!!
shell> mysqlbinlog hostname-bin.000002 | mysql # DANGER!!

浣跨敤涓庢湇鍔″櫒鐨勪笉鍚岃繛鎺ユ潵澶勭悊浜岃繘鍒舵棩蹇楁椂锛屽鏋滅1涓棩蹇楁枃浠跺寘鍚竴涓CREATE TEMPORARY TABLE璇彞锛岀2涓棩蹇楀寘鍚竴涓娇鐢ㄨ涓存椂琛ㄧ殑璇彞锛屽垯浼氶犳垚闂銆傚綋绗1mysql杩涚▼缁撴潫鏃讹紝鏈嶅姟鍣ㄦ挙閿涓存椂琛ㄣ傚綋绗2mysql杩涚▼鎯充娇鐢ㄨ琛ㄦ椂锛屾湇鍔″櫒鎶ュ憡 鈥滀笉鐭ラ亾璇鈥濄

瑕佹兂閬垮厤姝ょ被闂锛屼娇鐢ㄤ竴涓繛鎺ユ潵鎵ц鎯宠澶勭悊鐨勬墍鏈変簩杩涘埗鏃ュ織涓殑鍐呭銆備笅闈㈡彁渚涗簡涓绉嶆柟娉曪細

shell> mysqlbinlog hostname-bin.000001 hostname-bin.000002 | mysql

鍙︿竴涓柟娉曟槸锛

shell> mysqlbinlog hostname-bin.000001 >  /tmp/statements.sql
shell> mysqlbinlog hostname-bin.000002 >> /tmp/statements.sql
shell> mysql -e "source /tmp/statements.sql"

mysqlbinlog浜х敓鐨勮緭鍑哄彲浠ヤ笉闇瑕佸師鏁版嵁鏂囦欢鍗冲彲閲嶆柊鐢熸垚涓涓LOAD DATA INFILE鎿嶄綔銆mysqlbinlog灏嗘暟鎹鍒跺埌涓涓复鏃舵枃浠跺苟鍐欎竴涓紩鐢ㄨ鏂囦欢鐨LOAD DATA LOCAL INFILE璇彞銆傜敱绯荤粺纭畾鍐欏叆杩欎簺鏂囦欢鐨勭洰褰曠殑榛樿浣嶇疆銆傝鎯虫樉寮忔寚瀹氫竴涓洰褰曪紝浣跨敤--local-load閫夐」銆

鍥犱负mysqlbinlog鍙互灏LOAD DATA INFILE璇彞杞崲涓LOAD DATA LOCAL INFILE璇彞(涔熷氨鏄锛屽畠娣诲姞浜LOCAL)锛岀敤浜庡鐞嗚鍙ョ殑瀹㈡埛绔拰鏈嶅姟鍣ㄥ繀椤婚厤缃负鍏佽LOCAL鎿嶄綔銆傚弬瑙5.6.4鑺傦紝鈥淟OAD DATA LOCAL瀹夊叏闂

璀﹀憡锛LOAD DATA LOCAL璇彞鍒涘缓鐨勪复鏃舵枃浠朵笉浼氳嚜鍔ㄥ垹闄わ紝鍥犱负鍦ㄥ疄闄呮墽琛屽畬閭d簺璇彞鍓嶉渶瑕佸畠浠備笉鍐嶉渶瑕佽鍙ユ棩蹇楀悗搴旇嚜宸卞垹闄や复鏃舵枃浠躲傛枃浠朵綅浜庝复鏃舵枃浠剁洰褰曚腑锛屾枃浠跺悕绫讳技original_file_name-#-#

--hexdump閫夐」鍙互鍦ㄦ敞閲婁腑浜х敓鏃ュ織鍐呭鐨勫崄鍏繘鍒惰浆鍌細

shell> mysqlbinlog --hexdump master-bin.000001

涓婅堪鍛戒护鐨勮緭鍑哄簲绫讳技锛

/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
# at 4
#051024 17:24:13 server id 1  end_log_pos 98
# Position  Timestamp   Type   Master ID        Size      Master Pos    Flags
# 00000004 9d fc 5c 43   0f   01 00 00 00   5e 00 00 00   62 00 00 00   00 00
# 00000017 04 00 35 2e 30 2e 31 35  2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
# 00000027 6f 67 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |og..............|
# 00000037 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |................|
# 00000047 00 00 00 00 9d fc 5c 43  13 38 0d 00 08 00 12 00 |.......C.8......|
# 00000057 04 04 04 04 12 00 00 4b  00 04 1a                |.......K...|
#       Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
#       at startup
ROLLBACK;

鍗佸叚杩涘埗杞偍鐨勮緭鍑哄寘鍚笅闈㈢殑鍏冪礌锛

         Position: The byte position within the log file.

         Timestamp: The event timestamp. In the example just shown, '9d fc 5c 43' is the representation of '051024 17:24:13' in hexadecimal.

         Type: The type of the log event. '0f' means that the example event is a FORMAT_DESCRIPTION_EVENT. The types are:

                00  UNKNOWN_EVENT
                    This event should never be present in the log.
                01  START_EVENT_V3
                    This indicates the start of a log file written by MySQL 4 or earlier.
                02  QUERY_EVENT
                    The most common type of events.  These contain queries executed
                    on the master.
                03  STOP_EVENT
                    Indicates that master has stopped.
                04  ROTATE_EVENT
                    Written when the master switches to a new log file.
                05  INTVAR_EVENT
                    Used mainly for AUTO_INCREMENT values and if the LAST_INSERT_ID()
                    function is used in the statement.
                06  LOAD_EVENT
                    Used for LOAD DATA INFILE in MySQL 3.23.
                07  SLAVE_EVENT
                    Reserved for future use.
                08  CREATE_FILE_EVENT
                    Used for LOAD DATA INFILE statements.  This indicates the start
                    of execution of such a statement.  A temporary file is created
                    on the slave.  Used in MySQL 4 only.
                09  APPEND_BLOCK_EVENT
                    Contains data for use in a LOAD DATA INFILE statement.  The
                    data is stored in the temporary file on the slave.
                0a  EXEC_LOAD_EVENT
                    Used for LOAD DATA INFILE statements.  The contents of the
                    temporary file is stored in the table on the slave.
                    Used in MySQL 4 only.
                0b  DELETE_FILE_EVENT
                    Rollback of LOAD DATA INFILE statement.  The temporary file
                    should be deleted on slave.
                0c  NEW_LOAD_EVENT
                    Used for LOAD DATA INFILE in MySQL 4 and earlier.
                0d  RAND_EVENT
                    Used to send information about random values if the RAND()
                    function is used in the query.
                0e  USER_VAR_EVENT
                    Used to replicate user variables.
                0f  FORMAT_DESCRIPTION_EVENT
                    This indicates the start of a log file written by MySQL 5 or later.
                10  XID_EVENT
                    Event indicating commit of XA transaction
                11  BEGIN_LOAD_QUERY_EVENT
                    Used for LOAD DATA statements in MySQL 5 and later.
                12  EXECUTE_LOAD_QUERY_EVENT
                    Used for LOAD DATA statements in MySQL 5 and later.
                13  TABLE_MAP_EVENT
                    Reserved for future use
                14  WRITE_ROWS_EVENT
                    Reserved for future use
                15  UPDATE_ROWS_EVENT
                    Reserved for future use
                16  DELETE_ROWS_EVENT
                    Reserved for future use

         Master ID: The server id of the master that created the event.

         Size: The size in bytes of the event.

         Master Pos: The position of the event in the original master log file.

         Flags: 16 flags.

                01  LOG_EVENT_BINLOG_IN_USE_F
                    Log file correctly closed (Used only in FORMAT_DESCRIPTION_EVENT)
                    If this flag is set (if the flags are e.g. '01 00') in an
                    FORMAT_DESCRIPTION_EVENT, then the log file has not been
                    properly closed.  Most probably because of a master crash (for
                    example, due to power failure).
                02  Reserved for future use.
                04  LOG_EVENT_THREAD_SPECIFIC_F
                    Set if the event is dependent on the connection it was
                    executed in (example '04 00'), e.g. if the event uses
                    temporary tables.
                08  LOG_EVENT_SUPPRESS_USE_F
                    Set in some circumstances when the event is not dependent on
                    the current database

鍏跺畠鏍囧織淇濈暀鐢ㄤ簬灏嗘潵浣跨敤銆

鍦ㄤ互鍚庣殑鐗堟湰涓崄鍏繘鍒惰浆鍌ㄨ緭鍑虹殑鏍煎紡鍙兘浼氭敼鍙樸

8.7. mysqlcheck锛氳〃缁存姢鍜岀淮淇▼搴

mysqlcheck瀹㈡埛绔彲浠ユ鏌ュ拰淇MyISAM琛ㄣ傚畠杩樺彲浠ヤ紭鍖栧拰鍒嗘瀽琛ㄣ

mysqlcheck鐨勫姛鑳界被浼myisamchk锛屼絾鍏跺伐浣滀笉鍚屻備富瑕佸樊鍒槸褰mysqld鏈嶅姟鍣ㄥ湪杩愯鏃跺繀椤讳娇鐢mysqlcheck锛岃myisamchk搴旂敤浜庢湇鍔″櫒娌℃湁杩愯鏃躲備娇鐢mysqlcheck濂藉鏄笉闇瑕佸仠姝㈡湇鍔″櫒鏉ユ鏌ユ垨淇琛ㄣ

Mysqlcheck涓虹敤鎴锋彁渚涗簡涓绉嶆柟渚跨殑浣跨敤SQL璇彞CHECK TABLEREPAIR TABLEANALYZE TABLEOPTIMIZE TABLE鐨勬柟寮忋傚畠纭畾鍦ㄨ鎵ц鐨勬搷浣滀腑浣跨敤浣跨敤鍝釜璇彞锛岀劧鍚庡皢璇彞鍙戦佸埌瑕佹墽琛岀殑鏈嶅姟鍣ㄤ笂銆

3绉嶆柟寮忔潵璋冪敤mysqlcheck

shell> mysqlcheck[options] db_name [tables]
shell> mysqlcheck[options] ---database DB1 [DB2 DB3...]
shell> mysqlcheck[options] --all--database

濡傛灉娌℃湁鎸囧畾浠讳綍琛ㄦ垨浣跨敤---database--all--database閫夐」锛屽垯妫鏌ユ暣涓暟鎹簱銆

鍚屽叾瀹冨鎴风姣旇緝锛mysqlcheck鏈変竴涓壒娈婄壒鎬с傞噸鏂板懡鍚嶄簩杩涘埗鍙互鏇存敼妫鏌ヨ〃鐨勯粯璁よ涓(--check)銆傚鏋滀綘鎯宠涓涓伐鍏烽粯璁ゅ彲浠ヤ慨澶嶈〃鐨勫伐鍏凤紝鍙渶瑕佸皢mysqlcheck閲嶆柊澶嶅埗涓mysqlrepair锛屾垨鑰呬娇鐢ㄤ竴涓鍙烽摼鎺mysqlrepair閾炬帴mysqlcheck銆傚鏋滆皟鐢mysqlrepair锛屽彲鎸夌収鍛戒护淇琛ㄣ

涓嬮潰鐨勫悕鍙敤鏉ユ洿鏀mysqlcheck鐨勯粯璁よ涓猴細

mysqlrepair

榛樿閫夐」涓--repair

mysqlanalyze

榛樿閫夐」涓--analyze

mysqloptimize

榛樿閫夐」涓--optimize

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

         ---help-

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

         --all--database-A

妫鏌ユ墍鏈夋暟鎹簱涓殑鎵鏈夎〃銆備笌浣跨敤---database閫夐」鐩稿悓锛屽湪鍛戒护琛屼腑鍛藉悕鎵鏈夋暟鎹簱銆

         --all-in-1-1

涓嶆槸涓烘瘡涓〃鍙戝嚭涓涓鍙ワ紝鑰屾槸涓哄懡鍚嶆暟鎹簱涓緟澶勭悊鐨勬墍鏈夎〃鐨勬瘡涓暟鎹簱鎵ц涓涓鍙ャ

         --analyze-a

鍒嗘瀽琛ㄣ

         --auto-repair

濡傛灉鏌愪釜琚鏌ョ殑琛ㄧ牬鍧忎簡锛岃嚜鍔ㄤ慨澶嶅畠銆傛鏌ュ畬鎵鏈夎〃鍚庤嚜鍔ㄨ繘琛屾墍鏈夐渶瑕佺殑淇銆

         --character-sets-dir=path

瀛楃闆嗙殑瀹夎鐩綍銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --check-c

妫鏌ヨ〃鐨勯敊璇

         --check-only-changed-C

鍙鏌ヤ笂娆℃鏌ヤ互鏉ュ凡缁忔洿鏀圭殑鎴栨病鏈夋纭叧闂殑琛ㄣ

         --compress

鍘嬬缉鍦ㄥ鎴风鍜屾湇鍔″櫒涔嬮棿鍙戦佺殑鎵鏈変俊鎭紙濡傛灉浜岃呭潎鏀寔鍘嬬缉锛夈

         ---database-B

澶勭悊鏁版嵁搴撲腑鍛藉悕鐨勬墍鏈夎〃銆備娇鐢ㄨ閫夐」锛屾墍鏈夊瓧鍚嶅弬閲忚鐪嬩綔鏁版嵁搴撳悕锛岃屼笉鏄〃鍚嶃

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父涓'd:t:o,file_name'

         --default-character-set=charset

浣跨敤charsetas榛樿瀛楃闆嗐傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --extended-e

濡傛灉浣犳浣跨敤璇ラ夐」鏉ユ鏌ヨ〃锛屽彲浠ョ‘淇濆畠浠100%鍦颁竴鑷达紝浣嗛渶瑕佸緢闀跨殑鏃堕棿銆

濡傛灉浣犳浣跨敤璇ラ夐」鏉ヤ慨澶嶈〃锛屽垯杩愯鎵╁睍淇锛屼笉浣嗘墽琛岀殑鏃堕棿寰堥暱锛岃屼笖杩樹細浜х敓澶ч噺鐨勫瀮鍦捐!

         --fast-F

鍙鏌ユ病鏈夋纭叧闂殑琛ㄣ

         --force-f

鍗充娇鍑虹幇SQL閿欒涔熺户缁

         --host=host_name-h host_name

杩炴帴缁欏畾涓绘満涓婄殑MySQL鏈嶅姟鍣ㄣ

         --medium-check-m

鎵ц姣--extended鎿嶄綔鏇村揩鐨勬鏌ャ傚彧鑳藉彂鐜99.99%鐨勯敊璇紝鍦ㄥぇ澶氭暟鎯呭喌涓嬭繖宸茬粡瓒冲浜嗐

         --optimize-o

浼樺寲琛ㄣ

         --password[=password]-p[password]

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑瀵嗙爜銆傚鏋滀娇鐢ㄧ煭閫夐」褰㈠紡(-p)锛岄夐」鍜 瀵嗙爜涔嬮棿涓嶈兘鏈夌┖鏍笺傚鏋滃湪鍛戒护琛屼腑--password-p閫夐」鍚庨潰娌℃湁 瀵嗙爜鍊硷紝鍒欐彁绀鸿緭鍏ヤ竴涓瘑鐮併

         --port=port_num-P port_num

鐢ㄤ簬杩炴帴鐨TCP/IP绔彛鍙枫

         --protocol={TCP | SOCKET | PIPE | MEMORY}

浣跨敤鐨勮繛鎺ュ崗璁

         --quick-q

濡傛灉浣犳浣跨敤璇ラ夐」鍦ㄦ鏌ヨ〃锛屽畠闃叉鎵弿琛屼互妫鏌ラ敊璇摼鎺ョ殑妫鏌ャ傝繖鏄渶蹇殑妫鏌ユ柟娉曘

濡傛灉浣犳浣跨敤璇ラ夐」鍦ㄤ慨澶嶈〃锛屽畠灏濊瘯鍙慨澶嶇储寮曟爲銆傝繖鏄渶蹇殑淇鏂规硶銆

         --repair-r

鎵ц鍙互淇澶ч儴鍒嗛棶棰樼殑淇锛屽彧鏄敮涓鍊间笉鍞竴鏃朵笉鑳戒慨澶嶃

         --silent-s

娌夐粯妯″紡銆傚彧鎵撳嵃閿欒娑堟伅銆

         --socket=path-S path

鐢ㄤ簬杩炴帴鐨勫鎺ュ瓧鏂囦欢銆

         --tables

瑕嗙洊---database-B閫夐」銆傞夐」鍚庨潰鐨勬墍鏈夊弬閲忚瑙嗕负琛ㄥ悕銆

         --user=user_name-u user_name

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑MySQL鐢ㄦ埛鍚嶃

         --verbose-v

鍐楅暱妯″紡銆傛墦鍗板叧浜庡悇闃舵绋嬪簭鎿嶄綔鐨勪俊鎭

         --version-V

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

8.8. mysqldump锛氭暟鎹簱澶囦唤绋嬪簭

mysqldump瀹㈡埛绔彲鐢ㄦ潵杞偍鏁版嵁搴撴垨鎼滈泦鏁版嵁搴撹繘琛屽浠芥垨灏嗘暟鎹浆绉诲埌鍙︿竴涓SQL鏈嶅姟鍣(涓嶄竴瀹氭槸涓涓MySQL鏈嶅姟鍣)銆傝浆鍌ㄥ寘鍚垱寤鸿〃鍜/鎴栬杞借〃鐨SQL璇彞銆

濡傛灉浣犲湪鏈嶅姟鍣ㄤ笂杩涜澶囦唤锛屽苟涓旇〃鍧囦负MyISAM琛紝搴旇冭檻浣跨敤mysqlhotcopy锛屽洜涓哄彲浠ユ洿蹇湴杩涜澶囦唤鍜屾仮澶嶃傚弬瑙8.9鑺傦紝鈥渕ysqlhotcopy锛氭暟鎹簱澶囦唤绋嬪簭鈥

3绉嶆柟寮忔潵璋冪敤mysqldump

shell> mysqldump [options] db_name [tables]
shell> mysqldump [options] ---database DB1 [DB2 DB3...]
shell> mysqldump [options] --all--database

濡傛灉娌℃湁鎸囧畾浠讳綍琛ㄦ垨浣跨敤浜---database--all--database閫夐」锛屽垯杞偍鏁翠釜鏁版嵁搴撱

瑕佹兂鑾峰緱浣犵殑鐗堟湰鐨mysqldump鏀寔鐨勯夐」锛屾墽琛mysqldump ---help

濡傛灉杩愯mysqldump娌℃湁--quick--opt閫夐」锛mysqldump鍦ㄨ浆鍌ㄧ粨鏋滃墠灏嗘暣涓粨鏋滈泦瑁呭叆鍐呭瓨銆傚鏋滆浆鍌ㄥぇ鏁版嵁搴撳彲鑳戒細鍑虹幇闂銆傝閫夐」榛樿鍚敤锛屼絾鍙互鐢--skip-opt绂佺敤銆

濡傛灉浣跨敤鏈鏂扮増鏈殑mysqldump绋嬪簭鐢熸垚涓涓浆鍌ㄩ噸瑁呭埌寰堟棫鐗堟湰鐨MySQL鏈嶅姟鍣ㄤ腑锛屼笉搴斾娇鐢--opt-e閫夐」銆

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

         ---help-

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

         --add-drop--database

鍦ㄦ瘡涓CREATE DATABASE璇彞鍓嶆坊鍔DROP DATABASE璇彞銆

         --add-drop-tables

鍦ㄦ瘡涓CREATE TABLE璇彞鍓嶆坊鍔DROP TABLE璇彞銆

         --add-locking

LOCK TABLESUNLOCK TABLES璇彞寮曠敤姣忎釜琛ㄨ浆鍌ㄣ傞噸杞借浆鍌ㄦ枃浠舵椂鎻掑叆寰楁洿蹇傚弬瑙7.2.16鑺傦紝鈥淚NSERT璇彞鐨勯熷害鈥

         --all--database-A

杞偍鎵鏈夋暟鎹簱涓殑鎵鏈夎〃銆備笌浣跨敤---database閫夐」鐩稿悓锛屽湪鍛戒护琛屼腑鍛藉悕鎵鏈夋暟鎹簱銆

         --allow-keywords

鍏佽鍒涘缓鍏抽敭瀛楀垪鍚嶃傚簲鍦ㄦ瘡涓垪鍚嶅墠闈㈠姞涓婅〃鍚嶅墠缂銆

         ---comments[={0|1}]

濡傛灉璁剧疆涓 0锛岀姝㈣浆鍌ㄦ枃浠朵腑鐨勫叾瀹冧俊鎭紝渚嬪绋嬪簭鐗堟湰銆佹湇鍔″櫒鐗堟湰鍜屼富鏈恒--skipcomments---comments=0鐨勭粨鏋滅浉鍚屻 榛樿鍊间负1锛屽嵆鍖呮嫭棰濆淇℃伅銆

         --compact

浜х敓灏戦噺杈撳嚭銆傝閫夐」绂佺敤娉ㄩ噴骞跺惎鐢--skip-add-drop-tables--no-set-names--skip-disable-keys--skip-add-locking閫夐」銆

         --compatible=name

浜х敓涓庡叾瀹冩暟鎹簱绯荤粺鎴栨棫鐨MySQL鏈嶅姟鍣ㄦ洿鍏煎鐨勮緭鍑恒傚煎彲浠ヤ负ansimysql323mysql40postgresqloraclemssqldb2maxdbno_key_optionsno_tables_options鎴栬no_field_options銆傝浣跨敤鍑犱釜鍊硷紝鐢ㄩ楀彿灏嗗畠浠殧寮銆傝繖浜涘间笌璁剧疆鏈嶅姟鍣SQL妯″紡鐨勭浉搴旈夐」鏈夌浉鍚岀殑鍚箟銆傚弬瑙5.3.2鑺傦紝鈥淪QL鏈嶅姟鍣ㄦā寮忊

璇ラ夐」涓嶈兘淇濊瘉鍚屽叾瀹冩湇鍔″櫒涔嬮棿鐨勫吋瀹规с傚畠鍙惎鐢ㄩ偅浜涚洰鍓嶈兘澶熶娇杞偍杈撳嚭鏇村吋瀹圭殑SQL妯″紡鍊笺備緥濡傦紝--compatible=oracle 涓嶆槧灏Oracle绫诲瀷鎴栦娇鐢Oracle娉ㄩ噴璇硶鐨勬暟鎹被鍨嬨

         --complete-insert-c

浣跨敤鍖呮嫭鍒楀悕鐨勫畬鏁寸殑INSERT璇彞銆

         --compress-C

鍘嬬缉鍦ㄥ鎴风鍜屾湇鍔″櫒涔嬮棿鍙戦佺殑鎵鏈変俊鎭紙濡傛灉浜岃呭潎鏀寔鍘嬬缉锛夈

         --create-option

CREATE TABLE璇彞涓寘鎷墍鏈MySQL琛ㄩ夐」銆

         ---database-B

杞偍鍑犱釜鏁版嵁搴撱傞氬父鎯呭喌锛mysqldump灏嗗懡浠よ涓殑绗1涓悕瀛楀弬閲忕湅浣滄暟鎹簱鍚嶏紝鍚庨潰鐨勫悕鐪嬩綔琛ㄥ悕銆備娇鐢ㄨ閫夐」锛屽畠灏嗘墍鏈夊悕瀛楀弬閲忕湅浣滄暟鎹簱鍚嶃CREATE DATABASE IF NOT EXISTS db_nameUSE db_name璇彞鍖呭惈鍦ㄦ瘡涓柊鏁版嵁搴撳墠鐨勮緭鍑轰腑銆

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父涓'd:t:o,file_name'

         --default-character-set=charset

浣跨敤charsetas榛樿瀛楃闆嗐傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥銆傚鏋滄病鏈夋寚瀹氾紝mysqldump浣跨敤utf8

         --delayed-insert

浣跨敤INSERT DELAYED璇彞鎻掑叆琛屻

         --delete-master-logs

鍦ㄤ富澶嶅埗鏈嶅姟鍣ㄤ笂锛屽畬鎴愯浆鍌ㄦ搷浣滃悗鍒犻櫎浜岃繘鍒舵棩蹇椼傝閫夐」鑷姩鍚敤--master-data

         --disable-keys-K

瀵逛簬姣忎釜琛紝鐢/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;璇彞寮曠敤INSERT璇彞銆傝繖鏍峰彲浠ユ洿蹇湴瑁呰浇杞偍鏂囦欢锛屽洜涓哄湪鎻掑叆鎵鏈夎鍚庡垱寤虹储寮曘傝閫夐」鍙傚悎MyISAM琛ㄣ

         --extended-insert-e

浣跨敤鍖呮嫭鍑犱釜VALUES鍒楄〃鐨勫琛INSERT璇硶銆傝繖鏍蜂娇杞偍鏂囦欢鏇村皬锛岄噸杞芥枃浠舵椂鍙互鍔犻熸彃鍏ャ

         --fields-terminated-by=...--fields-enclosed-by=...--fields-optionally-enclosed-by=...--fields-escaped-by=...---terminated-by=...

杩欎簺閫夐」缁撳悎-T閫夐」浣跨敤锛屼笌LOAD DATA INFILE鐨勭浉搴斿瓙鍙ユ湁鐩稿悓鐨勫惈涔夈傚弬瑙13.2.5鑺傦紝鈥淟OAD DATA INFILE璇硶鈥

         --first-slave-x

涓嶈禐鎴愪娇鐢紝鐜板湪閲嶆柊鍛藉悕涓--lock-all-tables

         --flush-logs-F

寮濮嬭浆鍌ㄥ墠鍒锋柊MySQL鏈嶅姟鍣ㄦ棩蹇楁枃浠躲傝閫夐」瑕佹眰RELOAD鏉冮檺銆傝娉ㄦ剰濡傛灉缁撳悎--all--database(-A)閫夐」浣跨敤璇ラ夐」锛鏍规嵁姣忎釜杞偍鐨勬暟鎹簱鍒锋柊鏃ュ織銆備緥澶栨儏鍐垫槸褰撲娇鐢--lock-all-tables--master-data鐨勬椂鍊欙細鍦ㄨ繖绉嶆儏鍐典笅锛屾棩蹇楀彧鍒锋柊涓娆★紝鍦ㄦ墍鏈 琛ㄨ閿佸畾鍚庡埛鏂般傚鏋滀綘鎯宠鍚屾椂杞偍鍜屽埛鏂版棩蹇楋紝搴斾娇鐢--flush-logs杩炲悓--lock-all-tables--master-data

         --force-f

鍦ㄨ〃杞偍杩囩▼涓紝鍗充娇鍑虹幇SQL閿欒涔熺户缁

         --host=host_name-h host_name

浠庣粰瀹氫富鏈虹殑MySQL鏈嶅姟鍣ㄨ浆鍌ㄦ暟鎹傞粯璁や富鏈烘槸localhost

         --hex-blob

浣跨敤鍗佸叚杩涘埗绗﹀彿杞偍浜岃繘鍒跺瓧绗︿覆鍒(渚嬪锛'abc' 鍙樹负0x616263)銆傚奖鍝嶅埌鐨勫垪鏈BINARYVARBINARYBLOB

         --lock-all-tables-x

鎵鏈夋暟鎹簱涓殑鎵鏈夎〃鍔犻攣銆傚湪鏁翠綋杞偍杩囩▼涓氳繃鍏ㄥ眬璇婚攣瀹氭潵瀹炵幇銆傝閫夐」鑷姩鍏抽棴--single-transaction--lock-tables

         --lock-tables-l

寮濮嬭浆鍌ㄥ墠閿佸畾鎵鏈夎〃銆傜敤READ LOCAL閿佸畾琛ㄤ互鍏佽骞惰鎻掑叆MyISAM琛ㄣ傚浜庝簨鍔¤〃渚嬪InnoDBBDB--single-transaction鏄竴涓洿濂界殑閫夐」锛屽洜涓哄畠涓嶆牴鏈渶瑕侀攣瀹氳〃銆

璇锋敞鎰忓綋杞偍澶氫釜鏁版嵁搴撴椂锛--lock-tables鍒嗗埆涓烘瘡涓暟鎹簱閿佸畾琛ㄣ傚洜姝わ紝璇ラ夐」涓嶈兘淇濊瘉杞偍鏂囦欢涓殑琛ㄥ湪鏁版嵁搴撲箣闂寸殑閫昏緫涓鑷存с備笉鍚屾暟鎹簱琛ㄧ殑杞偍鐘舵佸彲浠ュ畬鍏ㄤ笉鍚屻

         --master-data[=value]

璇ラ夐」灏嗕簩杩涘埗鏃ュ織鐨勪綅缃拰鏂囦欢鍚嶅啓鍏ュ埌杈撳嚭涓傝閫夐」瑕佹眰鏈RELOAD鏉冮檺锛屽苟涓斿繀椤诲惎鐢ㄤ簩杩涘埗鏃ュ織銆傚鏋滆閫夐」鍊肩瓑浜1锛屼綅缃拰鏂囦欢鍚嶈鍐欏叆CHANGE MASTER璇彞褰㈠紡鐨勮浆鍌ㄨ緭鍑猴紝濡傛灉浣犱娇鐢ㄨSQL杞偍涓绘湇鍔″櫒浠ヨ缃粠鏈嶅姟鍣紝浠庢湇鍔″櫒浠庝富鏈嶅姟鍣ㄤ簩杩涘埗鏃ュ織鐨勬纭綅缃紑濮嬨傚鏋滈夐」鍊肩瓑浜2CHANGE MASTER璇彞琚啓鎴SQL娉ㄩ噴銆傚鏋value琚渷鐣ワ紝杩欐槸榛樿鍔ㄤ綔銆

--master-data閫夐」鍚敤--lock-all-tables锛岄櫎闈炶繕鎸囧畾--single-transaction(鍦ㄨ繖绉嶆儏鍐典笅锛屽彧鍦ㄥ垰寮濮嬭浆鍌ㄦ椂鐭椂闂磋幏寰楀叏灞璇婚攣瀹氥傚張瑙--single-transaction銆傚湪浠讳綍涓绉嶆儏鍐典笅锛屾棩蹇楃浉鍏冲姩浣滃彂鐢熷湪杞偍鏃躲傝閫夐」鑷姩鍏抽棴--lock-tables

         --no-create-db-n

璇ラ夐」绂佺敤CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name璇彞锛屽鏋滅粰鍑---database--all--database閫夐」锛屽垯鍖呭惈鍒拌緭鍑轰腑銆

         --no-create-info-t

涓嶅啓閲嶆柊鍒涘缓姣忎釜杞偍琛ㄧ殑CREATE TABLE璇彞銆

         --no-data-d

涓嶅啓琛ㄧ殑浠讳綍琛屼俊鎭傚鏋滀綘鍙兂杞偍琛ㄧ殑缁撴瀯杩欏緢鏈夌敤銆

         --opt

璇ラ夐」鏄熻锛涚瓑鍚屼簬鎸囧畾 --add-drop-tables--add-locking --create-option --disable-keys--extended-insert --lock-tables --quick --set-charset銆傚畠鍙互缁欏嚭寰堝揩鐨勮浆鍌ㄦ搷浣滃苟浜х敓涓涓彲浠ュ緢蹇鍏MySQL鏈嶅姟鍣ㄧ殑杞偍鏂囦欢銆璇ラ夐」榛樿寮鍚紝浣嗗彲浠ョ敤--skip-opt绂佺敤銆傝鎯冲彧绂佺敤纭俊鐢-opt鍚敤鐨勯夐」锛屼娇鐢--skip褰㈠紡锛涗緥濡傦紝--skip-add-drop-tables--skip-quick

         --password[=password]-p[password]

杩炴帴鏈嶅姟鍣ㄦ椂浣跨敤鐨勫瘑鐮併傚鏋滀綘浣跨敤鐭夐」褰㈠紡(-p)涓嶈兘鍦ㄩ夐」鍜屽瘑鐮佷箣闂存湁涓涓┖鏍銆傚鏋滃湪鍛戒护琛屼腑锛屽拷鐣ヤ簡--password-p閫夐」鍚庨潰鐨 瀵嗙爜鍊硷紝灏嗘彁绀轰綘杈撳叆涓涓

         --port=port_num-P port_num

鐢ㄤ簬杩炴帴鐨TCP/IP绔彛鍙枫

         --protocol={TCP | SOCKET | PIPE | MEMORY}

浣跨敤鐨勮繛鎺ュ崗璁

         --quick-q

璇ラ夐」鐢ㄤ簬杞偍澶х殑琛ㄣ傚畠寮哄埗mysqldump浠庢湇鍔″櫒涓娆′竴琛屽湴妫绱㈣〃涓殑琛岃屼笉鏄绱㈡墍鏈夎骞跺湪杈撳嚭鍓嶅皢瀹冪紦瀛樺埌鍐呭瓨涓

         --quote-names-Q

鐢ㄢ`鈥欏瓧绗﹀紩鐢ㄦ暟鎹簱銆佽〃鍜屽垪鍚嶃傚鏋滄湇鍔″櫒SQL妯″紡鍖呮嫭ANSI_QUOTES閫夐」锛岀敤鈥"鈥欏瓧绗﹀紩鐢ㄥ悕銆傞粯璁ゅ惎鐢ㄨ閫夐」銆傚彲浠ョ敤--skip-quote-names绂佺敤锛屼絾璇ラ夐」搴旇窡鍦ㄥ叾瀹冮夐」鍚庨潰锛屼緥濡傚彲浠ュ惎鐢--quote-names--compatible

         --result-file=file-r file

灏嗚緭鍑鸿浆鍚戠粰瀹氱殑鏂囦欢銆傝閫夐」搴旂敤鍦Windows涓紝鍥犱负瀹冪姝㈠皢鏂拌鈥\n鈥欏瓧绗﹁浆鎹负鈥\r\n鈥欏洖杞︺佽繑鍥/鏂拌搴忓垪銆

         --routines-R

鍦ㄨ浆鍌ㄧ殑鏁版嵁搴撲腑杞偍瀛樺偍绋嬪簭(鍑芥暟鍜岀▼搴)銆備娇鐢---routines浜х敓鐨勮緭鍑哄寘鍚CREATE PROCEDURECREATE FUNCTION璇彞浠ラ噸鏂板垱寤哄瓙绋嬪簭銆備絾鏄紝杩欎簺璇彞涓嶅寘鎷睘鎬э紝渚嬪瀛愮▼搴忓畾涔夎呮垨鍒涘缓鍜屼慨鏀规椂闂存埑銆傝繖璇存槑褰撻噸杞藉瓙绋嬪簭鏃讹紝瀵瑰畠浠繘琛屽垱寤烘椂瀹氫箟鑰呭簲璁剧疆涓洪噸杞界敤鎴凤紝鏃堕棿鎴崇瓑浜庨噸杞芥椂闂淬

濡傛灉浣犻渶瑕佸垱寤虹殑瀛愮▼搴忎娇鐢ㄥ師鏉ョ殑瀹氫箟鑰呭拰鏃堕棿鎴冲睘鎬э紝涓嶄娇鐢--routines銆傜浉鍙嶏紝浣跨敤涓涓叿鏈mysql鏁版嵁搴撶浉搴旀潈闄愮殑MySQL璐︽埛鐩存帴杞偍鍜岄噸杞mysql.proc琛ㄧ殑鍐呭銆

璇ラ夐」鍦MySQL 5.1.2涓坊鍔犺繘鏉ャ傚湪姝や箣鍓嶏紝瀛樺偍绋嬪簭涓嶈浆鍌ㄣ

         --set-charset

SET NAMES default_character_set鍔犲埌杈撳嚭涓傝閫夐」榛樿鍚敤銆傝鎯崇鐢SET NAMES璇彞锛屼娇鐢--skip-set-charset

         --single-transaction

璇ラ夐」浠庢湇鍔″櫒杞偍鏁版嵁涔嬪墠鍙戝嚭涓涓BEGIN SQL璇彞銆傚畠鍙傜敤浜庝簨鍔¤〃锛屼緥濡InnoDBBDB锛屽洜涓虹劧鍚庡畠灏嗗湪鍙戝嚭BEGIN鑰屾病鏈夐樆濉炰换浣曞簲鐢ㄧ▼搴忔椂杞偍涓鑷寸殑鏁版嵁搴撶姸鎬併

褰撲娇鐢ㄨ閫夐」鏃讹紝搴旇浣忓彧鏈InnoDB琛ㄨ兘浠ヤ竴鑷寸殑鐘舵佽杞偍銆備緥濡傦紝浣跨敤璇ラ夐」鏃朵换浣曡浆鍌ㄧ殑MyISAMHEAP琛ㄤ粛鐒跺彲浠ユ洿鏀圭姸鎬併

--single-transaction閫夐」鍜--lock-tables閫夐」鏄簰鏂ョ殑锛屽洜涓LOCK TABLES浼氫娇浠讳綍鎸傝捣鐨勪簨鍔¢殣鍚彁浜ゃ

瑕佹兂杞偍澶х殑琛紝搴旂粨鍚--quick浣跨敤璇ラ夐」銆

         --socket=path-S path

褰撹繛鎺localhost(涓洪粯璁や富鏈)鏃朵娇鐢ㄧ殑濂楁帴瀛楁枃浠躲

         --skip--comments

鍙傝---comments閫夐」鐨勬弿杩般

         --tab=path-T path

浜х敓tab鍒嗗壊鐨勬暟鎹枃浠躲傚浜庢瘡涓浆鍌ㄧ殑琛紝mysqldump鍒涘缓涓涓寘鍚垱寤鸿〃鐨CREATE TABLE璇彞鐨tbl_name.sql鏂囦欢锛屽拰涓涓寘鍚叾鏁版嵁鐨tbl_name.txt鏂囦欢銆傞夐」鍊间负鍐欏叆鏂囦欢鐨勭洰褰曘

榛樿鎯呭喌锛.txt鏁版嵁鏂囦欢鐨勬牸寮忔槸鍦ㄥ垪鍊煎拰姣忚鍚庨潰鐨勬柊琛屼箣闂翠娇鐢tab瀛楃銆傚彲浠ヤ娇鐢--fields-xxx----xxx閫夐」鏄庢樉鎸囧畾鏍煎紡銆

娉ㄩ噴锛璇ラ夐」鍙傜敤浜mysqldumpmysqld鏈嶅姟鍣ㄥ湪鍚屼竴鍙版満鍣ㄤ笂杩愯鏃躲備綘蹇呴』鍏锋湁FILE鏉冮檺锛屽苟涓旀湇鍔″櫒蹇呴』鏈夊湪浣犳寚瀹氱殑鐩綍涓湁鍐欐枃浠剁殑璁稿彲銆

         --tables

瑕嗙洊---database-B閫夐」銆傞夐」鍚庨潰鐨勬墍鏈夊弬閲忚鐪嬩綔琛ㄥ悕銆

         --triggers

涓烘瘡涓浆鍌ㄧ殑琛ㄨ浆鍌ㄨЕ鍙戝櫒銆傝閫夐」榛樿鍚敤锛涚敤--skip-triggers绂佺敤瀹冦

         --tz-utc

鍦ㄨ浆鍌ㄦ枃浠朵腑鍔犲叆SET TIME_ZONE='+00:00'浠ヤ究TIMESTAMP鍒楀彲浠ュ湪鍏锋湁涓嶅悓鏃跺尯鐨勬湇鍔″櫒涔嬮棿杞偍鍜岄噸杞姐(涓嶄娇鐢ㄨ閫夐」锛TIMESTAMP鍒楀湪鍏锋湁鏈湴鏃跺尯鐨勬簮鏈嶅姟鍣ㄥ拰鐩殑鏈嶅姟鍣ㄤ箣闂磋浆鍌ㄥ拰閲嶈浇锛--tz-utc涔熷彲浠ヤ繚鎶ょ敱浜庡浠ゆ椂甯︽潵鐨勬洿鏀广--tz-utc榛樿鍚敤銆傝鎯崇鐢ㄥ畠锛屼娇鐢--skip-tz-utc銆傝閫夐」鍦MySQL 5.1.2涓姞鍏ャ

         --user=user_name-u user_name

杩炴帴鏈嶅姟鍣ㄦ椂浣跨敤鐨MySQL鐢ㄦ埛鍚嶃

         --verbose-v

鍐楅暱妯″紡銆傛墦鍗板嚭绋嬪簭鎿嶄綔鐨勮缁嗕俊鎭

         --version-V

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

         --where='where-condition', -w 'where-condition'

鍙浆鍌ㄧ粰瀹氱殑WHERE鏉′欢閫夋嫨鐨勮褰曘傝娉ㄦ剰濡傛灉鏉′欢鍖呭惈鍛戒护瑙i噴绗︿笓鐢ㄧ┖鏍兼垨瀛楃锛屼竴瀹氳灏嗘潯浠跺紩鐢ㄨ捣鏉ャ

渚嬪锛

"--where=user='jimf'"
"-wuserid>1"
"-wuserid<1"

         --xml-X

灏嗚浆鍌ㄨ緭鍑哄啓鎴XML

杩樺彲浠ヤ娇鐢--var_name=value閫夐」璁剧疆涓嬮潰鐨勫彉閲忥細

         max_allowed_packet

瀹㈡埛绔/鏈嶅姟鍣ㄤ箣闂撮氫俊鐨勭紦瀛樺尯鐨勬渶澶уぇ灏忋傛渶澶т负1GB

         net_buffer_length

瀹㈡埛绔/鏈嶅姟鍣ㄤ箣闂撮氫俊鐨勭紦瀛樺尯鐨勫垵濮嬪ぇ灏忋傚綋鍒涘缓澶氳鎻掑叆璇彞鏃(濡傚悓浣跨敤閫夐」--extended-insert--opt)mysqldump鍒涘缓闀垮害杈net_buffer_length鐨勮銆傚鏋滃鍔犺鍙橀噺锛岃繕搴旂‘淇濆湪MySQL鏈嶅姟鍣ㄤ腑鐨net_buffer_length鍙橀噺鑷冲皯杩欎箞澶с

杩樺彲浠ヤ娇鐢--set-variable=var_name=value-O var_name=value璇硶璁剧疆鍙橀噺銆傜劧鑰岋紝鐜板湪涓嶈禐鎴愪娇鐢ㄨ璇硶銆

mysqldump鏈甯哥敤浜庡浠戒竴涓暣涓殑鏁版嵁搴擄細

shell> mysqldump --opt db_name > backup-file.sql

浣犲彲浠ヨ繖鏍峰皢杞偍鏂囦欢璇诲洖鍒版湇鍔″櫒锛

shell> mysql db_name < backup-file.sql

鎴栬呬负锛

shell> mysql -e "source /path-to--backup/backup-file.sql" db_name

mysqldump涔熷彲鐢ㄤ簬浠庝竴涓MySQL鏈嶅姟鍣ㄥ悜鍙︿竴涓湇鍔″櫒澶嶅埗鏁版嵁鏃惰杞芥暟鎹簱锛

shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name

鍙互鐢ㄤ竴涓懡浠よ浆鍌ㄥ嚑涓暟鎹簱锛

shell> mysqldump ---database db_name1 [db_name2 ...] > my_databases.sql

濡傛灉浣犳兂瑕佽浆鍌ㄦ墍鏈夋暟鎹簱锛屼娇鐢--all--database閫夐」锛

shell> mysqldump --all-databases > all_databases.sql

濡傛灉琛ㄤ繚瀛樺湪InnoDB瀛樺偍寮曟搸涓紝mysqldump鎻愪緵浜嗕竴绉嶈仈鏈哄浠界殑閫斿緞(鍙傝涓嬮潰鐨勫懡浠)銆傝澶囦唤鍙渶瑕佸湪寮濮嬭浆鍌ㄦ椂瀵规墍鏈夎〃杩涜鍏ㄥ眬璇婚攣瀹(浣跨敤FLUSH TABLES WITH READ LOCK)銆傝幏寰楅攣瀹氬悗锛岃鍙栦簩杩涘埗鏃ュ織鐨勭浉搴斿唴瀹瑰苟灏嗛攣閲婃斁銆傚洜姝ゅ鏋滃苟涓斿彧鏈夊綋鍙戝嚭FLUSH...鏃舵鎵ц涓涓暱鐨勬洿鏂拌鍙ワ紝MySQL鏈嶅姟鍣ㄦ墠鍋滄鐩村埌闀胯鍙ョ粨鏉燂紝鐒跺悗杞偍鍒欓噴鏀鹃攣銆傚洜姝ゅ鏋MySQL鏈嶅姟鍣ㄥ彧鎺ユ敹鍒扮煭("鐭墽琛屾椂闂")鐨勬洿鏂拌鍙ワ紝鍗充娇鏈夊ぇ閲忕殑璇彞锛屼篃涓嶄細娉ㄦ剰鍒伴攣鏈熼棿銆

shell> mysqldump --all-databases --single-transaction > all_databases.sql

瀵逛簬鐐瑰鐐规仮澶(涔熺О涓衡滃墠婊氣濓紝褰撲綘闇瑕佹仮澶嶆棫鐨勫浠藉苟閲嶆斁璇ュ浠戒互鍚庣殑鏇存敼鏃)锛屽惊鐜簩杩涘埗鏃ュ織(鍙傝5.11.3鑺傦紝鈥滀簩杩涘埗鏃ュ織鈥)鎴栬嚦灏戠煡閬撹浆鍌ㄥ搴旂殑浜岃繘鍒舵棩蹇楀唴瀹瑰緢鏈夌敤锛

shell> mysqldump --all-databases --master-data=2 > all_databases.sql
shell> mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql

濡傛灉琛ㄤ繚瀛樺湪InnoDB瀛樺偍寮曟搸涓紝鍚屾椂浣跨敤--master-data--single-transaction鎻愪緵浜嗕竴涓緢鏂逛究鐨勬柟寮忔潵杩涜閫傚悎鐐瑰鐐规仮澶嶇殑鑱旀満澶囦唤銆

鍏充簬澶囦唤鐨勮缁嗕俊鎭紝鍙傝5.9.1鑺傦紝鈥滄暟鎹簱澶囦唤鈥

8.9. mysqlhotcopy锛氭暟鎹簱澶囦唤绋嬪簭

mysqlhotcopy鏄竴涓Perl鑴氭湰锛屾渶鍒濈敱Tim Bunce缂栧啓骞舵彁渚涖傚畠浣跨敤LOCK TABLESFLUSH TABLEScpscp鏉ュ揩閫熷浠芥暟鎹簱銆傚畠鏄浠芥暟鎹簱鎴栧崟涓〃鐨勬渶蹇殑閫斿緞锛屼絾瀹冨彧鑳借繍琛屽湪鏁版嵁搴撶洰褰曟墍鍦ㄧ殑鏈哄櫒涓娿mysqlhotcopy鍙敤浜庡浠MyISAM銆傚畠杩愯鍦UnixNetWare涓

shell> mysqlhotcopy db_name [/path/to/new_directory]
shell> mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory

澶囦唤缁欏畾鏁版嵁搴撲腑鐨勫尮閰嶆鍒欒〃杈惧紡鐨勮〃锛

shell> mysqlhotcopy db_name./regex/

鍔犱笂鍙戦煶绗(~)鍓嶇紑锛岃〃鍚嶇殑姝e垯琛ㄨ揪寮忓彲浠ヨ鍚﹀畾锛

shell> mysqlhotcopy db_name./~regex/

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

         ---help-

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

         --allowold

濡傛灉鐩爣瀛樺湪涓嶆斁寮(鍔犱笂涓涓_old鍚庣紑閲嶆柊鍛藉悕瀹)

         --checkpoint=db_name.tbl_name

鍦ㄦ寚瀹氱殑db_name.tbl_name鎻掑叆妫鏌ョ偣鏉$洰銆

         ---debug

鍚敤璋冭瘯杈撳嚭銆

         --dryrun-n

鎶ュ憡鍔ㄤ綔鑰屼笉鎵ц瀹冧滑銆

         --flushlog

鎵鏈夎〃閿佸畾鍚庡埛鏂版棩蹇椼

         --keepold

瀹屾垚鍚庝笉鍒犻櫎浠ュ墠(閲嶆柊鍛藉悕鐨)鐨勭洰鏍囥

         -- method=command

澶嶅埗鏂规硶(cpscp)

         --noindices

澶囦唤涓笉鍖呮嫭鍏ㄩ儴绱㈠紩鏂囦欢銆傝繖鏍蜂娇澶囦唤鏇村皬銆佹洿蹇傚彲浠ュ湪浠ュ悗鐢myisamchk -rq閲嶆柊鏋勫缓绱㈠紩銆

         --password=password-p password

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑瀵嗙爜銆傝娉ㄦ剰璇ラ夐」鐨勫瘑鐮佸兼槸涓嶅彲閫夌殑锛屼笉璞″叾瀹MySQL绋嬪簭銆

         --port=port_num-P port_num

褰撹繛鎺ユ湰鍦版湇鍔″櫒鏃朵娇鐢ㄧ殑TCP/IP绔彛鍙枫

         --quiet-q

闄や簡鍑虹幇閿欒鏃朵繚鎸佹矇榛樸

         --regexp=expr

澶嶅埗鎵鏈夋暟鎹簱鍚嶅尮閰嶇粰鍑虹殑姝e垯琛ㄨ揪寮忕殑鏁版嵁搴撱

         --socket=path-S path

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

         --suffix=str

鎵澶嶅埗鐨勬暟鎹簱鍚嶇殑鍚庣紑銆

         --tmpdir=path

涓存椂鐩綍(浠f浛/tmp)

         --user=user_name-u user_name

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑MySQL鐢ㄦ埛鍚嶃

mysqlhotcopy浠庨夐」鏂囦欢璇诲彇[client][mysqlhotcopy]閫夐」缁勩

瑕佹兂鎵цmysqlhotcopy锛屼綘蹇呴』鍙互璁块棶澶囦唤鐨勮〃鏂囦欢锛屽叿鏈夐偅浜涜〃鐨SELECT鏉冮檺鍜RELOAD鏉冮檺(浠ヤ究鑳藉鎵цFLUSH TABLES)

浣跨敤perldoc璋冪敤鍏跺畠mysqlhotcopy鏂囨。锛

shell> perldoc mysqlhotcopy

8.10. mysqlimport锛氭暟鎹鍏ョ▼搴

mysqlimport瀹㈡埛绔彁渚涗簡LOAD DATA INFILEQL璇彞鐨勪竴涓懡浠よ鎺ュ彛銆mysqlimport鐨勫ぇ澶氭暟閫夐」鐩存帴瀵瑰簲LOAD DATA INFILE瀛愬彞銆傚弬瑙13.2.5鑺傦紝鈥淟OAD DATA INFILE璇硶鈥

杩欐牱璋冪敤mysqlimport

shell> mysqlimport [options] db_name textfile1 [textfile2 ...]

瀵逛簬鍦ㄥ懡浠よ涓懡鍚嶇殑姣忎釜鏂囨湰鏂囦欢锛mysqlimport鍘绘帀鏂囦欢鍚嶇殑鎵╁睍鍚嶅苟浣跨敤缁撴灉鏉ョ‘瀹氬皢瀵煎叆鏂囦欢鍐呭鐨勮〃鍚嶃備緥濡傦紝鏂囦欢 patient.txtpatient.textpatient鍧囧皢瀵煎叆琛patient

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

         ---help-

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

         --columns=column_list, -c column_list

璇ラ夐」閲囩敤鐢ㄩ楀彿鍒嗛殧鐨勫垪鍚嶄綔涓哄叾鍊笺傚垪鍚嶇殑椤哄簭鎸囩ず濡備綍鍖归厤鏁版嵁鏂囦欢鍒楀拰琛ㄥ垪銆

         --compress-C

鍘嬬缉鍦ㄥ鎴风鍜屾湇鍔″櫒涔嬮棿鍙戦佺殑鎵鏈変俊鎭紙濡傛灉浜岃呭潎鏀寔鍘嬬缉锛夈

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父鏄'd:t:o,file_name'

         --delete-D

瀵煎叆鏂囨湰鏂囦欢鍓嶆竻绌鸿〃銆

         --fields-terminated-by=...--fields-enclosed-by=...--fields-optionally-enclosed-by=...--fields-escaped-by=...--lines-terminated-by=...

杩欎簺閫夐」涓LOAD DATA INFILE鐩稿簲瀛愬彞鐨勫惈涔夌浉鍚屻傚弬瑙13.2.5鑺傦紝鈥淟OAD DATA INFILE璇硶鈥

         --force-f

蹇借閿欒銆備緥濡傦紝濡傛灉鏌愪釜鏂囨湰鏂囦欢鐨勮〃涓嶅瓨鍦紝缁х画澶勭悊鍏跺畠鏂囦欢銆備笉浣跨敤--force锛屽鏋滆〃涓嶅瓨鍦ㄥ垯mysqlimport閫鍑恒

         --host=host_name-h host_name

灏嗘暟鎹鍏ョ粰瀹氫富鏈轰笂鐨MySQL鏈嶅姟鍣ㄣ傞粯璁や富鏈烘槸localhost

         --ignore-i

鍙傝--replace閫夐」鐨勬弿杩般

         --ignore-lines=n

蹇借鏁版嵁鏂囦欢鐨勫墠n琛屻

         --local-L

浠庢湰鍦板鎴风璇诲叆杈撳叆鏂囦欢銆

         --lock-tables-l

澶勭悊鏂囨湰鏂囦欢鍓嶉攣瀹氭墍鏈夎〃浠ヤ究鍐欏叆銆傝繖鏍峰彲浠ョ‘淇濇墍鏈夎〃鍦ㄦ湇鍔″櫒涓婁繚鎸佸悓姝ャ

         --password[=password]-p[password]

褰撹繛鎺ユ湇鍔″櫒鏃朵娇鐢ㄧ殑瀵嗙爜銆傚鏋滀娇鐢ㄧ煭閫夐」褰㈠紡(-p)锛岄夐」鍜 瀵嗙爜涔嬮棿涓嶈兘鏈夌┖鏍笺傚鏋滃湪鍛戒护琛屼腑--password-p閫夐」鍚庨潰娌℃湁 瀵嗙爜鍊硷紝鍒欐彁绀鸿緭鍏ヤ竴涓瘑鐮併

         --port=port_num-P port_num

鐢ㄤ簬杩炴帴鐨TCP/IP绔彛鍙枫

         --protocol={TCP | SOCKET | PIPE | MEMORY}

浣跨敤鐨勮繛鎺ュ崗璁

         --replace-r

--replace--ignore閫夐」鎺у埗澶嶅埗鍞竴閿煎凡鏈夎褰曠殑杈撳叆璁板綍鐨勫鐞嗐傚鏋滄寚瀹--replace锛屾柊琛屾浛鎹㈡湁鐩稿悓鐨勫敮涓閿肩殑宸叉湁琛屻傚鏋滄寚瀹--ignore锛屽鍒跺凡鏈夌殑鍞竴閿肩殑杈撳叆琛岃璺宠繃銆傚鏋滀笉鎸囧畾杩欎袱涓夐」锛屽綋鍙戠幇涓涓鍒堕敭鍊兼椂浼氬嚭鐜颁竴涓敊璇紝骞朵笖蹇借鏂囨湰鏂囦欢鐨勫墿浣欓儴鍒嗐

         --silent-s

娌夐粯妯″紡銆傚彧鏈夊嚭鐜伴敊璇椂鎵嶈緭鍑恒

         --socket=path-S path

褰撹繛鎺localhost鏃朵娇鐢ㄧ殑濂楁帴瀛楁枃浠(涓洪粯璁や富鏈)

         --user=user_name-u user_name

褰撹繛鎺ユ湇鍔″櫒鏃MySQL浣跨敤鐨勭敤鎴峰悕銆

         --verbose-v

鍐楅暱妯″紡銆傛墦鍗板嚭绋嬪簭鎿嶄綔鐨勮缁嗕俊鎭

         --version-V

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

杩欓噷鏄竴涓ず渚嬩細璇濓紝鏄剧ず濡備綍浣跨敤mysqlimport

shell> mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
shell> ed
a
100     Max Sydow
101     Count Dracula
.
w imptest.txt
32
q
shell> od -c imptest.txt
0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
0000040
shell> mysqlimport --local test imptest.txt
test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
shell> mysql -e 'SELECT * FROM imptest' test
+------+---------------+
| id   | n             |
+------+---------------+
|  100 | Max Sydow     |
|  101 | Count Dracula |
+------+---------------+

8.11. mysqlshow锛嶆樉绀烘暟鎹簱銆佽〃鍜屽垪淇℃伅

mysqlshow瀹㈡埛鍙敤鏉ュ緢蹇湴鏌ユ壘瀛樺湪鍝簺鏁版嵁搴擄紝鏁版嵁搴撲腑鐨勮〃锛岃〃涓殑鍒楁垨绱㈠紩銆

mysqlshow涓轰竴浜SQL鏄剧ず璇彞鎻愪緵浜嗕竴涓懡浠よ鐣岄潰銆傜浉鍚岀殑淇℃伅鍙互閫氳繃鐩存帴浣跨敤閭d簺璇彞鑾峰緱銆備緥濡傦紝浣犲彲浠ヤ粠mysql瀹㈡埛绋嬪簭鍙戝嚭瀹冧滑銆傚弬瑙13.5.4鑺傦紝鈥淪HOW璇硶鈥

璞¤繖鏍疯皟鐢mysqlshow

shell> mysqlshow[閫夐」] [db_name [tbl_name [col_name]]]

         濡傛灉娌℃湁缁欏嚭鏁版嵁搴擄紝鏄剧ず鎵鏈夊尮閰嶇殑鏁版嵁搴撱

         濡傛灉娌℃湁缁欏嚭琛紝鏄剧ず鏁版嵁搴撲腑鎵鏈夊尮閰嶇殑琛ㄣ

         濡傛灉娌℃湁缁欏嚭鍒楋紝鏄剧ず琛ㄤ腑鎵鏈夊尮閰嶇殑鍒楀拰鍒楃被鍨嬨

璇锋敞鎰忥紝鍦MySQL鐨勬柊鐗堟湰涓紝浣犲彧鑳界湅鍒版湁閮ㄥ垎鏉冮檺鐨勯偅浜涙暟鎹簱銆佽〃鎴栬呭垪銆

濡傛灉鏈鍚庣殑鍙傛暟鍖呭惈shellSQL閫氱敤瀛楃 (*鈥欍佲?鈥欍佲%鈥欐垨鑰呪_)锛屽彧鏄剧ず閭d簺鍚嶅尮閰嶉氱敤瀛楃鐨勫悕瀛椼傚鏋滀竴涓暟鎹簱鍚嶅寘鍚笅鍒掔嚎锛屽簲璇ヤ娇鐢ㄤ竴涓弽鏂滅嚎锛堥儴鍒Unix shells闇瑕佸弻鍙嶆枩绾匡級瀵瑰畠浠繘琛岃浆涔夛紝浠ヤ究寰楀埌涓涓纭殑琛ㄦ垨鍒楃殑鍒楄〃銆傗*鈥欏拰鈥?鈥欏瓧绗﹁杞崲涓SQL鐨勨%鈥欏拰鈥_鈥欓氱敤瀛楃銆備綘璇曞浘鐢ㄢ_鈥欐樉绀轰竴涓〃鐨勫垪鍚嶆椂锛岃繖鍙兘浼氶犳垚涓浜涙贩娣嗭紝鍥犱负鍦ㄨ繖绉嶆儏鍐典笅 mysqlshow鏄剧ず涓庢ā寮忕浉鍖归厤鐨勮〃鍚嶃傝繖寰堝鏄撻氳繃鍦ㄥ懡浠よ娣诲姞涓涓%鈥欏弬閲忔潵瑙e喅銆

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

         ---help-

鏄剧ず涓涓府鍔╂秷鎭苟閫鍑恒

         --character-sets-dir=path

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

         --compress-C

鍘嬬缉鎵鏈夌殑瀹㈡埛鍜屾湇鍔″櫒涔嬮棿鍙戦佺殑淇℃伅锛堝鏋滃畠浠兘鏀寔鍘嬬缉锛夈

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

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父鏄'd:t:o,file_name'

         --default-character-set=charset

浣跨敤charset涓洪粯璁ゅ瓧绗﹂泦銆傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥

         --host=host_name-h host_name

鍦ㄧ粰鍑虹殑涓绘満涓婅繛鎺 MySQL鏈嶅姟鍣ㄣ

         --keys, -k

鏄剧ず琛ㄧ储寮曘

         --password[=password]-p[password]

杩炴帴鏈嶅姟鍣ㄦ椂浣跨敤鐨勫瘑鐮併傚鏋滀綘浣跨敤鐭夐」褰㈠紡(-p)涓嶈兘鍦ㄩ夐」鍜 瀵嗙爜涔嬮棿鏈変竴涓┖鏍銆傚鏋滃湪鍛戒护琛屼腑锛屼綘蹇界暐浜--password-p閫夐」鍚庨潰鐨 瀵嗙爜鍊硷紝灏嗘彁绀轰綘杈撳叆涓涓

         --port=port_num, -P port_num

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

         --protocol={TCP | SOCKET | PIPE | MEMORY}

杩炴帴鏃朵娇鐢ㄧ殑鍗忚銆

         --show-table-type

鏄剧ず涓鍒楁潵鎸囩ず琛ㄧ被鍨嬶紝涓SHOW FULL TABLES璇彞鏄剧ず鐩稿悓銆

         --socket=path-S path

褰撹繛鎺localhost鏃朵娇鐢ㄧ殑濂楁帴瀛楁枃浠讹紙瀹冩椂榛樿涓绘満锛夈

         --status, -i

鏄剧ず鍏充簬姣忎釜琛ㄧ殑棰濆淇℃伅銆

         --user=user_name-u user_name

杩炴帴鏈嶅姟鍣ㄦ椂浣跨敤鐨MySQL鐢ㄦ埛鍚嶃

         --verbose-v

鍐楅暱妯″紡銆傛墦鍗板嚭绋嬪簭鎿嶄綔鐨勮缁嗕俊鎭傝閫夐」鍙互澶氭浣跨敤浠ヤ究澧炲姞淇℃伅鎬婚噺銆

         --version-V

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

8.12. myisamlog锛氭樉绀篗yISAM鏃ュ織鏂囦欢鍐呭

myisamlog澶勭悊MyISAM鏃ュ織鏂囦欢鍐呭銆

璞¤繖鏍疯皟鐢myisamlog

shell> myisamlog [options] [logfile-name [tbl_name] ...]

甯哥敤鎿嶄綔鏄洿鏂帮紙-u锛夈傚鏋滄仮澶嶅畬鎴愶紙-r锛屾墍鏈夊啓鍜屽彲鑳界殑鏇存柊浠ュ強鍒犻櫎鎿嶄綔瀹屾垚骞朵笖鍙粺璁¢敊璇傚鏋滄病鏈夌粰鍑烘棩蹇楁枃浠跺悕锛屼娇鐢myisam.log浣滀负鏃ュ織鏂囦欢鍚嶃傚鏋滃湪鍛戒护琛屼腑鎸囧畾浜嗚〃鍚嶏紝鍙洿鏂伴偅浜涙寚瀹氱殑琛ㄣ

myisamlog鐞嗚В涓嬮潰鐨勯夐」锛

         -?-I

鏄剧ず涓涓府鍔╂秷鎭苟閫鍑恒

         -c N

鍙墽琛N涓懡浠ゃ

         -f N

鎸囧畾鎵撳紑鏂囦欢鐨勬渶澶ф暟鐩

         -F filepath/

TODO

         -i

閫鍑轰箣鍓嶆樉绀鸿缁嗕俊鎭

         -o offset

鎸囧畾璧峰鍋忕Щ閲忋

         -p N

浠庤矾寰勪腑绉婚櫎N涓粍浠躲

         -r

鎭㈠銆

         -R record-pos-file record-pos

鎸囧畾璁板綍浣嶇疆鏂囦欢鍜岃褰曚綅缃

         -u

鏇存柊銆

         -v

Verbose妯″紡銆備骇鐢熸洿澶氳緭鍑恒傝閫夐」鍙互澶氭浣跨敤浠ヤ究浜х敓瓒婃潵瓒婂鐨勮緭鍑恒

         -w write-file

鎸囧畾鍐欐枃浠躲

         -V

鏄剧ず鐗堟湰淇℃伅銆

8.13. perror锛氳В閲婇敊璇唬鐮

瀵逛簬澶у鏁扮郴缁熼敊璇紝闄ゅ唴閮ㄦ枃鏈俊鎭箣澶栵紝MySQL杩樻寜涓嬮潰鐨勯鏍兼樉绀虹殑绯荤粺閿欒浠g爜锛

message ... (errno: #)

message ... (Errcode: #)

閫氳繃妫鏌ョ郴缁熸枃妗f垨浣跨敤perror宸ュ叿锛屽彲浠ユ鏌ラ敊璇唬鐮佺殑鎰忎箟銆

perror涓虹郴缁熼敊璇唬鐮佹垨瀛樺偍寮曟搸锛堣〃澶勭悊锛夐敊璇唬鐮佹墦鍗板叾鎻忚堪淇℃伅銆

璞¤繖鏍疯皟鐢perror

shell> perror [options] errorcode ...

渚嬪锛

shell> perror13 64

Error code  13:  Permission denied

Error code  64:  Machine is not on the network

娉ㄩ噴锛瑕佹兂鏄剧ずMySQL绨囩殑閿欒浠g爜锛岀敤--ndb閫夐」璋冪敤perror

shell> perror --ndb errorcode

璇锋敞鎰忥紝绯荤粺閿欒淇℃伅鐨勫惈涔夊彲鑳戒笌鎿嶄綔绯荤粺鏈夊叧銆傚湪涓嶅悓鐨勬搷浣滅郴缁熶腑閿欒浠g爜鐨勫惈涔夊彲鑳戒笉鍚屻

8.14. replace锛氬瓧绗︿覆鏇挎崲瀹炵敤宸ュ叿

replace瀹炵敤宸ュ叿鍙互鍙婃椂鏇存敼鏂囦欢鎴栨爣鍑嗚緭鍏ヤ腑鐨勫瓧绗︿覆銆傚畠棣栧厛浣跨敤鏈夐檺鐘舵佹満鏉ュ尮閰嶉暱鐨勫瓧绗︿覆銆傝宸ュ叿鍙互鐢ㄦ潵浜ゆ崲瀛楃涓层備緥濡傦紝涓嬮潰鐨勫懡浠や氦鎹㈢粰瀹氭枃浠file1file2涓殑ab

shell> replace a b b a -- file1 file2 ...

浣跨敤--閫夐」鏉ユ寚绀哄瓧绗︿覆-鏇挎崲鍒楄〃鐨勭粨鏉熶綅缃拰寮濮嬬殑鏂囦欢鍚嶃

鍦ㄥ懡浠よ涓殑浠讳綍鏂囦欢鍚嶈鍙婃椂淇敼锛屽洜姝ゅ湪杞崲涔嬪墠锛屽彲鑳借瀵规簮鏂囦欢杩涜澶囦唤銆

濡傛灉鍦ㄥ懡浠よ涓病鏈夋寚瀹氭枃浠跺悕锛replace璇诲彇鏍囧噯杈撳叆骞跺啓鍒版爣鍑嗚緭鍑轰腑銆傚湪杩欑鎯呭喌涓嬶紝涓嶉渶瑕--閫夐」銆

replace绋嬪簭鐢ㄤ簬msql2mysql鍙傝25.9.1鑺傦紝鈥渕sql2mysql锛氳浆鎹SQL绋嬪簭浠ョ敤浜嶮ySQL鈥

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

         -?-I

鏄剧ず涓鏉″府鍔╂秷鎭苟閫鍑恒

         -# debug_options

鍐欒皟璇曟棩蹇椼debug_options瀛楃涓查氬父鏄'd:t:o,file_name'

         -s

娌夐粯妯″紡銆傛墦鍗板嚭绋嬪簭鎵ц鐨勫皯閲忎俊鎭

         -v

鍐楅暱妯″紡銆傛墦鍗板嚭绋嬪簭鎵ц鐨勫ぇ閲忎俊鎭

         -V

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

8.15. mysql_zap锛氭潃姝荤鍚堟煇涓妯″紡鐨勮繘绋

mysql_zap鏉姝诲尮閰嶆煇涓妯″紡鐨勮繘绋嬨傝薄杩欐牱璋冪敤瀹冿細

shell> mysql_zap [-signal] [-?Ift] pattern

濡傛灉杩涚▼鐨ps鍛戒护鐨勮緭鍑鸿鍖呭惈璇ユā寮忥紝鍒欒涓哄叾鍖归厤銆傞粯璁ゆ儏鍐碉紝mysql_zap瀵规瘡涓繘绋嬭姹傜‘璁ゃ傚搷搴y鍒欐潃姝昏杩涚▼锛屾垨鑰q閫鍑 mysql_zap銆傚浜庡叾瀹冨搷搴旓紝mysql_zap涓嶈瘯鍥炬潃姝昏繘绋嬨

濡傛灉缁欏嚭-signal閫夐」锛屽畠鎸囧畾鍙戦佸埌姣忎釜杩涚▼鐨勪俊鍙峰悕鎴栦俊鍙风紪鍙枫傚惁鍒欙紝mysql_zap棣栧厛灏濊瘯TERM锛堜俊鍙15锛夌劧鍚庣敤KILL锛堜俊鍙9锛夈

mysql_zap鐞嗚В涓嬮潰鐨勯澶栭夐」锛

         ---help-?-I

鏄剧ず涓鏉″府鍔╂秷鎭苟閫鍑恒

         -f

寮哄埗妯″紡銆mysql_zap 瑙嗗浘鏉姝绘瘡涓尮閰嶇殑杩涚▼鑰屼笉闇瑕佺‘璁ゃ

         -t

娴嬭瘯妯″紡銆傛樉绀烘瘡涓繘绋嬬殑淇℃伅浣嗕笉鏉姝诲畠銆


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