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

*: support "show create user" #9240

Merged
merged 19 commits into from
Feb 21, 2019
Merged

Conversation

lnhote
Copy link
Contributor

@lnhote lnhote commented Feb 1, 2019

What problem does this PR solve?

Support SHOW CREATE USER as in MySQL 5.7.
fix #7733

What is changed and how it works?

  1. add GetEncodedPassword function to Manager interface.
  2. add support for ShowCreateTable in buildShowSchema function.
  3. add support for ShowCreateUser in ShowExec.fetchAll function

Check List

Tests

  • Unit test

Code changes

  • exported function/method change
  • Has exported variable/fields change
  • Has interface methods change

@shenli
Copy link
Member

shenli commented Feb 5, 2019

@lnhote Thanks!
Please fix the CI.

@shenli shenli added the contribution This PR is from a community contributor. label Feb 5, 2019
@morgo
Copy link
Contributor

morgo commented Feb 8, 2019

@lnhote Thank you for working on this! It looks like it just needs go fmt to be run:

go fmt privilege/privileges/privileges.go

@lnhote
Copy link
Contributor Author

lnhote commented Feb 10, 2019

Thanks for the help. Please take another look.

@codecov-io
Copy link

codecov-io commented Feb 10, 2019

Codecov Report

Merging #9240 into master will increase coverage by 0.13%.
The diff coverage is 51.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9240      +/-   ##
==========================================
+ Coverage   67.02%   67.15%   +0.13%     
==========================================
  Files         373      373              
  Lines       78150    78191      +41     
==========================================
+ Hits        52378    52512     +134     
+ Misses      21094    20977     -117     
- Partials     4678     4702      +24
Impacted Files Coverage Δ
util/testkit/testkit.go 14.16% <0%> (-1.02%) ⬇️
planner/core/planbuilder.go 49.35% <33.33%> (-0.04%) ⬇️
privilege/privileges/privileges.go 57.31% <45.45%> (-1.84%) ⬇️
executor/show.go 45.1% <78.94%> (+1.22%) ⬆️
ddl/delete_range.go 75.13% <0%> (-2.65%) ⬇️
infoschema/infoschema.go 76.31% <0%> (-1.32%) ⬇️
store/tikv/lock_resolver.go 41.7% <0%> (-0.95%) ⬇️
executor/distsql.go 72.24% <0%> (+0.45%) ⬆️
executor/join.go 79.42% <0%> (+0.52%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a24081...81b503e. Read the comment docs.

@morgo
Copy link
Contributor

morgo commented Feb 10, 2019

@lnhote can you please add tests for:

  • a user that doesn't exist
  • the user exists but the host portion doesn't match

I am getting the following behavior on a fresh install. Both are different results from MySQL:

mysql> SET PASSWORD='abcd';
2019/02/10 02:35:19.953 session.go:1639: [info] [CRUCIAL OPERATION] con:1 schema_ver:15 set password for user <nil> (by root@127.0.0.1).
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW CREATE USER 'root'@'%'; <-- correct
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for root@%                                                                                                                                            |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'root'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*A154C52565E9E7F94BFC08A1FE702624ED8EFFDA' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SHOW CREATE USER 'root'@'nowhere'; <--- incorrect
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for root@nowhere                                                                                                                                            |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'root'@'nowhere' IDENTIFIED WITH 'mysql_native_password' AS '*A154C52565E9E7F94BFC08A1FE702624ED8EFFDA' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create user 'aaa'@'aaa'; <-- incorrect
2019/02/10 02:35:39.737 privileges.go:65: [error] Get user privilege record fail: user aaa, host aaa
+---------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for aaa@aaa                                                                                                   |
+---------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'aaa'@'aaa' IDENTIFIED WITH 'mysql_native_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

@morgo
Copy link
Contributor

morgo commented Feb 10, 2019

Expected behavior:

mysql [localhost:5724] {msandbox} ((none)) > show grants for 'root'@'nowhere';
ERROR 1141 (42000): There is no such grant defined for user 'root' on host 'nowhere'
mysql [localhost:5724] {msandbox} ((none)) > show grants for 'aaa'@'aaa';
ERROR 1141 (42000): There is no such grant defined for user 'aaa' on host 'aaa'

executor/builder.go Outdated Show resolved Hide resolved
@zz-jason zz-jason changed the title Support show create user *: support "show create user" Feb 15, 2019
@morgo
Copy link
Contributor

morgo commented Feb 15, 2019

@lnhote I left two review comments. It looks good otherwise. Thanks!

@morgo
Copy link
Contributor

morgo commented Feb 15, 2019

LGTM

@morgo morgo added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 15, 2019
@morgo
Copy link
Contributor

morgo commented Feb 19, 2019

@lnhote please resolve conflicts.

@lnhote
Copy link
Contributor Author

lnhote commented Feb 20, 2019

@morgo PTAL.

@morgo
Copy link
Contributor

morgo commented Feb 20, 2019

LGTM
@jackysp PTAL

@@ -16,13 +16,13 @@ package executor_test
import (
"context"
"fmt"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not remove this line, keep the sys libs separate with the 3rd party libs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the blank line will cause check_dev to fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check_dev could pass in master branch? I think you've added a blank line with some white spaces, try to keep it as it used to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it.

@jackysp
Copy link
Member

jackysp commented Feb 21, 2019

/run-all-tests

@jackysp
Copy link
Member

jackysp commented Feb 21, 2019

/run-integration-common-test

@jackysp
Copy link
Member

jackysp commented Feb 21, 2019

/run-integration-ddl-test

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/LGT1 Indicates that a PR has LGTM 1. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support SHOW CREATE USER as in MySQL 5.7
6 participants