mysqladmin命令用法
mysqladmin 工具的使用格式:
mysqladmin [option] command [command option] command ......
option 选项:
-c number 自动运行次数统计,必须和 -i 一起使用
-i number 间隔多长时间重复执行
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 得到服务器的版本信息
示例:
--每个两秒查看一次服务器的状态,总共重复5次
./mysqladmin -uroot -p -i 2 -c 5 status
--修改密码
mysqladmin -uroot -ptest passoword 新密码 --不要在新密码后添加分号
--判断服务是否启动
[root@localhost bin]# mysqladmin -uroot -predhat ping mysqladmin: [Warning] Using a password on the command line interface can be insecure. mysqld is alive [root@localhost bin]#
--关闭服务
mysqladmin -utest -ptest1 shutdown
--查看mysql版本
[root@localhost bin]# mysqladmin -uroot -predhat version mysqladmin: [Warning] Using a password on the command line interface can be insecure. mysqladmin Ver 8.42 Distrib 5.7.17, for linux-glibc2.5 on x86_64 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 5.7.17-log Protocol version 10 Connection Localhost via UNIX socket UNIX socket /tmp/mysql.sock Uptime: 5 hours 55 min 56 sec Threads: 6 Questions: 1936 Slow queries: 21 Opens: 840 Flush tables: 1 Open tables: 124 Queries per second avg: 0.090 [root@localhost bin]#
--查看所有的全局变量
mysqladmin -utest -ptest1 variables
--mysql的状态
[root@localhost bin]# mysqladmin -uroot -predhat status mysqladmin: [Warning] Using a password on the command line interface can be insecure. Uptime: 21197 Threads: 6 Questions: 1932 Slow queries: 21 Opens: 840 Flush tables: 1 Open tables: 124 Queries per second avg: 0.091 [root@localhost bin]#
--查询所有mysql连接的客户端
[root@localhost bin]# mysqladmin -uroot -predhat processlist mysqladmin: [Warning] Using a password on the command line interface can be insecure. +----+------+---------------------+--------------+---------+-------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+---------------------+--------------+---------+-------+----------+------------------+ | 5 | root | 192.168.0.206:64294 | | Sleep | 14779 | | | | 8 | root | 192.168.0.206:64297 | | Sleep | 21287 | | | | 10 | root | localhost | | Sleep | 2430 | | | | 22 | root | 192.168.0.206:54750 | account_data | Sleep | 3160 | | | | 23 | root | 192.168.0.206:54751 | account_data | Sleep | 14764 | | | | 32 | root | localhost | | Query | 0 | starting | show processlist | +----+------+---------------------+--------------+---------+-------+----------+------------------+ [root@localhost bin]#
--杀掉某个客户端的链接
C:\>mysqladmin -utest -ptest1 kill 7,8
C:\>mysqladmin -utest -ptest1 processlist
+----+------+----------------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+----------------+----+---------+------+-------+------------------+
| 12 | test | localhost:3112 | | Query | 0 | | show processlist |
+----+------+----------------+----+---------+------+-------+------------------+
--创建数据库和删除数据库
C:\>mysqladmin -utest -ptest1 create aaa
C:\>mysqladmin -utest -ptest1 drop aaa
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 'aaa;' database [y/N] y
Database "aaa;" dropped
--查询服务器拓展的状态
mysqladmin -utest -ptest1 extended-status
--重载授权表
mysqladmin -utest -ptest1 reload
mysqladmin -utest -ptest1 flush-privileges
--刷新所有表缓存,并关闭和打开log
./mysqladmin -uroot -p refresh
--使用安全模式关闭数据库
./mysqladmin -uroot -p shutdown
--显示服务器上的所有数据库
./mysqlshow -uroot -p
--显示数据库daba-test下有些什么表:
./mysqlshow -uroot -p daba-test
--统计daba-test 下数据库表列的汇总
./mysqlshow -uroot -p daba-test -v
--统计daba-test 下数据库表的列数和行数
./mysqlshow -uroot -p daba-test -v -v