From 7865febf1993f23e3865c9b672d380cb629ec007 Mon Sep 17 00:00:00 2001 From: Alex Tymchuk Date: Wed, 30 Aug 2023 13:47:13 +0000 Subject: [PATCH] PMM-12375 use Exec to select a database --- agent/connectionchecker/connection_checker.go | 7 ++++++- managed/models/database.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/agent/connectionchecker/connection_checker.go b/agent/connectionchecker/connection_checker.go index 025703dd08..c5e39f8b2b 100644 --- a/agent/connectionchecker/connection_checker.go +++ b/agent/connectionchecker/connection_checker.go @@ -289,10 +289,15 @@ func (cc *ConnectionChecker) checkProxySQLConnection(ctx context.Context, dsn st res.Error = err.Error() } + if _, err := db.ExecContext(ctx, "USE mysql"); err != nil { + res.Error = err.Error() + return &res + } + var version string if err := db.QueryRowContext( ctx, - "USE mysql; SELECT /* agent='connectionchecker' */ variable_value FROM global_variables WHERE variable_name = 'admin-version'").Scan(&version); err != nil { //nolint:lll + "SELECT /* agent='connectionchecker' */ variable_value FROM global_variables WHERE variable_name = 'admin-version'").Scan(&version); err != nil { //nolint:lll res.Error = err.Error() return &res } diff --git a/managed/models/database.go b/managed/models/database.go index 7bd5c77ec0..fc107aadc1 100644 --- a/managed/models/database.go +++ b/managed/models/database.go @@ -917,7 +917,7 @@ var databaseSchema = [][]string{ }, 85: { `ALTER TABLE services - ADD COLUMN version VARCHAR`, + ADD COLUMN version VARCHAR NOT NULL DEFAULT ''`, }, }