ubuntu 安裝使用 mytop

apt搜索一下

$ sudo apt search mytop
Sorting... Done
Full Text Search... Done
mytop/focal,focal,now 1.9.1-4 all
  top like query monitor for MySQL

然後安裝一下

 sudo apt-get install mytop  

直接執行 mytop 報錯

$ mytop
Cannot connect to MySQL server. Please check the:

  * database you specified "" (default is "")
  * username you specified "root" (default is "root")
  * password you specified "" (default is "")
  * hostname you specified "localhost" (default is "localhost")
  * port you specified "3306" (default is 3306)
  * socket you specified "" (default is "")

The options my be specified on the command-line or in a ~/.mytop or
~/.my.cnf config file. See the manual (perldoc mytop) for details.

Here's the exact error from DBI. It might help you debug:

Access denied for user 'root'@'localhost' (using password: NO)

說我沒有找到 .mytop 或者 my.cnf 文件,那麼這個文件應該怎麼配置呢?通過find尋找發現了跟mytop有關的文件夾

$ sudo find / -name "mytop"
find: ‘/proc/2308/task/2308/net’: Invalid argument
find: ‘/proc/2308/net’: Invalid argument
find: ‘/run/user/1001/doc’: Permission denied
find: ‘/run/user/1001/gvfs’: Permission denied
/usr/bin/mytop
/usr/share/doc/mytop

這個就是可執行文件,不是它

$ ll /usr/bin/mytop 
-rwxr-xr-x 1 root root 60K 1月  10  2017 /usr/bin/mytop*

 發現這個有配置,然後查看一下這個默認配置有個參考

$ ll /usr/share/doc/mytop
total 12K
-rw-r--r-- 1 root root 2.2K 1月  10  2017 changelog.Debian.gz
-rw-r--r-- 1 root root 1.3K 1月  10  2017 copyright
-rw-r--r-- 1 root root  871 1月  10  2017 mytop.sample.conf

發現了這個 simple conf 。好了,如此以來應該是要按這個配置,看一下它的內容

# Copy this file to ~/.mytop and customize it to your own needs

# Username to use when logging in to the MySQL server
user=root
# Password to use when logging in to the MySQL server
pass=
# Hostname of the MySQL server.
host=localhost
# Port number of the MySQL server.
port=3306
# Connect to specific database by default.
db=test
# How long between display refreshes.
delay=5
# Use direct socket instead of TCP/IP network to connect to the MySQL server.
socket=
# Run mytop only once and than exit.
batchmode=0
# Display headers or not.
header=1
# Use colors if available.
color=1
# Display idle threads.
idle=1
# Resolve IP addresses to names.
resolve=1
# Compact large numbers for better readability, e.g. 10.000 -> 10.0k.
long=0
# Reverse sort order from ascending to descending using Idle time.
sort=0
# Use vt100 escape sequences to reduce screen flicker.
vt100=0

然後配置一份文件到 

touch ~/.mytop

這個文件裏面配置如下內容

# Copy this file to ~/.mytop and customize it to your own needs

# Username to use when logging in to the MySQL server
user=root
# Password to use when logging in to the MySQL server
pass=密碼
# Hostname of the MySQL server.
host=localhost
# Port number of the MySQL server.
port=3306
# Connect to specific database by default.
db=test
# How long between display refreshes.
delay=5
# Use direct socket instead of TCP/IP network to connect to the MySQL server.
socket=/tmp/mysql.sock
# Run mytop only once and than exit.
batchmode=0
# Display headers or not.
header=1
# Use colors if available.
color=1
# Display idle threads.
idle=1
# Resolve IP addresses to names.
resolve=1
# Compact large numbers for better readability, e.g. 10.000 -> 10.0k.
long=0
# Reverse sort order from ascending to descending using Idle time.
sort=0
# Use vt100 escape sequences to reduce screen flicker.
vt100=0

 如此以來就配置好了。重新啓動一下看看。

$ mytop

得到

 這樣以來就可以用它監控mysql 的 qps 了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章