mysqluc 是MySQL Utilities 提供的一个命令行环境下运行的工具。该工具有自己的控制台,允许用户执行当前安装的MySQL工具的任何命令。--utildir 选项用于指定 MySQL Utilities 安装路径。
该控制台提供了一些命令,允许用户与控制台进行交互。如下所示:
# mysqluc
Launching console ...
Welcome to the MySQL Utilities Client (mysqluc) version 1.5.3
Copyright (c) 2010, 2014 Oracle and/or its affiliates. All rights reserved.
This is a release of dual licensed MySQL Utilities. For the avoidance of
doubt, this particular copy of the software is released
under the version 2 of the GNU General Public License.
MySQL Utilities is brought to you by Oracle.
Type 'help' for a list of commands or press TAB twice for list of utilities.
mysqluc> help
Command Description
---------------------- ---------------------------------------------------
help utilities Display list of all utilities supported.
help Display help for a specific utility.
show errors Display errors captured during the execution of the
utilities.
clear errors clear captured errors.
show last error Display the last error captured during the
execution of the utilities
help | help commands Show this list.
exit | quit Exit the console.
set = Store a variable for recall in commands.
show options Display list of options specified by the user on
launch.
show variables Display list of variables.
Press ENTER to execute command.
Press ESCAPE to clear the command entry.
Press DOWN to retrieve the previous command.
Press UP to retrieve the next command in history.
Press TAB for type completion of utility, option,
or variable names.
Press TAB twice for list of matching type
completion (context sensitive).
mysqluc>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# mysqluc
Launchingconsole...
WelcometotheMySQLUtilitiesClient(mysqluc)version1.5.3
Copyright(c)2010,2014Oracleand/oritsaffiliates.Allrightsreserved.
ThisisareleaseofduallicensedMySQLUtilities.Fortheavoidanceof
doubt,thisparticularcopyofthesoftwareisreleased
undertheversion2oftheGNUGeneralPublicLicense.
MySQLUtilitiesisbroughttoyoubyOracle.
Type'help'foralistofcommandsorpressTABtwiceforlistofutilities.
mysqluc>help
CommandDescription
-------------------------------------------------------------------------
helputilitiesDisplaylistofallutilitiessupported.
helpDisplayhelpforaspecificutility.
showerrorsDisplayerrorscapturedduringtheexecutionofthe
utilities.
clearerrorsclearcapturederrors.
showlasterrorDisplaythelasterrorcapturedduringthe
executionoftheutilities
help|helpcommandsShowthislist.
exit|quitExittheconsole.
set=Storeavariableforrecallincommands.
showoptionsDisplaylistofoptionsspecifiedbytheuseron
launch.
showvariablesDisplaylistofvariables.
PressENTERtoexecutecommand.
PressESCAPEtoclearthecommandentry.
PressDOWNtoretrievethepreviouscommand.
PressUPtoretrievethenextcommandinhistory.
PressTABfortypecompletionofutility,option,
orvariablenames.
PressTABtwiceforlistofmatchingtype
completion(contextsensitive).
mysqluc>
其中最有用的命令是'help '来显示给定程序的选项。如下所示:
mysqluc> help mysqldiskusage
Usage: mysqldiskusage --server=user:pass@host:port:socket db1 --all
mysqldiskusage - show disk usage for databases
Options:
Option Description
------------------- ------------------------------------------------------
--version show program's version number and exit
--help display a help message and exit
--license display program's license and exit
--server=SERVER connection information for the server in the form:
[:]@[:][:] or
[:][:] or
path>[].
--ssl-ca=SSL_CA The path to a file that contains a list of trusted SSL
CAs.
--ssl-cert=SSL_CERT The name of the SSL certificate file to use for
establishing a secure connection.
--ssl-key=SSL_KEY The name of the SSL key file to use for establishing a
secure connection.
-f, --format=FORMAT display the output in either grid (default), tab, csv,
or vertical format
-h, --no-headers do not show column headers (only applies to formats:
grid, tab, csv).
-b, --binlog include binary log usage
-r, --relaylog include relay log usage
-l, --logs include general and slow log usage
-i, --innodb include InnoDB tablespace usage
-m, --empty include empty databases
-a, --all show all usage including empty databases
-v, --verbose control how much information is displayed. e.g., -v =
verbose, -vv = more verbose, -vvv = debug
-q, --quiet turn off all messages for quiet execution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
mysqluc>helpmysqldiskusage
Usage:mysqldiskusage--server=user:pass@host:port:socketdb1--all
mysqldiskusage-showdiskusagefordatabases
Options:
OptionDescription
-------------------------------------------------------------------------
--versionshowprogram's version number and exit
--help display a help message and exit
--license display program'slicenseandexit
--server=SERVERconnectioninformationfortheserverintheform:
[:]@[:][:]or
[:][:]or
path>[].
--ssl-ca=SSL_CAThepathtoafilethatcontainsalistoftrustedSSL
CAs.
--ssl-cert=SSL_CERTThenameoftheSSLcertificatefiletousefor
establishingasecureconnection.
--ssl-key=SSL_KEYThenameoftheSSLkeyfiletouseforestablishinga
secureconnection.
-f,--format=FORMATdisplaytheoutputineithergrid(default),tab,csv,
orverticalformat
-h,--no-headersdonotshowcolumnheaders(onlyappliestoformats:
grid,tab,csv).
-b,--binlogincludebinarylogusage
-r,--relaylogincluderelaylogusage
-l,--logsincludegeneralandslowlogusage
-i,--innodbincludeInnoDBtablespaceusage
-m,--emptyincludeemptydatabases
-a,--allshowallusageincludingemptydatabases
-v,--verbosecontrolhowmuchinformationisdisplayed.e.g.,-v=
verbose,-vv=moreverbose,-vvv=debug
-q,--quietturnoffallmessagesforquietexecution.
该控制台提供tab完成所有命令、实用选项和用户自定义的变量。
该控制台不需要键入“ mysql”前缀。例如,如果用户输入“ disku '控制台将完成命令' diskusage ' 。如下所示:
mysqluc> help diskusage
Usage: mysqldiskusage --server=user:pass@host:port:socket db1 --all
mysqldiskusage - show disk usage for databases
Options:
Option Description
------------------- ------------------------------------------------------
--version show program's version number and exit
--help display a help message and exit
--license display program's license and exit
--server=SERVER connection information for the server in the form:
[:]@[:][:] or
[:][:] or
path>[].
--ssl-ca=SSL_CA The path to a file that contains a list of trusted SSL
CAs.
--ssl-cert=SSL_CERT The name of the SSL certificate file to use for
establishing a secure connection.
--ssl-key=SSL_KEY The name of the SSL key file to use for establishing a
secure connection.
-f, --format=FORMAT display the output in either grid (default), tab, csv,
or vertical format
-h, --no-headers do not show column headers (only applies to formats:
grid, tab, csv).
-b, --binlog include binary log usage
-r, --relaylog include relay log usage
-l, --logs include general and slow log usage
-i, --innodb include InnoDB tablespace usage
-m, --empty include empty databases
-a, --all show all usage including empty databases
-v, --verbose control how much information is displayed. e.g., -v =
verbose, -vv = more verbose, -vvv = debug
-q, --quiet turn off all messages for quiet execution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
mysqluc>helpdiskusage
Usage:mysqldiskusage--server=user:pass@host:port:socketdb1--all
mysqldiskusage-showdiskusagefordatabases
Options:
OptionDescription
-------------------------------------------------------------------------
--versionshowprogram's version number and exit
--help display a help message and exit
--license display program'slicenseandexit
--server=SERVERconnectioninformationfortheserverintheform:
[:]@[:][:]or
[:][:]or
path>[].
--ssl-ca=SSL_CAThepathtoafilethatcontainsalistoftrustedSSL
CAs.
--ssl-cert=SSL_CERTThenameoftheSSLcertificatefiletousefor
establishingasecureconnection.
--ssl-key=SSL_KEYThenameoftheSSLkeyfiletouseforestablishinga
secureconnection.
-f,--format=FORMATdisplaytheoutputineithergrid(default),tab,csv,
orverticalformat
-h,--no-headersdonotshowcolumnheaders(onlyappliestoformats:
grid,tab,csv).
-b,--binlogincludebinarylogusage
-r,--relaylogincluderelaylogusage
-l,--logsincludegeneralandslowlogusage
-i,--innodbincludeInnoDBtablespaceusage
-m,--emptyincludeemptydatabases
-a,--allshowallusageincludingemptydatabases
-v,--verbosecontrolhowmuchinformationisdisplayed.e.g.,-v=
verbose,-vv=moreverbose,-vvv=debug
-q,--quietturnoffallmessagesforquietexecution.
输入完整的命令,然后按ENTER键执行,不必在意程序所需环境,控制台会完成的。
用户还可以使用--execute选项来执行命令。该选项值是一个以分号分隔的命令列表。这些命令可以是基本的命令或MySQL Utilities命令。控制台将执行每个命令并显示输出。
也可以是用管道,如echo “” | mysqluc。
该控制台还允许用户对常使用的选项值进行自定义变量。语法为'set VARNAME=VALUE'。输入'show variables'命令列出所有变量。要使用这些自定义变量,需要在变量前加上一个$前缀。用户定义的变量只对当前的会话窗口有效,对其他控制台窗口无效的。
选项
MySQL Utilities mysqluc version 1.5.3
License type: GPLv2
Usage: mysqluc
mysqluc - Command line client for running MySQL Utilities
Options:
--version show program's version number and exit
--help display this help message and exit
--license display program's license and exit
--width=WIDTH display width
--utildir=UTILDIR location of utilities
-e COMMANDS, --execute=COMMANDS
execute commands and exit. Multiple commands are
separated with semi-colons. Note: some platforms may
require double quotes around command list.
--add-utility=ADD_UTIL
append an utility in the format mysql.
The mysql.py must be located inside the
folder given by the utildir option
--hide-utils when this option is given, the default utilities will
not be available, must be used only along of --add-
utility option
-v, --verbose control how much information is displayed. e.g., -v =
verbose, -vv = more verbose, -vvv = debug
-q, --quiet turn off all messages for quiet execution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
MySQLUtilitiesmysqlucversion1.5.3
Licensetype:GPLv2
Usage:mysqluc
mysqluc-CommandlineclientforrunningMySQLUtilities
Options:
--versionshowprogram's version number and exit
--help display this help message and exit
--license display program'slicenseandexit
--width=WIDTHdisplaywidth
--utildir=UTILDIRlocationofutilities
-eCOMMANDS,--execute=COMMANDS
executecommandsandexit.Multiplecommandsare
separatedwithsemi-colons.Note:someplatformsmay
requiredoublequotesaroundcommandlist.
--add-utility=ADD_UTIL
appendanutilityintheformatmysql.
Themysql.pymustbelocatedinsidethe
foldergivenbytheutildiroption
--hide-utilswhenthisoptionisgiven,thedefaultutilitieswill
notbeavailable,mustbeusedonlyalongof--add-
utilityoption
-v,--verbosecontrolhowmuchinformationisdisplayed.e.g.,-v=
verbose,-vv=moreverbose,-vvv=debug
-q,--quietturnoffallmessagesforquietexecution.
使用--execute选项或管道命令到控制台可能需要引号或双引号(如Windows平台上)。
实例
显示所有MySQL Utilities命令
# mysqluc -e "help utilities"
Launching console ...
Utility Description
---------------- ---------------------------------------------------------
mysqlauditadmin audit log maintenance utility
mysqlauditgrep audit log search utility
mysqldbcompare compare databases for consistency
mysqldbcopy copy databases from one server to another
mysqldbexport export metadata and data from databases
mysqldbimport import metadata and data from files
mysqldiff compare object definitions among objects where the
difference is how db1.obj1 differs from db2.obj2
mysqldiskusage show disk usage for databases
mysqlfailover automatic replication health monitoring and failover
mysqlfrm show CREATE TABLE from .frm files
mysqlindexcheck check for duplicate or redundant indexes
mysqlmetagrep search metadata
mysqlprocgrep search process information
mysqlreplicate establish replication with a master
mysqlrpladmin administration utility for MySQL replication
mysqlrplcheck check replication
mysqlrplms establish multi-source replication
mysqlrplshow show slaves attached to a master
mysqlrplsync replication synchronization checker utility
mysqlserverclone start another instance of a running server
mysqlserverinfo show server information
mysqluserclone clone a MySQL user account to one or more new users
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# mysqluc -e "help utilities"
Launchingconsole...
UtilityDescription
-------------------------------------------------------------------------
mysqlauditadminauditlogmaintenanceutility
mysqlauditgrepauditlogsearchutility
mysqldbcomparecomparedatabasesforconsistency
mysqldbcopycopydatabasesfromoneservertoanother
mysqldbexportexportmetadataanddatafromdatabases
mysqldbimportimportmetadataanddatafromfiles
mysqldiffcompareobjectdefinitionsamongobjectswherethe
differenceishowdb1.obj1differsfromdb2.obj2
mysqldiskusageshowdiskusagefordatabases
mysqlfailoverautomaticreplicationhealthmonitoringandfailover
mysqlfrmshowCREATETABLEfrom.frmfiles
mysqlindexcheckcheckforduplicateorredundantindexes
mysqlmetagrepsearchmetadata
mysqlprocgrepsearchprocessinformation
mysqlreplicateestablishreplicationwithamaster
mysqlrpladminadministrationutilityforMySQLreplication
mysqlrplcheckcheckreplication
mysqlrplmsestablishmulti-sourcereplication
mysqlrplshowshowslavesattachedtoamaster
mysqlrplsyncreplicationsynchronizationcheckerutility
mysqlserverclonestartanotherinstanceofarunningserver
mysqlserverinfoshowserverinformation
mysqluserclonecloneaMySQLuseraccounttooneormorenewusers
使用变量并执行。$在Linux平台上需要转义。
# mysqluc -e "set SRV=instance_3306; mysqldiskusage --server=$SRV" -vvv
Launching console ...
Executing command: set SRV=instance_3306
Executing command: mysqldiskusage --server=
The console has detected that the utility 'mysqldiskusage' ended with an error code.
You can get more information about the error by running the console command 'show last error'.
# mysqluc -e "set SRV=instance_3306; mysqldiskusage --server=\$SRV" -vvv
Launching console ...
Executing command: set SRV=instance_3306
Executing command: mysqldiskusage --server=instance_3306
# Source on localhost: ... connected.
# Database totals:
+---------------------+--------------+
| db_name | total |
+---------------------+--------------+
| mysql | 1,577,145 |
| performance_schema | 489,543 |
| ttlsa_com | 116,593,588 |
| ttlsa_com_copy | 160,237 |
+---------------------+--------------+
Total database disk usage = 118,820,513 bytes or 113.32 MB
#...done.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# mysqluc -e "set SRV=instance_3306; mysqldiskusage --server=$SRV" -vvv
Launchingconsole...
Executingcommand:setSRV=instance_3306
Executingcommand:mysqldiskusage--server=
Theconsolehasdetectedthattheutility'mysqldiskusage'endedwithanerrorcode.
Youcangetmoreinformationabouttheerrorbyrunningtheconsolecommand'show last error'.
# mysqluc -e "set SRV=instance_3306; mysqldiskusage --server=\$SRV" -vvv
Launchingconsole...
Executingcommand:setSRV=instance_3306
Executingcommand:mysqldiskusage--server=instance_3306
# Source on localhost: ... connected.
# Database totals:
+---------------------+--------------+
|db_name|total|
+---------------------+--------------+
|mysql|1,577,145|
|performance_schema|489,543|
|ttlsa_com|116,593,588|
|ttlsa_com_copy|160,237|
+---------------------+--------------+
Totaldatabasediskusage=118,820,513bytesor113.32MB
#...done.
使用管道
# echo "set SRV=instance_3306; mysqldiskusage --server=\$SRV" | mysqluc -vvv
Launching console ...
Executing command: set SRV=instance_3306
Executing command: mysqldiskusage --server=instance_3306
# Source on localhost: ... connected.
# Database totals:
+---------------------+--------------+
| db_name | total |
+---------------------+--------------+
| mysql | 1,577,145 |
| performance_schema | 489,543 |
| ttlsa_com | 116,593,588 |
| ttlsa_com_copy | 160,237 |
+---------------------+--------------+
Total database disk usage = 118,820,513 bytes or 113.32 MB
#...done.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# echo "set SRV=instance_3306; mysqldiskusage --server=\$SRV" | mysqluc -vvv
Launchingconsole...
Executingcommand:setSRV=instance_3306
Executingcommand:mysqldiskusage--server=instance_3306
# Source on localhost: ... connected.
# Database totals:
+---------------------+--------------+
|db_name|total|
+---------------------+--------------+
|mysql|1,577,145|
|performance_schema|489,543|
|ttlsa_com|116,593,588|
|ttlsa_com_copy|160,237|
+---------------------+--------------+
Totaldatabasediskusage=118,820,513bytesor113.32MB
#...done.
显示所有变量
# mysqluc SRV=instance_3306 SITE=www.ttlsa.com -e "show variables"
Launching console ...
Variable Value
-------- -----------------------------------------------------------------
SRV instance_3306
SITE www.ttlsa.com
1
2
3
4
5
6
7
8
# mysqluc SRV=instance_3306 SITE=www.ttlsa.com -e "show variables"
Launchingconsole...
VariableValue
-------------------------------------------------------------------------
SRVinstance_3306
SITEwww.ttlsa.com
权限
对运行mysqluc无需特殊权限,不过对要执行的工具要有该工具执行所需的权限,前面文章有说到每个工具所需要的权限。