<p>mysql5.7 ์•Œ ์ˆ˜์—†๋Š” ์ธ์ฆ ํ”Œ๋Ÿฌ๊ทธ์ธ</p>

์— ๋งŒ๋“  2018๋…„ 06์›” 06์ผ  ยท  20์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: go-sql-driver/mysql

๋ฌธ์ œ ์„ค๋ช…

๋ฌด์Šจ ์ผ์ด ์ผ์–ด๋‚˜์•ผํ•˜๋Š”์ง€, ๋Œ€์‹  ๋ฌด์Šจ ์ผ์ด ์ผ์–ด๋‚˜๋Š”์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”.
mysql5.7 ์•Œ ์ˆ˜์—†๋Š” ์ธ์ฆ ํ”Œ๋Ÿฌ๊ทธ์ธ

์˜ˆ์ œ ์ฝ”๋“œ

// version go1.10.2 darwin/amd64
db, err := sql.Open("mysql", "admin:admin@tcp(127.0.0.1:9696)/test")
    if err != nil {
        fmt.Println("failed to open database:", err.Error())
        return
    }
    defer db.Close()

    rows, err := db.Query("SELECT id,str FROM test_shard_hash")
    if err != nil {
        fmt.Println("fetech data failed:", err.Error())
        return
    }
    defer rows.Close()
    for rows.Next() {
        var id int
        var str string
        rows.Scan(&id, &str)
        fmt.Println("uid:", id, "name:", str)
    }

์˜ค๋ฅ˜ ๊ธฐ๋ก

[mysql] 2018/06/06 22:15:07 auth.go:293: unknown auth plugin:
[mysql] 2018/06/06 22:15:07 driver.go:120: could not use requested auth plugin '': this authentication plugin is not supported

๊ตฌ์„ฑ

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์—…๊ทธ๋ ˆ์ด๋“œํ•˜๊ณ ์ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.

github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql์˜ DialCfg์™€ ํ•จ๊ป˜ ํ”„๋ก์‹œ ๋‹ค์ด์–ผ๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ์ œ ๊ฒฝ์šฐ ๊ฐ„๋‹จํ•œ ์ˆ˜์ •์€ ๊ตฌ์„ฑ ๊ตฌ์กฐ์ฒด์— AllowNativePasswords๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

&mysqldriver.Config{ AllowNativePasswords: true, ... }

๋ชจ๋“  20 ๋Œ“๊ธ€

๋‹ค์Œ ์„น์…˜๋„ ๋ฌธ์ œ ํ…œํ”Œ๋ฆฟ์—์„œ ์ข‹์€ ์ด์œ ์ž…๋‹ˆ๋‹ค.

### Configuration
*Driver version (or git SHA):*

*Go version:* run `go version` in your console

*Server version:* E.g. MySQL 5.6, MariaDB 10.0.20

*Server OS:* E.g. Debian 8.1 (Jessie), Windows 10

๋‚ด ์ƒ๊ฐ์—๋Š” ๋งˆ์Šคํ„ฐ ๋ธŒ๋žœ์น˜๊ฐ€ ์ตœ์‹  ๋ฒ„์ „์ด ์•„๋‹ˆ๋ผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. git rev-parse HEAD ํŠน์ • ๋ฒ„์ „์„ ํ™•์ธํ•˜๊ณ  ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ๋‹ค์‹œ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค.

์•ˆ๋…•ํ•˜์„ธ์š”, ์ €๋„์ด ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๊ฒฐ์‹ฌ ํ–ˆ์Šต๋‹ˆ๊นŒ?

์•„๋‹ˆ

์ด ๋ถ„๊ธฐ๊ฐ€ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๊นŒ? https://github.com/go-sql-driver/mysql/tree/empty_auth

์–ด์จŒ๋“ ์ด ๋ธ”๋ก https://github.com/go-sql-driver/mysql/blob/d523deb1b23d913de5bdada721a6071e71283618/packets.go#L157 -L167 ๋’ค์— ๊ฐ„๋‹จํ•œ print(data) ์‚ฝ์ž… ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ข‹์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์—ฌ๊ธฐ https://github.com/go-sql-driver/mysql/blob/d523deb1b23d913de5bdada721a6071e71283618/packets.go#L469 -L474 ๊ฒฐ๊ณผ ํŒจํ‚ท ๋คํ”„๋ฅผ ๋ณด๋‚ด์„œ ํšŒ๊ท€ ํ…Œ์ŠคํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@gocuntian ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ ํ–ˆ์Šต๋‹ˆ๊นŒ?

