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
