Documentation
¶
Index ¶
- Constants
- Variables
- func Execute()
- func RecommendIndexes(db *sql.DB, sql string, dynamicSelectivity bool) (map[string][]IndexRecommendation, error)
- type AccountPrivilege
- type Advice
- type BinlogStats
- type CheckItem
- type Column
- type CommandInfo
- type CommandResult
- type DeployConfig
- type DiagnosticInfo
- type HostInfo
- type IndexRecommendation
- type SQLParseResult
- type SSHClient
- type SSHConfig
- type TableColumnInfo
- type UserCreateRequest
Constants ¶
View Source
const ( // Default values DefaultInstallDir = "/usr/local" DefaultDataDir = "/data/mysql" DefaultMySQLPort = 3306 DefaultSSHPort = 22 DefaultSSHUser = "root" DefaultMGRPort = 33061 DownloadMysqlUrl = "https://dev.mysql.com/get/Downloads/MySQL-8.0" // Timeouts SSHTimeout = 5 MySQLStartTimeout = 60 ServiceTimeout = 30 // Architecture types ArchMasterSlave = "master-slave" ArchMGR = "mgr" ArchPXC = "pxc" // File patterns MySQLPackagePatternMinimal = "mysql-%s-linux-glibc2.28-x86_64-minimal.tar.xz" MySQLPackagePatternFull = "mysql-%s-linux-glibc2.28-x86_64.tar.xz" LogFilePattern = "mysql_deploy_%s.log" BackupDirPattern = "%s_backup_%s" )
Constants for configuration
View Source
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" )
颜色常量
Variables ¶
View Source
var CheckupCmd = &cobra.Command{ Use: "checkup", Short: "MySQL health checkup with HTML report output", Run: func(cmd *cobra.Command, args []string) { dsn := fmt.Sprintf("%s:%s@(%s:%d)/%s", dbUser, dbPassWd, dbHost, dbPort, database) db := mysqlConnect(dsn) defer db.Close() filename := "mysql_checkup_report.html" f, err := os.Create(filename) ifErrWithLog(err) defer f.Close() f.WriteString(htmlHeader) f.WriteString(renderDirectory()) if showOSInfo { f.WriteString(renderSysInfo()) } advices := analyzeAdvices(db) f.WriteString(renderAdvices(advices)) f.WriteString(renderModule("指标与参数", paramItemsWithPerf, db)) f.WriteString(renderModule("数据与索引", tableItems, db)) f.WriteString(renderModule("SQL与性能", sqlItems, db)) f.WriteString(renderModule("账号与权限", accountItems, db)) f.WriteString(renderModule("主从状态", replicaItems, db)) f.WriteString(htmlFooter) fmt.Printf("巡检报告已生成: %s\n", filename) }, }
View Source
var RootCmd = &cobra.Command{
Use: "mysqldba",
Short: "Welcome to the MySQL DBA Toolbox.",
Long: "Welcome to the MySQL DBA Toolbox. \nAuthor: HongBin <hongbin119@gmail.com> \nVersion: " + version,
}
RootCmd represents the base command when called without any subcommands
Functions ¶
func Execute ¶
func Execute()
Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func RecommendIndexes ¶
Types ¶
type AccountPrivilege ¶
type AccountPrivilege struct { User string Host string Grants []string HighRisk bool IsWildcardHost bool LastUsed string }
账号权限结构体
type BinlogStats ¶
type BinlogStats struct { TotalCount int InsertCount int UpdateCount int DeleteCount int QueryType string QueryCount int TableName string Timestamp string TransactionSize int // 事务大小(字节) StartPosition int64 // 事务开始位置 }
BinlogStats 统计结构体
type CommandInfo ¶
type CommandInfo struct { Name string Required bool Description string InstallCmd map[string]string // OS -> install command }
CommandInfo represents information about a command
type CommandResult ¶
CommandResult holds the result of a command execution
type DeployConfig ¶
type DeployConfig struct { MysqlVersion string InstallPrefix string DataDir string ReplicationUser string ReplicationPass string AdminUser string AdminPass string RootPass string MyCnfTemplate string ServiceTemplate string HostFile string Architecture string SSHUser string SSHPort int MySQLPort int MGRGroupName string MGRPort int ForceDownload bool ForceDeploy bool SSHKeyPath string MinimalPackage bool // 是否使用minimal安装包 AppUser string // 应用账号用户名 AppPass string // 应用账号密码 }
DeployConfig holds all deployment configuration
type DiagnosticInfo ¶
type IndexRecommendation ¶
IndexRecommendation holds the recommended index information
type SQLParseResult ¶
type SQLParseResult struct { Tables map[string]string // alias -> real table name TableColumns map[string]*TableColumnInfo // table name -> column info }
SQLParseResult contains the complete parsed SQL information
func ParseSQL ¶
func ParseSQL(query string) (*SQLParseResult, error)
ParseSQL parses SQL statement and extracts table and column information
type SSHConfig ¶
type SSHConfig struct { HostFile string Command string LocalFile string RemotePath string SSHUser string SSHPort int SSHKeyPath string Timeout int Parallel int }
SSHConfig holds SSH configuration
Click to show internal directories.
Click to hide internal directories.