Add maxAllowedPacket DSN Parameter#489
Conversation
I feel this sentence is worth enough to include in README. |
|
What we currently do is indeed a hack we should maybe avoid in the future. It might be a good idea to just use MySQL's default value by default, allow modification via the Anyway, @xiezhenye please use the PR template (edit you post) and make the necessary additions. |
|
I prefer maxAllowedPacket to maxPacketAllowed so naming is consistent with the variable in MySQL. But if the name was intentional: for what the reason? |
AUTHORS
Outdated
| Stan Putrya <root.vagner at gmail.com> | ||
| Stanley Gunawan <gunawan.stanley at gmail.com> | ||
| Xiaobing Jiang <s7v7nislands at gmail.com> | ||
| Zhenye Xie <xiezhenye at gmail.com> |
There was a problem hiding this comment.
Please move your entry to the end (alphabetical order)
README.md
Outdated
| Default: 0 | ||
| ``` | ||
|
|
||
| Max MySQL packet size allowed in bytes. Use `maxPacketAllowed` == 0 to fetch the `max_allowed_packet` variable from server. |
There was a problem hiding this comment.
Remove "MySQL" and replace "maxPacketAllowed == 0" with "Use maxPacketAllowed = 0" (single =).
There was a problem hiding this comment.
Maybe also add "automatically" before "fetch"
|
@arnehormann's comment is still valid. The parameter name should be consistent with the variable name ( |
README.md
Outdated
| I/O write timeout. The value must be a decimal number with an unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. | ||
|
|
||
|
|
||
| ##### `maxPacketAllowed` |
There was a problem hiding this comment.
maxAllowedPacket also here and in DSN
README.md
Outdated
| Default: 0 | ||
| ``` | ||
|
|
||
| Max packet size allowed in bytes. Use `maxAllowedPacket` = 0 to automatically fetch the `max_allowed_packet` variable from server. |
There was a problem hiding this comment.
Please write it as maxAllowedPacket=0 to make it consistent with other variables.
driver.go
Outdated
| mc.Close() | ||
| return nil, err | ||
| if mc.cfg.MaxAllowedPacket > 0 { | ||
| mc.maxPacketAllowed = mc.cfg.MaxAllowedPacket |
There was a problem hiding this comment.
also change the name here
driver.go
Outdated
| mc.Close() | ||
| return nil, err | ||
| } | ||
| mc.maxPacketAllowed = stringToInt(maxap) - 1 |
driver.go
Outdated
| mc.maxPacketAllowed = stringToInt(maxap) - 1 | ||
| } | ||
| mc.maxPacketAllowed = stringToInt(maxap) - 1 | ||
| if mc.maxPacketAllowed < maxPacketSize { |
dsn.go
Outdated
|
|
||
| if cfg.MaxAllowedPacket > 0 { | ||
| if hasParam { | ||
| buf.WriteString("&maxPacketAllowed=") |
dsn.go
Outdated
| buf.WriteString("&maxPacketAllowed=") | ||
| } else { | ||
| hasParam = true | ||
| buf.WriteString("?maxPacketAllowed=") |
dsn.go
Outdated
| return | ||
| } | ||
|
|
||
| case "maxPacketAllowed": |
dsn_test.go
Outdated
| }, { | ||
| "user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci", | ||
| &Config{User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "dbname", Collation: "utf8mb4_unicode_ci", Loc: time.UTC, Timeout: 30 * time.Second, ReadTimeout: time.Second, WriteTimeout: time.Second, AllowAllFiles: true, AllowOldPasswords: true, ClientFoundRows: true}, | ||
| "user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci&maxPacketAllowed=16777216", |
dsn.go
Outdated
| MultiStatements bool // Allow multiple statements in one query | ||
| ParseTime bool // Parse time values to time.Time | ||
| Strict bool // Return warnings as errors | ||
| MaxAllowedPacket int // Max packet size allowed |
There was a problem hiding this comment.
Please move it after Loc *time.Location // Location for time.Time values.
We just put all the bool vars at the end for more efficient struct packing.
README.md
Outdated
| Default: 0 | ||
| ``` | ||
|
|
||
| Max packet size allowed in bytes. Use `maxAllowedPacket`=0 to automatically fetch the `max_allowed_packet` variable from server. |
|
Thanks a lot! |
Description
Add a
maxPacketAllowedDSN param and a config field to set it directly instead of fetch from server.Some mysql proxy implements or other services using mysql protocol may not supports 'select @@max_allowed_packet'.
maxPacketAllowedparam can be used to walk around these problems.It can also be used to limit the max row size returned from server.
Checklist