Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: add mysql.user columns for parser#1121 #21856

Merged
merged 8 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ const (
Reload_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
FILE_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Config_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_Tablespace_Priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_Tablespace_Priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Repl_slave_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Repl_client_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
PRIMARY KEY (Host, User));`
// CreateGlobalPrivTable is the SQL statement creates Global scope privilege table in system db.
CreateGlobalPrivTable = "CREATE TABLE IF NOT EXISTS mysql.global_priv (" +
Expand Down Expand Up @@ -440,6 +442,8 @@ const (
version56 = 56
// version57 fixes the bug of concurrent create / drop binding
version57 = 57
// version58 add `Repl_client_priv` and `Repl_slave_priv` to `mysql.user`
version58 = 58
)

var (
Expand Down Expand Up @@ -501,6 +505,7 @@ var (
upgradeToVer55,
upgradeToVer56,
upgradeToVer57,
upgradeToVer58,
}
)

Expand Down Expand Up @@ -1250,6 +1255,15 @@ func insertBuiltinBindInfoRow(s Session) {
mustExecute(s, sql)
}

func upgradeToVer58(s Session, ver int64) {
if ver >= version58 {
return
}
doReentrantDDL(s, "ALTER TABLE mysql.user ADD COLUMN `Repl_slave_priv` ENUM('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N' AFTER `Execute_priv`", infoschema.ErrColumnExists)
doReentrantDDL(s, "ALTER TABLE mysql.user ADD COLUMN `Repl_client_priv` ENUM('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N' AFTER `Repl_slave_priv`", infoschema.ErrColumnExists)
mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET Repl_slave_priv='Y',Repl_client_priv='Y'")
}

func writeMemoryQuotaQuery(s Session) {
comment := "memory_quota_query is 32GB by default in v3.0.x, 1GB by default in v4.0.x"
sql := fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES ("%s", '%d', '%s') ON DUPLICATE KEY UPDATE VARIABLE_VALUE='%d'`,
Expand Down Expand Up @@ -1333,7 +1347,7 @@ func doDMLWorks(s Session) {

// Insert a default user with empty password.
mustExecute(s, `INSERT HIGH_PRIORITY INTO mysql.user VALUES
("%", "root", "", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y")`)
("%", "root", "", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y")`)

// Init global system variables table.
values := make([]string, 0, len(variable.GetSysVars()))
Expand Down
4 changes: 2 additions & 2 deletions session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *testBootstrapSuite) TestBootstrap(c *C) {
c.Assert(err, IsNil)
c.Assert(req.NumRows() == 0, IsFalse)
datums := statistics.RowToDatums(req.GetRow(0), r.Fields())
match(c, datums, `%`, "root", []byte(""), "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y")
match(c, datums, `%`, "root", []byte(""), "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y")

c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "anyhost"}, []byte(""), []byte("")), IsTrue)
mustExecSQL(c, se, "USE test;")
Expand Down Expand Up @@ -159,7 +159,7 @@ func (s *testBootstrapSuite) TestBootstrapWithError(c *C) {
c.Assert(req.NumRows() == 0, IsFalse)
row := req.GetRow(0)
datums := statistics.RowToDatums(row, r.Fields())
match(c, datums, `%`, "root", []byte(""), "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y")
match(c, datums, `%`, "root", []byte(""), "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y")
c.Assert(r.Close(), IsNil)

mustExecSQL(c, se, "USE test;")
Expand Down
4 changes: 2 additions & 2 deletions tests/globalkilltest/global_kill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *TestGlobalKillSuite) startTiDBWithoutPD(port int, statusPort int) (cmd
fmt.Sprintf("-P=%d", port),
fmt.Sprintf("--status=%d", statusPort),
fmt.Sprintf("--log-file=%s/tidb%d.log", *tmpPath, port))
fmt.Sprintf("--config=%s", "./config.toml")
fmt.Sprintf("--config=%s", "./config.toml")
log.Infof("starting tidb: %v", cmd)
err = cmd.Start()
if err != nil {
Expand All @@ -136,7 +136,7 @@ func (s *TestGlobalKillSuite) startTiDBWithPD(port int, statusPort int, pdPath s
fmt.Sprintf("-P=%d", port),
fmt.Sprintf("--status=%d", statusPort),
fmt.Sprintf("--log-file=%s/tidb%d.log", *tmpPath, port))
fmt.Sprintf("--config=%s", "./config.toml")
fmt.Sprintf("--config=%s", "./config.toml")
log.Infof("starting tidb: %v", cmd)
err = cmd.Start()
if err != nil {
Expand Down