One difference between mymysql and go-mysql-driver is that I want to learn go by writing a tool today. Mymysql and go-mysql-driver are frequently used for online delivery .?? There are also some articles that drive online comparison, but none of them mention one point. I personally think it is very important to record it .???????? Use go-mysq first
One difference between mymysql and go-mysql-driver is that I want to learn go by writing a tool today. Mymysql and go-mysql-driver are mostly used for online delivery. ?? There are also some articles that drive online comparison, but none of them mention one point. I personally think it is very important to record it. ?? ?????? Use go-mysq first
A difference between mymysql and go-mysql-driver
If you want to write a tool today, you want to learn go by the way. Mymysql and go-mysql-driver are mostly used for online delivery.
?? There are also some articles that drive online comparison, but none of them mention one point. I personally think it is very important to record it.
??
?????? First, let's look at the example of using go-mysql-driver.
?? Db ,_: =SQL. Open ("mysql", connect_string) ?? Db. Query ("set binlog_format = row ") ? ?? Rows ,_: =Db. Query ("select @ binlog_format ") ??ForRows. Next (){ ????VarVString ???? Rows. Scan (&V) ???? Fmt. Println (v )? // The output value is MIXED (global value) ?? }?? ?? Rows. Close () ?? Db. Close () ? |
? The preceding output shows that the set statement is invalid.
The reason is that in the database/SQL library implementation, the above variable db maintains a thread pool rather than a thread, so the db is executed twice before and after. query is not guaranteed to be in the same session.
Similarly, set @ a = 1This thread variable may also be used in subsequent selectCannot get 1This value.
?
?
Since mymysql is not based on database/SQL, the following code ensures that 19
?
Mydb: = mysql. New ("tcp", "", "ip: port", user, password, dbname)
??? Mydb. Connect ()
??? Mydb. Query ("set @ a = 19 ")
??? Res, _: = mydb. Start ("select @ ")
??? For {
????? Row, _: = res. GetRow ()
????? If row = nil {break}
????? Fmt. Println (row. Str (0 ))
??? }??
???
??? Mydb. Close ()