Skip to content

Commit

Permalink
session: fix bootstrap error in ANSI sql_mode (#8353) (#8367)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and winkyao committed Nov 21, 2018
1 parent 65be0df commit 30241e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ func (s *testBootstrapSuite) TestUpgrade(c *C) {
c.Assert(ver, Equals, int64(currentBootstrapVersion))
}

func (s *testBootstrapSuite) TestANSISQLMode(c *C) {
defer testleak.AfterTest(c)()
store, dom := newStoreWithBootstrap(c, s.dbName)
defer store.Close()
se := newSession(c, store, s.dbName)
mustExecSQL(c, se, "USE mysql;")
mustExecSQL(c, se, `set @@global.sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI"`)
mustExecSQL(c, se, `delete from mysql.TiDB where VARIABLE_NAME="tidb_server_version";`)
delete(storeBootstrapped, store.UUID())
se.Close()

// Do some clean up, BootstrapSession will not create a new domain otherwise.
dom.Close()
domap.Delete(store)

// Set ANSI sql_mode and bootstrap again, to cover a bugfix.
// Once we have a SQL like that:
// select variable_value from mysql.tidb where variable_name = "system_tz"
// it fails to execute in the ANSI sql_mode, and makes TiDB cluster fail to bootstrap.
dom1, err := BootstrapSession(store)
c.Assert(err, IsNil)
defer dom1.Close()
se = newSession(c, store, s.dbName)
mustExecSQL(c, se, "select @@global.sql_mode")
se.Close()
}

func (s *testBootstrapSuite) TestOldPasswordUpgrade(c *C) {
pwd := "abc"
oldpwd := fmt.Sprintf("%X", auth.Sha1Hash([]byte(pwd)))
Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ func CreateSession(store kv.Storage) (Session, error) {

// loadSystemTZ loads systemTZ from mysql.tidb
func loadSystemTZ(se *session) (string, error) {
sql := `select variable_value from mysql.tidb where variable_name = "system_tz"`
sql := `select variable_value from mysql.tidb where variable_name = 'system_tz'`
rss, errLoad := se.Execute(context.Background(), sql)
if errLoad != nil {
return "", errLoad
Expand Down

0 comments on commit 30241e0

Please sign in to comment.