Skip to content
ziutek edited this page Mar 13, 2013 · 7 revisions

Drop mysql, autorc, thrsafe; supply only godrv

I'm sure you split things up into 4 different APIs for some good reason, but I don't clearly see why. Can you explain your reasoning?

My thought is: Go provides a very nice stdlib API for database access. The hooks for the driver code enable it to be threadsafe, and automatically reconnect on errors. So, I would propose that the threadsafe, auto-reconnecting functionality can (and should) be merged into the godrv driver code, and that mysql, autorc, and thrsafe packages be dropped.


mymysql provides full interface to MySQL server.

godrv is a thin adapter that allows to use mymysql as database/sql driver. database/sql provides connection pooling, auto-reconnecting and thread safety. Driver shouldn't do such things itself so there is no any reason to merge autorc and thrsafe to godrv code. autorc and thrsafe are for people that need to use mymysql directly because of some limitations of database/sql and still have access to auto-recconecting or/and thread-safe interface.

So what you can do with raw mymysql that you can't using database/sql:

  1. You can perform operations that need to be executed on the same connection (using session variables, etc). Using database/sql there is no way to guarantee that specific operations use the same connection.

  2. You can call server side stored procedures. Such procedures can return more than one result but database/sql assumes that there is only one result per query.

  3. You can perform queries witch multi-statements that returns multiple results sets.

  4. You can use SendLongData command.

  5. You have full mapping between Go types and MySQL types (but there is Conn.NarrowTypeSet method to limit number of types returned by query to type set defined by database/sql).

Connection pooling, autorc

I have currently written my database layer using MyMysql for a big project and I am very happy with how everything is working but I wanted to check that I am using it correctly as I think I might be opening and closing connections every time I connect to the database and I was hoping to use connection pooling type functionality. [...] Does the MyMysql library support connection pooling or should I use the auto reconnect library and never close the connection?


For connection pooling use database/sql package and mymysql/godrv as driver. Furthermore, if you use database/sql, your application can work with any database system (Postgress, . SQLite, MongoDB, ...)

Use raw mymysql only if you have specific problem that is difficult to be resolved using database/sql. In this case mymysql/autorc is preferred. Use mymysql/mysql only if you need some functionality that autorc lacks or if you want implement over it your own higher level interface (eg: connection pooling: http://www.ryanday.net/2012/09/12/golang-using-channels-for-a-connection-pool/).

See also issue 42.

Questions about SQL, MySQL, database/sql, mymysql

Issue #123456

What should I to do to ... ? Why ... works in this way ?


Please don't create issues for simple questions. There are many people that uses SQL, MySQL, database/sql and mymysql. If you have some question about SQL/MySQL ask it to some SQL/MySQL forum/group. If you have any question about mymysql or database/sql pleas ask it to golang-nuts group. If you have mymysql specific problem that nobody can help on golang-nuts please ask me directly (michal at Lnet pl)