MySQLAdmin用法
用于执行管理性操作。语法是:
shell> mysqladmin [OPTIONS] command [command-option] command ...
通过执行mysqladmin --help,你可以得到你mysqladmin的版本所支持的一个选项列表。
目前mysqladmin支持下列命令:
create databasename 创建一个新数据库
drop databasename 删除一个数据库及其所有表
extended-status 给出服务器的一个扩展状态消息 相当于SHOW GLOBAL STATUS;
flush-hosts 洗掉所有缓存的主机
flush-logs 洗掉所有日志
flush-tables 洗掉所有表
flush-privileges 再次装载授权表(同reload)
kill id,id,... 杀死mysql线程
password 新口令,将老口令改为新口令
ping 检查mysqld是否活着
processlist 显示服务其中活跃线程列表
reload 重载授权表
refresh 洗掉所有表并关闭和打开日志文件
shutdown 关掉服务器
status 给出服务器的简短状态消息
variables 打印出可用变量
version 得到服务器的版本信息
mysqladmin status命令结果有下述列:
Uptime MySQL服务器已经运行的秒数
Threads 活跃线程(客户)的数量
Questions 从mysqld启动起来自客户问题的数量 已经发送给服务器的查询的个数
Slow queries 已经超过long_query_time秒的查询数量
Opens mysqld已经打开了多少表
Flush tables flush ..., refresh和reload命令数量
Open tables 现在被打开的表数量
Memory in use 由mysqld代码直接分配的内存(只有在MySQL用--with-debug编译时可用)
Max memory used 由mysqld代码直接分配的最大内存(只有在MySQL用--with-debug编译时可用)
SHOW GLOBAL STATUS;
--查看MySQL本次启动后的运行时间(单位:秒)
show status like 'uptime';
--查看select语句的执行数
show [global] status like 'com_select';
--查看insert语句的执行数
show [global] status like 'com_insert';
--查看update语句的执行数
show [global] status like 'com_update';
--查看delete语句的执行数
show [global] status like 'com_delete';
--查看试图连接到MySQL(不管是否连接成功)的连接数
show status like 'connections';
--查看线程缓存内的线程的数量。
show status like 'threads_cached';
--查看当前打开的连接的数量。
show status like 'threads_connected';
--查看当前打开的连接的数量。
show status like 'threads_connected';
--查看创建用来处理连接的线程数。如果Threads_created较大,你可能要增加thread_cache_size值。
show status like 'threads_created';
--查看激活的(非睡眠状态)线程数。
show status like 'threads_running';
--查看立即获得的表的锁的次数。
show status like 'table_locks_immediate';
--查看不能立即获得的表的锁的次数。如果该值较高,并且有性能问题,你应首先优化查询,然后拆分表或使用复制。
show status like 'table_locks_waited';
--查看创建时间超过slow_launch_time秒的线程数。
show status like 'slow_launch_threads';
--查看查询时间超过long_query_time秒的查询的个数。
show status like 'slow_queries';
shell 脚本例子:
#!/bin/bash
# 用户名
MYSQL_USER='root'
# 密码
MYSQL_PWD='mysql'
# 主机地址/IP
MYSQL_HOST='127.0.0.1'
# 端口
MYSQL_PORT='3306'
# 数据连接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
echo $MYSQL_CONN
# 参数是否正确
if [ $# -ne "1" ];then
echo "arg error!"
fi
# 获取数据
case $1 in
Uptime)
result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` # MySQL服务器已经运行的秒数
echo $result
;;
Com_update)
result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` # 查看update语句的执行数
echo $result
;;
Slow_queries)
result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` # long_query_time 已经超过long_query_time秒的查询数量
echo $result
;;
Com_select)
result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` # 查看select语句的执行数
echo $result
;;
Com_rollback)
result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` # 查看事物回滚的执行数
echo $result
;;
Questions)
result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` # 从mysqld启动起来自客户问题的数量
echo $result
;;
Com_insert)
result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` # 查看insert语句的执行数
echo $result
;;
Com_delete)
result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` # 查看delete语句的执行数
echo $result
;;
Com_commit)
result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` # 查看commit语句的执行数
echo $result
;;
Bytes_sent)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` # 已经发送给客户端的字节数
echo $result
;;
Bytes_received)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` # 从客户端处已经接收到的字节数
echo $result
;;
Com_begin)
result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac
MySQLAdmin用法
用于执行管理性操作。语法是:
shell> mysqladmin [OPTIONS] command [command-option] command ...
通过执行mysqladmin --help,你可以得到你mysqladmin的版本所支持的一个选项列表。
目前mysqladmin支持下列命令:
create databasename 创建一个新数据库
drop databasename 删除一个数据库及其所有表
extended-status 给出服务器的一个扩展状态消息
flush-hosts 洗掉所有缓存的主机
flush-logs 洗掉所有日志
flush-tables 洗掉所有表
flush-privileges 再次装载授权表(同reload)
kill id,id,... 杀死mysql线程
password 新口令,将老口令改为新口令
ping 检查mysqld是否活着
processlist 显示服务其中活跃线程列表
reload 重载授权表
refresh 洗掉所有表并关闭和打开日志文件
shutdown 关掉服务器
status 给出服务器的简短状态消息
variables 打印出可用变量
version 得到服务器的版本信息