title: I could not connect Mysql with ODBC in Golang
body: <p>I want to connect mssql, mysql, postgres database servers with ODBC in Go. I have used this package: <a href="https://github.com/alexbrainman/odbc" rel="nofollow noreferrer">https://github.com/alexbrainman/odbc</a></p>
  <p>I could connect my local mssql but I could not connect mysql. It gives this error: &quot;Query Preparation Error SQLDriverConnect: {IM002} [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified&quot;</p>
  <p>My OS is Windows 10. After that I will also try on Ubuntu.</p>
  <p>This is my code:</p>
  <pre><code>
  import (
      &quot;database/sql&quot;
      &quot;fmt&quot;
      &quot;log&quot;
  
      _ &quot;database/sql/driver&quot;
  
      _ &quot;github.com/alexbrainman/odbc&quot;
  )
  
  func main() {
      // conn, err := sql.Open(&quot;odbc&quot;,
      //  &quot;uid=sa;pwd=Str0ngPa$$w0rd;port=1433;driver=sql server;server=host.docker.internal;database=master;TDS_Version=7.2;&quot;)
      dbConn := fmt.Sprintf(&quot;driver=mysql;server=%s;port=3306;=database=%s;user=%s;password=%s;TDS_Version=7.2;&quot;,
          &quot;host.docker.internal&quot;, &quot;sys&quot;, &quot;root&quot;, &quot;secret&quot;)
      conn, err := sql.Open(&quot;odbc&quot;, dbConn)
  
      if err != nil {
          fmt.Println(&quot;Connecting Error&quot;)
          return
      }
      defer conn.Close()
      fmt.Println(&quot;Sql Server Connected&quot;)
  
      stmt, err := conn.Prepare(&quot;select thirdtest, onetest from firsttable WHERE secondtest &gt;= 5 limit 5&quot;)
      if err != nil {
          fmt.Println(&quot;Query Preparation Error&quot;, err)
          return
      }
      defer stmt.Close()
      fmt.Println(&quot;Query Prepared&quot;)
  
      // Use db.Query() to send the query to the database. Check errors as usual.
      row, err := stmt.Query()
      if err != nil {
          fmt.Println(&quot;Query Error&quot;, err)
          return
      }
      defer row.Close()
  
      fmt.Printf(&quot;\nResult set 1:\n&quot;)
      for row.Next() {
          var (
              thirdtest float64
              onetest   string
          )
          fmt.Println(&quot;result 1&quot;)
          err := row.Scan(&amp;onetest, &amp;thirdtest)
          if err == nil {
              fmt.Println(onetest, thirdtest)
          }
      }
  
      err = row.Err()
      if err != nil {
          fmt.Printf(&quot;\nFatal: %s\n&quot;, err)
      }
  
      stmt, err = conn.Prepare(&quot;select top 5 database_id, name from sys.databases WHERE database_id &gt;= ?&quot;)
      if err != nil {
          log.Fatal(err)
      }
  
      row, err = stmt.Query(1)
      if err != nil {
          log.Fatal(err)
      }
      defer row.Close()
  
      fmt.Printf(&quot;\nResult set 2:\n&quot;)
      for row.Next() {
          var (
              id   int
              name string
          )
          if err := row.Scan(&amp;id, &amp;name); err == nil {
              fmt.Println(id, name)
          } else {
              log.Fatal(err)
          }
      }
      err = row.Err()
      if err != nil {
          log.Fatal(err)
      }
  
      fmt.Printf(&quot;\nFinished correctly\n&quot;)
      return
  }
  </code></pre>