diff --git a/Menu/DBA_Toolbox_Logo.png b/Menu/DBA_Toolbox_Logo.png new file mode 100644 index 0000000000000000000000000000000000000000..66d7e501f154e738eeb2dfb30db5ef1b432d3a5a Binary files /dev/null and b/Menu/DBA_Toolbox_Logo.png differ diff --git "a/Menu/\345\276\256\344\277\241\345\233\276\347\211\207_20230329094139.png" "b/Menu/\345\276\256\344\277\241\345\233\276\347\211\207_20230329094139.png" deleted file mode 100644 index 60357bf213983e682d6dc593965d6da03ca78f93..0000000000000000000000000000000000000000 Binary files "a/Menu/\345\276\256\344\277\241\345\233\276\347\211\207_20230329094139.png" and /dev/null differ diff --git a/Privileges/Privileges_Inspection.go b/Privileges/Privileges_Inspection.go index a2fa8b3e484c746c9b3e4c5d889775e7be783e9a..22f2fb93a3583ad56b06cddf89415ebcbfaeb238 100644 --- a/Privileges/Privileges_Inspection.go +++ b/Privileges/Privileges_Inspection.go @@ -20,7 +20,8 @@ var ( Completed = color.S256(255, 27) ) -var user_usera_slice = make([]string, 0, 30) +var user_username_slice = make([]string, 0, 30) +var user_userhost_slice = make([]string, 0, 30) func Privileges_Inspection() { sqlStr := "select user,host from mysql.user where user not in ('mysql.session','mysql.sys','mysql.infoschema');" @@ -34,8 +35,8 @@ func Privileges_Inspection() { for counts.Next() { var user User err := counts.Scan(&user.TABLE_SCHEMA, &user.TABLE_NAME) - user_usera_slice = append(user_usera_slice, user.TABLE_SCHEMA) - + user_username_slice = append(user_username_slice, user.TABLE_SCHEMA) + user_userhost_slice = append(user_userhost_slice, user.TABLE_NAME) if err != nil { panic(err.Error()) } @@ -47,9 +48,10 @@ func Privileges_Inspection() { func User_Privileges_Inspection() { var user User - for j := 0; j < len(user_usera_slice); j++ { - values := user_usera_slice[j] - sqlStr := "show grants for" + "'" + values + "'" + for j := 0; j < len(user_username_slice); j++ { + userName := user_username_slice[j] + userHost := user_userhost_slice[j] + sqlStr := "show grants for" + "'" + userName + "'@'" + userHost + "'" err := Global.DB.QueryRow(sqlStr).Scan(&user.TABLE_SCHEMA) if err != nil { fmt.Printf("scan failed, err:%v\n", err) diff --git a/README.md b/README.md index f4f576869fe6585d63bf5a11ddf807978e75c166..bdaedb3084d379884afed684e90f806b1a6897bb 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,10 @@ [![](https://img.shields.io/badge/GreatSQL-博客-brightgreen.svg)](https://greatsql.cn/home.php?mod=space&uid=10&do=blog&view=me&from=space) [![](https://img.shields.io/badge/License-Apache_v2.0-blue.svg)](https://gitee.com/GreatSQL/GreatSQL/blob/master/LICENSE) [![](https://img.shields.io/badge/release-1.2.1-blue.svg)](https://gitee.com/GreatSQL/gt-checksum/releases/tag/1.2.1) -![输入图片说明](Menu/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230329094139.png) -# 数据库巡检工具 DB OSInspection +![输入图片说明](Menu/DBA_Toolbox_Logo.png) +# DBA工具箱 DBA_TOOLBOX ## 简介: -DB_OSInspection 数据库巡检工具,实现对数据库一秒巡检,对实例有大概了解。 -该工具具有简单易用、高效准确等特点,非常适合运维人员和开发人员使用。 +这款软件是一个全面的数据库管理工具,旨在帮助DBA更轻松地管理和维护数据库。它提供了各种功能,包括数据库监控、性能优化、备份和恢复、安全管理、查询分析等等。此外,它还支持多种数据库平台,如MySQL、Oracle、SQL Server等。无论您是初学者还是经验丰富的DBA,这个工具箱都将成为您工作中不可或缺的助手。 ## 下载 - [V1.2 Windows版本](https://gitee.com/KAITOO/db_-osinspection/releases/download/V1.2/DB_OSInspection.exe) @@ -15,13 +14,13 @@ DB_OSInspection 数据库巡检工具,实现对数据库一秒巡检,对实 ## 快速上手 ```go Windows环境下可直接使用,不能保存巡检结果 -./DB_OSInspection -u 用户名 -p 密码 +./DBA_TOOLBOX -u 用户名 -p 密码 在Linux环境下保存巡检结果可以用 - ./DB_OSInspection -u 用户名 -p 密码 >err.log + ./DBA_TOOLBOX -u 用户名 -p 密码 >err.log 监测模式 -./DB_OSInspection -u 用户名 -p 密码 -m monitor +./DBA_TOOLBOX -u 用户名 -p 密码 -m monitor ``` ### 参数解析 **所有输入后面都需要跟空格,否则会错误** @@ -35,50 +34,26 @@ Windows环境下可直接使用,不能保存巡检结果 - -h 输出帮助 ## 已实现功能 ### 实现数据库监控可实时输出 --m 选择monitor 模式即可 +-m 选择monitor 模式即可时间监控通用日志,实现对数据库操作实时输出 ### 实现表巡检 -- 大小超过10G的表 -- 索引超过6个的表 -- 碎片率超过50%的表 -- 行数超过1000万行的表 -- 非默认字符集的表 -- 含有大字段的表 -- varchar定义超长的表 -- 无主键/索引的表 +- 大小超过10G的表 \ 索引超过6个的表 \ 碎片率超过50%的表 +- 行数超过1000万行的表 \ 非默认字符集的表 \ 含有大字段的表 +- varchar定义超长的表 \ 无主键/索引的表 ### 索引巡检 -- 重复索引 -- 索引列超过5个的索引 -- 无用索引 +- 重复索引 \ 索引列超过5个的索引 \ 无用索引 ### 重要参数 -- version -- innodb_buffer_pool_size -- innodb_flush_log_at_trx_commit -- innodb_log_file_size -- innodb_log_files_in_group -- innodb_file_per_table -- innodb_max_dirty_pages_pct -- sync_binlog -- max_connections -- table_open_cache -- table_definition_cache +- version\innodb_buffer_pool_size\innodb_flush_log_at_trx_commit +- innodb_log_file_size\innodb_log_files_in_group\innodb_file_per_table +- innodb_max_dirty_pages_pct\sync_binlog\max_connections +- table_open_cache\table_definition_cache ### 重要状态指标 -- Uptime -- Opened_files -- Opened_table_definitions -- Opened_tables -- Max_used_connections -- Threads_created -- Threads_connected -- Aborted_connects -- Aborted_clients -- Table_locks_waited -- Innodb_buffer_pool_wait_free -- Innodb_log_waits -- Table_locks_waited -- Innodb_row_lock_waits -- Innodb_row_lock_time_avg -- Binlog_cache_disk_use -- Created_tmp_disk_tables +- Uptime\Opened_files\Opened_table_definitions +- Opened_tables\Max_used_connections +- Threads_created\Threads_connected +- Aborted_connects\Aborted_clients\Table_locks_waited +- Innodb_buffer_pool_wait_free\Innodb_log_waits +- Table_locks_waited\Innodb_row_lock_waits +- Innodb_row_lock_time_avg\Binlog_cache_disk_use\Created_tmp_disk_tables ### 用户检查 - 无密码用户 - %用户 diff --git a/go.sum b/go.sum index 9d4ae08580848f06caed37adc9010f29da79301d..8c939376afc62e467098fe3d7c064682f296bf10 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,12 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE= github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/main.go b/main.go index cb7bfac9f97ce4aeb0d30814444952172ab9e677..cf5679b3c0f1bb28f39c828bd5d18879c490e7a1 100644 --- a/main.go +++ b/main.go @@ -75,12 +75,12 @@ func main() { flag.Parse() if *v { - fmt.Println("DB OSInspection V1.0") + fmt.Println("DBA_TOOLBOX V2.0") return } if *h || *u == "" { - fmt.Println("Usage: DB OSInspection [options]") + fmt.Println("Usage: DBA_TOOLBOX [options]") flag.PrintDefaults() return } @@ -88,7 +88,7 @@ func main() { //调用banner banner() // 32 设置绿色,使用 33 设置黄色,使用 34 设置蓝色 - fmt.Printf("\033[31m%s\033[0m", "欢迎使用数据库巡检工具 DB OSInspection V1.0\n") + fmt.Printf("\033[31m%s\033[0m", "欢迎使用 DBA_TOOLBOX V2.0\n") fmt.Printf("————————————————————————————————————————————————————————\n") conn := fmt.Sprintf("%s:%s@%s(%s)/%s", *u, *p, *nw, *P, "mysql") @@ -110,6 +110,6 @@ func main() { //跳转菜单页面 Menu.Menu(*m) - fmt.Println("感谢您使用数据库巡检工具 DB OSInspection") + fmt.Println("Enjoy DBA_TOOLBOX :)") }