Skip to content

Commit

Permalink
fix(dbm-services): load schema set tc_admin = 0 TencentBlueKing#7907
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq authored and zhangzhw8 committed Nov 12, 2024
1 parent 0be70df commit b209ad6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (c *ImportSchemaFromBackendComp) migrateUseMydumper() (err error) {
}

// migrateUseMysqlDump 运行备份表结构
// nolint
func (c *ImportSchemaFromBackendComp) migrateUseMysqlDump() (err error) {
dumpOption := mysqlutil.MySQLDumpOption{
DumpSchema: true,
Expand Down Expand Up @@ -306,11 +307,21 @@ func (c *ImportSchemaFromBackendComp) migrateUseMysqlDump() (err error) {
Charset: c.charset,
MySQLDumpOption: dumpOption,
}
if err := dumper.Dump(); err != nil {
if err = dumper.Dump(); err != nil {
logger.Error("dump failed: %s", err.Error())
return err
}
logger.Info("备份表结构成功,开始导入表结构到中控")
_, err = c.tdbctlConn.Exec("set global tc_admin=0;")
if err != nil {
return err
}
defer func() {
_, err = c.tdbctlConn.Exec("set global tc_admin=1;")
if err != nil {
logger.Error("set global tc_admin=1 failed %s,请手动配置成tc_admin = 1", err.Error())
}
}()
dumpfileInfo := dumper.GetDumpFileInfo()
loader := mysqlutil.ExecuteSqlAtLocal{
IsForce: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (e ExecuteSqlAtLocal) ExecuteSqlByMySQLClient(sqlfile string, targetdbs []s
return nil
}

// ExecuteSqlWithOutReport TODO
func (e ExecuteSqlAtLocal) ExecuteSqlWithOutReport(sqlfile string, targetdbs []string) (err error) {
for _, db := range targetdbs {
if err = e.ExecuteSqlByMySQLClientOne(sqlfile, db, false); err != nil {
Expand All @@ -114,6 +115,7 @@ func (e ExecuteSqlAtLocal) ExecuteSqlByMySQLClientOne(sqlfile string, db string,
return nil
}

// TestConnectionByMySQLClient TODO
func (e ExecuteSqlAtLocal) TestConnectionByMySQLClient(db string, report bool) (err error) {
command := e.CreateLoadSQLCommand()
command = fmt.Sprintf(`echo "select version()" | %s %s`, command, db)
Expand Down Expand Up @@ -144,7 +146,7 @@ func (e ExecuteSqlAtLocal) ExecuteCommand(command string, report bool) (err erro
defer ef.Sync()
// 标准输出复制一份到错误文件中
stdout := io.MultiWriter(os.Stdout)
//stdout := io.MultiWriter(os.Stdout, ef)
// stdout := io.MultiWriter(os.Stdout, ef)
// 错误不输出控制台 去掉os.Stderr
// stderr := io.MultiWriter(os.Stderr, &stderrBuf, ef)
stderr := io.MultiWriter(&stderrBuf, ef)
Expand Down

0 comments on commit b209ad6

Please sign in to comment.