๋‚˜๋Š” ๊ฐ™์€ ์งˆ๋ฌธ์ด ์žˆ๋Š”๋ฐ, ๋‚ด ์งˆ๋ฌธ์€ ๋‚ด ์„œ๋ฒ„๊ฐ€ ์ธ์ฆ ๋ฐฉ๋ฒ•์—†์ด ์ดˆ๊ธฐํ™” ํŒจํ‚ท์„ ๋ณด๋‚ด๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
accroding ์†Œ์Šค ์ฝ”๋“œ :
auth.go : 240, func auth ()์— ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
if plugin == ""{
ํ”Œ๋Ÿฌ๊ทธ์ธ = "mysql_native_password"
}
๋‚ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค

MySQL 5.1์— ์—ฐ๊ฒฐํ•  ๋•Œ ๋™์ผํ•œ ๊ฒฝ๊ณ ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

auth.go:293: unknown auth plugin:
driver.go:120: could not use requested auth plugin '': this authentication plugin is not supported

https://github.com/go-sql-driver/mysql/tree/empty_auth ์ง€์ ์—์„œ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ง€์ ์„ ๋ณ‘ํ•ฉ ํ•  ๊ณ„ํš์ด ์žˆ์Šต๋‹ˆ๊นŒ? ์•ˆ๋…•ํ•˜์„ธ์š”.

๋‚˜๋Š” ๊ฐ™์€ ๋ฌธ์ œ๋ฅผ ๊ฐ€์ง€๊ณ ์žˆ๋‹ค.
driver.go:113: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
๋งˆ์Šคํ„ฐ์—์„œ ์‹คํŒจ (๊ฐ€์ ธ ์˜ค๊ธฐ)
v1.4.0์—์„œ ์‹คํŒจ
v1.3.0์—์„œ ์ž‘๋™

ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ์ œ๊ณต ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋‹ˆ๋ฉด ๊ทธ๊ฒƒ์ด ๋˜ ๋‹ค๋ฅธ ๋ฌธ์ œ๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์ƒˆ๋กœ์šด ๋ฌธ์ œ๋ฅผ ๋งŒ๋“ค์–ด์•ผํ•ฉ๋‹ˆ๊นŒ?

๋‹ค์‹œ ์—ด์—ˆ์Šต๋‹ˆ๋‹ค. # 828 ๋ฐ # 835 ์ฐธ์กฐ ( empty_auth ์ง€์ ์˜ PR)

์—ฌ๊ธฐ์— ๋งค์šฐ ์œ ์‚ฌํ•œ ์ฆ์ƒ์„ ๊ฐ€์ง„ ๋‘ ๊ฐ€์ง€ ๋ฌธ์ œ๊ฐ€์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

# 835์˜ ์ˆ˜์ •์€ ๋นˆ ์ธ์ฆ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ด๋ฆ„์ด์žˆ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ด์ง€๋งŒ @mbertschler ๋ฐ mysql_native_password ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค (https://github.com/ ์ฐธ์กฐ). ์ž์„ธํ•œ ๋‚ด์šฉ์€ go-sql-driver / mysql / issues / 828 # issuecomment-401856689๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

๋‹ค๋ฅธ ๋ฌธ์ œ ์ผ ์ˆ˜๋„ ์žˆ์ง€๋งŒ # 835์—์„œ ์ œ์•ˆํ•œ ๊ฒƒ๋ณด๋‹ค ๋” ๊ด‘๋ฒ”์œ„ํ•œ ์ˆ˜์ •์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

@ kwoodhouse93 ์—ฌ๊ธฐ์— ์„ค๋ช… ๋œ๋Œ€๋กœ ์šฐ๋ฆฌ์—๊ฒŒ ์˜ˆ๋ฅผ ๋“ค์–ด, ํŒจํ‚ท ๋กœ๊ทธ๋ฅผ ๋ณด๋‚ผ ์ˆ˜ : https://github.com/go-sql-driver/mysql/issues/815#issuecomment ๋ฐ”๋žŒ์งํ•˜๊ฒŒ ์‚ฌ์šฉ (-396244978๋ฅผ empty_auth ์ง€์  / # 835)?

๋˜ํ•œ &allowNativaPasswords=true ๋ฅผ DSN์— ์ถ”๊ฐ€ํ•ด๋ณด์‹ญ์‹œ์˜ค (๊ธฐ๋ณธ์ ์œผ๋กœ true ์ด์–ด์•ผ ํ•จ).

empty_auth ๋ธŒ๋žœ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์–ธ๊ธ‰ ๋œ ์œ„์น˜์— print(data) ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์œผ๋ฉฐ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

[74/4092]0xc42036c004[mysql] 2018/07/13 11:49:18 driver.go:123: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
[74/4092]0xc420371004[mysql] 2018/07/13 11:49:26 driver.go:123: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
...

