mysqladmin 工具的使用格式:
mysqladmin [option] command [command option] command ......
option 選項:
-c number 自動運行次數統計,必須和 -i 一起使用
-i number 間隔多長時間重復執行
每個兩秒查看一次服務器的狀態,總共重復5次。
./mysqladmin -uroot -p -i 2 -c 5 status
-#, --debug[=name] Output debug log. Often this is 'd:t:o,filename'.
-f, --force Don't ask for confirmation on drop database; with
multiple commands, continue even if an error occurs. 禁用錯誤,drop 數據庫時不提示,執行多條命令時出錯繼續執行
-C, --compress Use compression in server/client protocol.
--character-sets-dir=name 字符集所在目錄
Directory where character sets are.
--default-character-set=name 設置默認字符集
Set the default character set.
-?, --help Display this help and exit. 顯示幫助
-h, --host=name Connect to host. 連接的主機名或iP
-p, --password[=name] 登錄密碼,如果不寫於參數後,則會提示輸入
Password to use when connecting to server. If password is
not given it's asked from the tty.
-P, --port=# Port number to use for connection. 指定數據庫端口
--protocol=name The protocol of connection (tcp,socket,pipe,memory). 指定連接協議
-r, --relative Show difference between current and previous values when
used with -i. Currently works only with extended-status. 顯示前後變化的值,必須結合- i
./mysqladmin -uroot -p -i 2 -r extended-status
假如此處顯示的uptime 將永遠是2,因為與之前取的結果比只相差2.
-O, --set-variable=name
Change the value of a variable. Please note that this
option is deprecated; you can set variables directly with
--variable-name=value.修改變量的值,該選項已經不再使用,請使用--variable-name=value 的方式修改變量值
-s, --silent Silently exit if one can't connect to server.
-S, --socket=name Socket file to use for connection. 指定socket file
-i, --sleep=# Execute commands again and again with a sleep between. 間隔一段時間執行一次
-u, --user=name User for login if not current user.登錄數據庫用戶名
-v, --verbose Write more information. 寫更多的信息
-V, --version Output version information and exit. 顯示版本
./mysql -uroot -p -V
-E, --vertical Print output vertically. Is similar to --relative, but
prints output vertically.
-w, --wait[=#] Wait and retry if connection is down. 如果連接斷開,等待w 指定的時間後重試
--connect_timeout=#
--shutdown_timeout=#
1、查看服務器的狀況:status
./mysql -uroot -p status
顯示結果:
Uptime: 4883162 Threads: 1 Questions: 86 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 18 Queries per second avg: 0.000
2.修改root 密碼:
mysqladmin -u root -poldpassword password 'newpassword'
3.檢查mysqlserver是否可用:
mysqladmin -uroot -p ping
顯示結果:
mysqld is alive
4.查詢服務器的版本
mysqladmin -uroot -p version
5.查看服務器狀態的當前值:
mysqladmin -uroot -p extended-status
顯示結果:
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
| Aborted_clients | 12 |
| Aborted_connects | 300 |
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Bytes_received | 23608 |
| .......
|Threads_created | 3 |
| Threads_running | 1 |
| Uptime | 4884294 |
+-----------------------------------+----------+
6.查詢服務器系統變量值:
mysqladmin -uroot -p variables
顯示結果:
+---------------------------------+----------------------------------------+
| Variable_name | Value |
+---------------------------------+----------------------------------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| automatic_sp_privileges | ON |
| back_log | 50 |
| basedir | /usr/local/mysql/ |
..
7.顯示服務器所有運行的進程:
mysqladmin -uroot -p processlist
mysqladmin -uroot -p-i 1 processlist 每秒刷新一次
顯示結果:
+-----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+----+---------+------+-------+------------------+
| 331 | root | localhost | | Query | 0 | | show processlist |
+-----+------+-----------+----+---------+------+-------+------------------+
8.創建數據庫
./mysqladmin -uroot -p create daba-test
驗證:
./mysql -uroot -p 登錄後:show databases;
9.顯示服務器上的所有數據庫
./mysqlshow -uroot -p
10.顯示數據庫daba-test下有些什麼表:
./mysqlshow -uroot -p daba-test
11.統計daba-test 下數據庫表列的匯總
./mysqlshow -uroot -p daba-test -v
12.統計daba-test 下數據庫表的列數和行數
./mysqlshow -uroot -p daba-test -v -v