MySQL管理工具MySQL Utilities — mysqluc (31)

默北 MySQLMySQL管理工具MySQL Utilities — mysqluc (31)已关闭评论15,3964字数 8023阅读26分44秒阅读模式

mysqluc 是MySQL Utilities 提供的一个命令行环境下运行的工具。该工具有自己的控制台,允许用户执行当前安装的MySQL工具的任何命令。​​--utildir 选项用于指定 MySQL Utilities 安装路径。

该控制台提供了一些命令,允许用户与控制台进行交互。如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

# 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 <utility>          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 <variable>=<value>  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.                         
<ENTER>                 Press ENTER to execute command.                    
<ESCAPE>                Press ESCAPE to clear the command entry.           
<DOWN>                  Press DOWN to retrieve the previous command.       
<UP>                    Press UP to retrieve the next command in history.  
<TAB>                   Press TAB for type completion of utility, option,  
                        or variable names.                                 
<TAB><TAB>              Press TAB twice for list of matching type          
                        completion (context sensitive).                    

mysqluc>

其中最有用的命令是'help <utility>'来显示给定程序的选项。如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

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:    
                     <user>[:<password>]@<host>[:<port>][:<socket>] or     
                     <login-path>[:<port>][:<socket>] or <config-          
                     path>[<[group]>].                                     
--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.

该控制台提供tab完成所有命令、实用选项和用户自定义的变量。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

该控制台不需要键入“ mysql”前缀。例如,如果用户输入“ disku <TAB >'控制台将完成命令' diskusage ' 。如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

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:    
                     <user>[:<password>]@<host>[:<port>][:<socket>] or     
                     <login-path>[:<port>][:<socket>] or <config-          
                     path>[<[group]>].                                     
--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.

输入完整的命令,然后按ENTER键执行,不必在意程序所需环境,控制台会完成的。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

用户还可以使用--execute选项来执行命令。该选项值是一个以分号分隔的命令列表。这些命令可以是基本的命令或MySQL Utilities命令。控制台将执行每个命令并显示输出。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

也可以是用管道,如echo “<commands>” | mysqluc。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

该控制台还允许用户对常使用的选项值进行自定义变量。语法为'set VARNAME=VALUE'。输入'show variables'命令列出所有变量。要使用这些自定义变量,需要在变量前加上一个$前缀。用户定义的变量只对当前的会话窗口有效,对其他控制台窗口无效的。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

选项

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<utility_name>.
                        The mysql<utility_name>.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.

使用--execute选项或管道命令到控制台可能需要引号或双引号(如Windows平台上)。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

实例

显示所有MySQL Utilities命令文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

# 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

使用变量并执行。$在Linux平台上需要转义。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

# 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.

使用管道文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

# 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.

显示所有变量文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

# mysqluc SRV=instance_3306 SITE=www.ttlsa.com -e "show variables"                             
Launching console ...


Variable  Value                                                            
--------  -----------------------------------------------------------------
SRV       instance_3306                                                    
SITE      www.ttlsa.com

权限

对运行mysqluc无需特殊权限,不过对要执行的工具要有该工具执行所需的权限,前面文章有说到每个工具所需要的权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/ 文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 19/03/2015 01:00:53
  • 转载请务必保留本文链接:https://www.ttlsa.com/mysql/mysql-utilities-mysqluc/