A difference between mymysql and go-mysql-driver

Source: Internet
Author: User
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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.