mysql客户端工具使用

mysqladmin是个客户端的管理工具,使用的方式如下:

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

包含的命令如下:

create db_name  创建一个新的数据库

drop db_name删除数据库

extended-status 显示服务器状态变量及对应的值

flush-hosts 刷新机器缓存中的所有信息 相当于commit?

flush-logs 刷新日志 相当于fulsh logs生成一个新的log

flush-privileges 重新加载授权表

flush-status 清空状态变量

flush-tables刷新表  ??

flush-threads 刷新线程缓存

kill id,id,....杀掉线程

ping 查看服务器是否可用

processlist 显示线程的列表,使用--verbose选项,输出就是show full processlist

reload 重载授权表

refresh 刷新所有的表并关闭在打开日志文件

shutdown 关闭服务器

start-slave 启动复制

status 显示状态信息

stop-slave停止复制

variables显示系统变量和值

version显示版本

------------------------------------------------

mysqlcheck这个客户端主要是检查,修复,优化,分析表。

当使用该工具的时候,表被锁住不可用,对于检查操作,加的事读锁。mysql_upgrade命令也是调用了mysqlcheck,也会锁表。

mysqlcheck跟myisamchk很像,但是不同,mysqlcheck主要是mysqld运行的时候使用,myisamchk是在不运行的时候使用,使用mysqlcheck不需要停止服务。

mysqlcheck使用sql语句check table,repaire table analyze table 和optimize table,它决定使用哪个语句来操作,mysqlcheck也可以用在在myisam表上。

使用方法

shell> mysqlcheck [options] db_name [tbl_name ...]
shell> mysqlcheck [options] --databases db_name ...
shell> mysqlcheck [options] --all-databases
下面是指定的选项,主要的也就是check,repaire,analyze

Format Description Introduced
--all-databases Check all tables in all databases  
--all-in-1 Execute a single statement for each database that names all the tables from that database  
--analyze Analyze the tables  
--auto-repair If a checked table is corrupted, automatically fix it  
--bind-address Use specified network interface to connect to MySQL Server 5.6.1
--character-sets-dir Directory where character sets are installed  
--check Check the tables for errors  
--check-only-changed Check only tables that have changed since the last check  
--check-upgrade Invoke CHECK TABLE with the FOR UPGRADE option  
--compress Compress all information sent between client and server  
--databases Interpret all arguments as database names  
--debug Write debugging log  
--debug-check Print debugging information when program exits  
--debug-info Print debugging information, memory, and CPU statistics when program exits  
--default-auth Authentication plugin to use 5.6.2
--default-character-set Specify default character set  
--defaults-extra-file Read named option file in addition to usual option files  
--defaults-file Read only named option file  
--defaults-group-suffix Option group suffix value  
--enable-cleartext-plugin Enable cleartext authentication plugin 5.6.28
--extended Check and repair tables  
--fast Check only tables that have not been closed properly  
--fix-db-names Convert database names to 5.1 format  
--fix-table-names Convert table names to 5.1 format  
--force Continue even if an SQL error occurs  
--help Display help message and exit  
--host Connect to MySQL server on given host  
--login-path Read login path options from .mylogin.cnf 5.6.6
--medium-check Do a check that is faster than an --extended operation  
--no-defaults Read no option files  
--optimize Optimize the tables  
--password Password to use when connecting to server  
--pipe On Windows, connect to server using named pipe  
--plugin-dir Directory where plugins are installed 5.6.2
--port TCP/IP port number to use for connection  
--print-defaults Print default options  
--protocol Connection protocol to use  
--quick The fastest method of checking  
--repair Perform a repair that can fix almost anything except unique keys that are not unique  
--secure-auth Do not send passwords to server in old (pre-4.1) format 5.6.17
--shared-memory-base-name The name of shared memory to use for shared-memory connections  
--silent Silent mode  
--skip-database Omit this database from performed operations 5.6.11
--socket For connections to localhost, the Unix socket file to use  
--ssl Enable secure connection  
--ssl-ca Path of file that contains list of trusted SSL CAs  
--ssl-capath Path of directory that contains trusted SSL CA certificates in PEM format  
--ssl-cert Path of file that contains X509 certificate in PEM format  
--ssl-cipher List of permitted ciphers to use for connection encryption  
--ssl-crl Path of file that contains certificate revocation lists 5.6.3
--ssl-crlpath Path of directory that contains certificate revocation list files 5.6.3
--ssl-key Path of file that contains X509 key in PEM format  
--ssl-verify-server-cert Verify server certificate Common Name value against host name used when connecting to server  
--tables Overrides the --databases or -B option  
--use-frm For repair operations on MyISAM tables  
--user MySQL user name to use when connecting to server  
--verbose Verbose mode  
--version Display version information and exit  
--write-binlog Log ANALYZE, OPTIMIZE, REPAIR statements to binary log. --skip-write-binlog adds NO_WRITE_TO_BINLOG to these statements.

不知道这个分析都做了什么动作,分析些什么内容

---------------------------------------

mysqlshow显示表的信息

 mysqlshow -h XXXX -P3307 test --status -t  下面是显示数据库中包含一个特定列的所有表信息的shell

#!/bin/sh
#This scripts returns all the tables in a database that contains some field

function usage
{
echo "Usage: $0 USER DB COLUMN"
}

function ExistsColumn
{
local USER=$1
local DB=$2
local TABLE=$3
local COLUMN=$4

SEARCH_RESULT=$(mysqlshow -u ${USER} ${DB} ${TABLE} ${COLUMN} | awk '{ if ( NR == 5) print $2 }')
if [ "${COLUMN}" = "${SEARCH_RESULT}" ];
then
echo "true";
else
echo "false";
fi
}

function main
{
local USER=$1
local DB=$2
local COLUMN=$3

if [[ "${USER}" = "" || "${DB}" = "" || "${COLUMN}" = "" ]];
then
usage
exit 1
fi

all_tables=$(mysqlshow -u ${USER} ${DB} | \
awk '{ if (NR >4 ) print $_}' | \
sed -e 's/[|+-]//g; /^$/d ' | \
xargs )
for TABLE in ${all_tables}; do
if [ "true" = "$(ExistsColumn $USER $DB $TABLE $COLUMN)" ];
then
echo $TABLE
fi
done

}

main $*





你可能感兴趣的:(mysql客户端工具使用)