共計(jì) 3600 個(gè)字符,預(yù)計(jì)需要花費(fèi) 9 分鐘才能閱讀完成。
本篇內(nèi)容主要講解“如何使用 mysqladmin 管理 mysql”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓丸趣 TV 小編來帶大家學(xué)習(xí)“如何使用 mysqladmin 管理 mysql”吧!
mysqladmin 是 mysql 數(shù)據(jù)庫(kù)中的專用管理工具,通過該工具可以完成檢查服務(wù)器配置、當(dāng)前狀態(tài)、創(chuàng)建 / 刪除數(shù)據(jù)庫(kù)等操作。
用法:
Usage: mysqladmin [OPTIONS] command command….
常用參數(shù):
● -i,–sleep=#:重復(fù)執(zhí)行該命令的間隔時(shí)間。
● -r,–relative:當(dāng)于 - i 參數(shù)聯(lián)合使用并且指定了 extended-status 命令時(shí),顯示本次與上次之間,各狀態(tài)值之間的差異。
常用命令:
● create databasename:創(chuàng)建數(shù)據(jù)庫(kù)
● drop databasename:刪除數(shù)據(jù)庫(kù)
● extended-status:查看服務(wù)端狀態(tài)信息,和在 mysql 命令行模式下執(zhí)行 show global status 的功能一樣。
● flush-logs:刷新日志。
● flush-status:重置狀態(tài)變量。
● flush-tables:刷新所有表。
● flush-threads:刷新線程緩存。
● flush-privileges:重新加載授權(quán)表,功能與 reload 命令完全相同。
● refresh:刷新所有表,請(qǐng)切換日志文件。
● password [new-password]:修改指定用戶的密碼,功能與 set password 語句完全相同。
● ping:通過 ping 的方式,檢查當(dāng)前 mysql 服務(wù)是否仍能正常提供服務(wù)。
● kill id、id、…:殺掉連接至 mysql 服務(wù)器的線程,功能與 kill id 語句完全相同。
● processlist:查看當(dāng)前 mysql 服務(wù)所有的連接線程信息。功能完全等同于 show processlist 語句。常用。
● shutdown:關(guān)閉數(shù)據(jù)庫(kù)。常用。
● status:查看當(dāng)前 mysql 的狀態(tài),只顯示 mysql 命令行模式下 status 命令的最后一行信息。
● start-slave:?jiǎn)?dòng) slave 服務(wù),跟 start slave 語句功能完全相同。
● stop-slave:停止 slave 服務(wù),跟 stop slave 語句功能完全相同。
● variables:顯示系統(tǒng)變量,功能與 show global variables 語句完全相同。
● version:查看版本信息,同時(shí)還包括 status 命令的信息。
用法示例:
(1)創(chuàng)建和刪除數(shù)據(jù)庫(kù)
[root@oeldb1 ~]# mysqladmin -uroot -p123456 create test1
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@oeldb1 ~]# mysqladmin -uroot -p123456 drop test1;
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
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 test1 database [y/N] y
Database test1 dropped
(2)查看狀態(tài)信息
[root@oeldb1 ~]# mysqladmin -uroot -p123456 status
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Uptime: 952 Threads: 2 Questions: 12 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.012
其中:
● Uptime: mysql 服務(wù)的啟動(dòng)時(shí)間。
● Threads: 當(dāng)前連接的會(huì)話數(shù)。
● Questions: 自 mysql 服務(wù)啟動(dòng)后,執(zhí)行的查詢語句數(shù)量。
● Slow queries: 慢查詢語句的數(shù)量。
● Opens: 當(dāng)前處于打開狀態(tài)的表對(duì)象的數(shù)量。
● Flush tables: 執(zhí)行過 flush-*、refresh 和 reload 命令的數(shù)量。
● Open tables: 當(dāng)前會(huì)話打開的表對(duì)象的數(shù)量。
● Queries per second avg: 查詢的執(zhí)行頻率。
詳細(xì)的狀態(tài)信息:
[root@oeldb1 ~]# mysqladmin -uroot -p123456 extended-status | grep -i max
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
| Connection_errors_max_connections | 0 |
| Innodb_row_lock_time_max | 0 |
| Max_execution_time_exceeded | 0 |
| Max_execution_time_set | 0 |
| Max_execution_time_set_failed | 0 |
| Max_used_connections | 1 |
| Max_used_connections_time | 2017-06-25 21:22:48 |
| Tc_log_max_pages_used | 0 |
(3)查看 mysq 服務(wù)是否 alive
[root@oeldb1 ~]# mysqladmin -uroot -p123456 ping
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive
(4)每隔一秒輸出一下當(dāng)前 mysql 服務(wù)的狀態(tài)信息:
[root@oeldb1 ~]# mysqladmin -uroot -p123456 -i 1 status
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Uptime: 1069 Threads: 2 Questions: 14 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.013
Uptime: 1070 Threads: 2 Questions: 15 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.014
Uptime: 1071 Threads: 2 Questions: 16 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.014
Uptime: 1072 Threads: 2 Questions: 17 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.015
Uptime: 1073 Threads: 2 Questions: 18 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.016
Uptime: 1074 Threads: 2 Questions: 19 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.017
(5)每秒執(zhí)行的查詢數(shù)量:
[root@oeldb1 ~]# mysqladmin -uroot -p123456 -i 1 -r extended-status | grep -e Com_select
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
| Com_select | 0 |
| Com_select | 0 |
| Com_select | 0 |
| Com_select | 0 |
| Com_select | 0 |
到此,相信大家對(duì)“如何使用 mysqladmin 管理 mysql”有了更深的了解,不妨來實(shí)際操作一番吧!這里是丸趣 TV 網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!