์žฌ ์‹œ๋„๋ฅผ ์ค‘์ง€ํ•˜๊ธฐ ์ „์— 12 ๋ฒˆ ๋ฐ˜๋ณต๋˜์—ˆ์œผ๋ฉฐ ๊ฐ ์ฃผ์†Œ๋Š” ์•ฝ๊ฐ„ ์”ฉ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

๋‚ด DSN๊ณผ ๊ด€๋ จํ•˜์—ฌ mysql.Config ์™€ ํ•จ๊ป˜ FormatDSN() ์žˆ์Šต๋‹ˆ๋‹ค. AllowNativePasswords ๋Š” Config ๊ตฌ์กฐ์ฒด๋ฅผ ๋งŒ๋“ค ๋•Œ ์ƒ๋žต๋˜์—ˆ์œผ๋ฏ€๋กœ AllowNativePasswords: true, . ์ด๋กœ ์ธํ•ด ๋™์ž‘์ด ๋‹ค์†Œ ๋ณ€๊ฒฝ๋˜์—ˆ์ง€๋งŒ ๊ถ๊ทน์ ์œผ๋กœ ๋™์ผํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐ˜ํ™˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

[74/4092]0xc420294004[7/4092]0xc420294004S[74/4092]0xc4201bb004[mysql] 2018/07/13 11:53:13 driver.go:123: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.

(์ฐธ๊ณ , ์ด๋ฒˆ์—๋Š” ๋ฐ˜๋ณต๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ํ•œ ๋ฒˆ ์‹คํŒจํ•˜๊ณ  ํด๋ผ์ด์–ธํŠธ ์•ฑ์— ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ์Šต๋‹ˆ๋‹ค.)

print(data) ์˜ํ•ด ์ƒ์„ฑ ๋œ ์ถœ๋ ฅ์„ ๋ณด๋ฉด ํ•ด๋‹น ์ฃผ์†Œ์˜ ๋‚ด์šฉ์„๋ณด๊ณ  ์‹ถ์Šต๋‹ˆ๊นŒ? ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค ์ฃผ์‹œ๋ฉด ๋‹ค์‹œ ์‹œ๋„ํ•ด ์ฃผ์‹œ๋ฉด ๊ธฐ์ฉ๋‹ˆ๋‹ค (๋‚˜ ์ž์‹ ์„ ๋ณด ๊ฒ ์ง€๋งŒ ์˜ค๋Š˜์€ ์ด๊ฒƒ์— ๋” ๋งŽ์€ ์‹œ๊ฐ„์„ ํ• ์•  ํ•  ์‹œ๊ฐ„์ด ์—†์Šต๋‹ˆ๋‹ค).

์—…๊ทธ๋ ˆ์ด๋“œํ•˜๊ณ ์ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.

github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql์˜ DialCfg์™€ ํ•จ๊ป˜ ํ”„๋ก์‹œ ๋‹ค์ด์–ผ๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ์ œ ๊ฒฝ์šฐ ๊ฐ„๋‹จํ•œ ์ˆ˜์ •์€ ๊ตฌ์„ฑ ๊ตฌ์กฐ์ฒด์— AllowNativePasswords๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

&mysqldriver.Config{ AllowNativePasswords: true, ... }

@mglonnro ์ฐธ์กฐ https://github.com/go-sql-driver/mysql/issues/815#issuecomment -425704501

์ด ์˜ค๋ฅ˜๋Š” ๊ตฌ์„ฑ์—์„œ AllowNativePasswords: true ๋ฅผ ์ง€์ •ํ•˜์—ฌ ์ œ ๊ฒฝ์šฐ์— ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

AllowNativePassword๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ true์ž…๋‹ˆ๋‹ค.
Config{} ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์„ฑ ๊ฐœ์ฒด๋ฅผ ๋งŒ๋“ค๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค. DSN ๋˜๋Š” NewConfig() ํ•ฉ๋‹ˆ๋‹ค.

https://godoc.org/github.com/go-sql-driver/mysql#Config

DSN ๋ฌธ์ž์—ด์—์„œ ๊ตฌ๋ฌธ ๋ถ„์„๋˜๋Š” ๋Œ€์‹  ์ƒˆ ๊ตฌ์„ฑ์ด ์ƒ์„ฑ๋˜๋Š” ๊ฒฝ์šฐ ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ •ํ•˜๋Š” NewConfig ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๊ฐ์‚ฌ. API ๋ฌธ์„œ๋ฅผ ์ฝ๊ณ  ํ•ด๋‹น ๋‹จ๊ณ„๋ฅผ ๋†“ ์ณค๊ธฐ ๋•Œ๋ฌธ์— Config ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