Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to refresh existing db connection username and password #1613

Unanswered
blnprasad asked this question in Q&A
Discussion options

I have a long running daemon written in Go, that listens to a port and spins up multiple go routines for every new connection to handle the data. There is a global variable context that has db Conn(*sql.DB) that is assigned connection context returned by database/sql library’s open() function during initialization time.
for security reasons we want to rotate db username & password periodically. I'm looking for best possible way to achieve same but i'm not able to find any pointers to it in documentation. Can you please suggest for the same?
I'm also not able find info about auto reconnection details in case of DB failure. Just wondering how long driver will keep retyring in case of DB shutdown or failure?

closest one that i got is: https://stackoverflow.com/questions/61921525/how-to-update-db-connection-in-gorm-with-new-aws-token/77287404#77287404. but its good for only postgress.

You must be logged in to vote

Replies: 1 comment

Comment options

closest one that i got is: https://stackoverflow.com/questions/61921525/how-to-update-db-connection-in-gorm-with-new-aws-token/77287404#77287404. but its good for only postgress.

This solution is also good for MySQL.
You can use BeforeConnect option.
https://pkg.go.dev/github.com/go-sql-driver/mysql@v1.8.1#BeforeConnect

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /