-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add maxAllowedPacket DSN Parameter #489
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "MySQL" and replace "maxPacketAllowed
== 0" with "Use maxPacketAllowed
= 0" (single =).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also change the name here
driver.go
Outdated
mc.Close() | ||
return nil, err | ||
} | ||
mc.maxPacketAllowed = stringToInt(maxap) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
driver.go
Outdated
mc.maxPacketAllowed = stringToInt(maxap) - 1 | ||
} | ||
mc.maxPacketAllowed = stringToInt(maxap) - 1 | ||
if mc.maxPacketAllowed < maxPacketSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
dsn.go
Outdated
|
||
if cfg.MaxAllowedPacket > 0 { | ||
if hasParam { | ||
buf.WriteString("&maxPacketAllowed=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
dsn.go
Outdated
buf.WriteString("&maxPacketAllowed=") | ||
} else { | ||
hasParam = true | ||
buf.WriteString("?maxPacketAllowed=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
dsn.go
Outdated
return | ||
} | ||
|
||
case "maxPacketAllowed": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`maxAllowedPacket=0`
Thanks a lot! |
Description
Add a
maxPacketAllowed
DSN 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'.
maxPacketAllowed
param can be used to walk around these problems.It can also be used to limit the max row size returned from server.
Checklist