首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MYSQL入门学习之十八:MYSQLADMIN下令参数详解

2012-12-25 
MYSQL入门学习之十八:MYSQLADMIN命令参数详解mysqladmin工具主要用来对数据库做一些简单的操作,以及显示服

MYSQL入门学习之十八:MYSQLADMIN命令参数详解
        mysqladmin工具主要用来对数据库做一些简单的操作,以及显示服务器状态等。其使用格式如下:
        mysqladmin [option] command [command option] command ......
        在命令行中输入mysqladmin -?,打印出如下帮助信息

-c, --count=#Number of iterations to make. This works with -i (--sleep) only.自动运行次数,必须和 -i 一起使用--debug-checkCheck memory and open file usage at exit .--debug-infoPrint some debug info at exit.-f, --forceDon't ask for confirmation on drop database; with multiple commands, continue even if an error occurs.禁用错误,drop 数据库时不提示,执行多条命令时出错继续执行-C, --compressUse compression in server/client protocol.在服务器和客户端之间使用压缩--character-sets-dir=nameDirectory where character sets are.设置字符集目录--default-character-set=nameSet the default character set.设置字符集默认目录-?, --helpDisplay this help and exit.显示帮助信息-h, --host=nameConnect to host.主机名-b, --no-beepTurn off beep on error.报错时,不响铃(嘟的一声)-p, --password[=name]Password to use when connecting to server. If password is not given it's asked from the tty.服务器连接密码-W, --pipeUse named pipes to connect to server.使用命名管道连接服务器-P, --port=#Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).端口号--protocol=nameThe protocol of connection (tcp,socket,pipe,memory).设置连接使用的协议-r, --relativeShow difference between current and previous values when used with -i. Currently works only with extended-status.显示前后变化的值,必须结合- i-O, --set-variable=nameChange the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.修改变量的值,使用--variable-name=value 的方式修改变量值--shared-memory-base-name=nameBase name of shared memory.-s, --silentSilently exit if one can't connect to server.如果连接服务器失败则退出-S, --socket=nameSocket file to use for connection.指定socket file-i, --sleep=#Execute commands again and again with a sleep between.间隔一段时间执行一次--sslEnable SSL for connection (automatically enabled with other flags). Disable with --skip-ssl.--ssl-ca=nameCA file in PEM format (check OpenSSL docs, implies --ssl).--ssl-capath=nameCA directory (check OpenSSL docs, implies --ssl).--ssl-cert=nameX509 cert in PEM format (implies --ssl).--ssl-cipher=nameSSL cipher to use (implies --ssl).--ssl-key=nameX509 key in PEM format (implies --ssl).--ssl-verify-server-cert Verify server's "Common Name" in its cert against hostname used when connecting. This option is disabled by default.-u, --user=nameUser for login if not current user.用户名-v, --verboseWrite more information.-V, --versionOutput version information and exit.显示MYSQLADMIN的版本-E, --verticalPrint output vertically. Is similar to --relative, but prints output vertically.垂直显示输出-w, --wait[=#]Wait and retry if connection is down.如果连接断开,则等待并重试--connect_timeout=#连接超时--shutdown_timeout=#超时关闭        示例:

create databasenameCreate a new database创建一个新数据库debugInstruct server to write debug information to log通知服务器将调试信息写入日志drop databasenameDelete a database and all its tables删除一个数据库及其所有表extended-statusGives an extended status message from the server给出服务器的一个扩展状态消息flush-hostsFlush all cached hosts清除所有缓存的主机flush-logsFlush all logs清除所有日志flush-statusClear status variablesflush-tablesFlush all tables清除所有表flush-threadsFlush the thread cache清除线程缓存flush-privilegesReload grant tables (same as reload)再次装载授权表(同reload)kill id,id,...Kill mysql threads杀死mysql线程password new-passwordChange old password to new-password, MySQL 4.1 hashing.将老口令改为新口令old-password new-passwordChange old password to new-password in old format.修改口令pingCheck if mysqld is alive检查mysqld是否在线processlistShow list of active threads in server显示服务其中活跃线程列表reloadReload grant tables重载授权表refreshFlush all tables and close and open logfiles洗掉所有表并关闭和打开日志文件shutdownTake server down关掉服务器statusGives a short status message from the server给出服务器的简短状态消息start-slaveStart slave启动slavestop-slaveStop slave关闭slavevariablesPrints variables available打印出可用变量versionGet version info from server得到服务器的版本信息

        示例:

C:\Users\qxl>mysqladmin -uroot versionmysqladmin  Ver 8.42 Distrib 5.1.28-rc, for Win32 on ia32Copyright (C) 2000-2006 MySQL ABThis software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL licenseServer version          5.1.28-rc-communityProtocol version        10Connection              localhost via TCP/IPTCP port                3306Uptime:                 31 min 3 secThreads: 1  Questions: 23  Slow queries: 0  Opens: 16  Flush tables: 2  Open tables: 0  Queries per second avg: 0.12C:\Users\qxl>mysqladmin -u root -p create test_adminEnter password:C:\Users\qxl>mysqladmin -u root -p drop test_adminEnter password:Dropping the database is potentially a very bad thing to do.Any data stored in the database will be destroyed.Do you really want to drop the 'test_admin' database [y/N] yDatabase "test_admin" droppedC:\Users\qxl>mysqladmin -u root flush-statusC:\Users\qxl>mysqladmin -u root processlist+----+------+----------------+----+---------+------+-------+------------------+| Id | User | Host           | db | Command | Time | State | Info             |+----+------+----------------+----+---------+------+-------+------------------+| 21 | root | localhost:8925 |    | Query   | 0    |       | show processlist |+----+------+----------------+----+---------+------+-------+------------------+C:\Users\qxl>mysqladmin -u root statusUptime: 1947  Threads: 1  Questions: 32  Slow queries: 0  Opens: 18  Flush tables: 2  Open tables: 2  Queries per second avg: 0.16
        其中mysqladmin -u root status输出信息中各项的详细说明如下:

        Uptime:MySQL服务器已经运行的秒数
        Threads:活跃线程(客户)的数量
        Questions:从mysqld启动起来自客户查询的数量
        Slow queries:已经超过long_query_time秒的查询数量
        Opens:mysqld已经打开了多少表
        Flush tables:flush ..., refresh和reload命令数量
        Open tables:现在被打开的表数量
        Queries per second avg:查询平均用时

热点排行