go-sql-driver / mysql Goto Github PK
View Code? Open in Web Editor NEWGo MySQL Driver is a MySQL driver for Go's (golang) database/sql package
Home Page: https://pkg.go.dev/github.com/go-sql-driver/mysql
License: Mozilla Public License 2.0
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
Home Page: https://pkg.go.dev/github.com/go-sql-driver/mysql
License: Mozilla Public License 2.0
This is Issue 20 moved from a Google Code project.
Added by 2012-12-18T21:28:10.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-High
Currently the driver returns an empty []byte slice instead of nil
Implement connection compression
hi,
I used this code to visit mysql. However, when vising mysql 5.5.9-log version,
Query & Prepare function will return "Malformed Packet"
And, they all run successfully on other version of mysql.
mysqlConf: ssss:ssss@tcp(11.11.11.11:3306)/ssss?charset=utf8
How i use:
categoryDB, err := sql.Open("mysql", categoryDBConf)
if err != nil {
fmt.Printf("%v\n", err)
}
defer categoryDB.Close()
rows, err := categoryDB.Query(`select 1`)
if err != nil {
fmt.Printf("%v\n", err)
}
This is Issue 7 moved from a Google Code project.
Added by 2012-06-23T21:09:10.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (WontFix).
Original labels: Type-Defect, Priority-High, OpSys-OSX
<b>Problem summary:</b>
Not sure if this is something particular to my system or if I am using the driver incorrectly, but when I call something similar to the following code with the mysql server shut off, it does not return an err:
import (
"log"
"database/sql"
_ "code.google.com/p/go-mysql-driver/mysql"
)
var database *sql.DB
func main() {
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatal("Could not connect to:", k)
}
database = db
// database later is accessed by various goroutines
doMuchWorkHere()
}
I am running the mysql server locally. Dsn similar to "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8&keepalive=1"
I considered using db.Driver() to get the underlying driver and maybe using mc.Ping myself to test, but the documentation for database/sql seems to imply that Open would return a failure on setup if the server could not be contacted.
I thought maybe it was due to net.Dial being used instead of net.DialTimeout, but I am not sure.
Am I using the driver wrongly by expecting open to return an error if the server is down or it cannot be contacted?
Used go-mysql-version:
changeset: 27:2c2c693701e6
tag: tip
user: Julien Schmidt
date: Wed May 30 16:00:01 2012 +0200
MySQL-Server version: mysql 5.5.25
Used Operation System: osx 10.7.4
Go version: go version go1.0.2
Hi,
The fact that "go get" does not handle versioning, is a problem for most of Go projects. So, to avoid breaking dependencies, I suggest using "git flow" (there's a package in macports and ubuntu) with default settings (master/develop/feature/hotfix) in this project. This makes your master point to the lates tagget release or hotfix, that will probably be a more stable interface.
thanks
MySQL's utf8
is not really utf8
and it's advisable to replace it with utf8mb4
, if the server supports it (MySQL 5.5.3+).
Ideally, you could set it in the DSN and fall back to utf8
for older versions. I see four ways to get there:
My preferred way would be to specify charset
twice in the connection string (first set it to utf8
, then to utf8mb4
- if the second one fails we still at least have utf8), but params
is a map and can only contain one charset. If it's converted to an array of of [2]string
(or a key - value struct), this would be possible. This should also be highlighted/advised in the documentation.
Next, the client could ask the server for the supported charsets and automatically downgrade utf8mb4
to utf8
if it's not available.
A (nasty) workaround and the way no change to the code is required would be to set a charset
twice (one time ending in or beginning with a space) and set the one first encountered by range mc.cfg.params
to utf8
and the second one to utf8mb4
. Your code sees it as two different parameters, but for MySQL both are the same. I dislike it as it's clumsy and fragile - it depends on the way in which map
and the driver are implemented.
Last, you could provide a Register
function like mymysql.
I'll try to help out with a pull-request if you want, I just want to know if you're interested in this and which way you'd prefer beforehand.
Steps:
db, err := sql.Open(
"mysql",
fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", user, pass, host, port, name),
)
if err != nil { panic(err) }
var i int
err = db.QueryRow("SELECT 1 FROM DUAL").Scan(&i)
if err != nil { panic(err) }
Everything works great here. Then I try to actually use it for a different query.
var thing string
err = db.QueryRow("SELECT thing FROM place WHERE id = ?", id).Scan(&thing)
if err != nil { panic(err) }
This reliably panics with one of the two "Commands out of sync" errors, but ONLY on linux_amd64. It works fine on darwin_amd64.
Any insight appreciated.
I downloaded the most recent version of the MySQL driver and I cannot get it to connect to any databases. I've tried using a DSN for both socket and tcp connections.
This is Issue 5 moved from a Google Code project.
Added by 2012-05-30T12:21:24.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-High, Usability, OpSys-All
<b>Problem summary:</b>
go-mysql-driver panics when trying to parse a datetime field that is timestamped at exactly midnight. Full stack trace attached and one solution to the problem mentioned below. (There might or might not be ways to fix it at lower level somewhere)
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
May 26, 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
5.5.24 MySQL Community Server (GPL)
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
Windows 7 64bit
<b>Example code which reproduces the error (optional):</b>
rows, err := db.Query("SELECT updated_at FROM table")
when the content of that datetime field in any of the returned rows is: 2010-04-29 00:00:00
Fix:
So.. might not be the best way, but one way to fix this is by changing the switch case from readBinaryRows in packets.go like this:
diff -r 787b14074e0f mysql/packets.go
--- a/mysql/packets.go Sat May 26 17:50:45 2012 +0200
+++ b/mysql/packets.go Wed May 30 13:11:16 2012 +0100
@@ -989,13 +989,20 @@
if num == 0 {
row[i] = []byte("0000-00-00 00:00:00")
} else {
+ var timestampdata []byte
+ if len(data) < pos+7 {
+ timestampdata = make([]byte, pos+7)
+ copy(timestampdata, data)
+ } else {
+ timestampdata = data
+ }
row[i] = []byte(fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d",
- bytesToUint16(data[pos:pos+2]),
- data[pos+2],
- data[pos+3],
- data[pos+4],
- data[pos+5],
- data[pos+6]))
+ bytesToUint16(timestampdata[pos:pos+2]),
+ timestampdata[pos+2],
+ timestampdata[pos+3],
+ timestampdata[pos+4],
+ timestampdata[pos+5],
+ timestampdata[pos+6]))
}
pos += int(num)
This is Issue 10 moved from a Google Code project.
Added by 2012-08-03T15:01:57.000Z by julian.morrison.
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Enhancement, Priority-Medium, OpSys-All
Please add the ability to use streaming mode, like this http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html so that rows.Next() actually fetches the next row, rather than slicing an in-memory list of rows.
The company I work for has a use case where we want to read very large result sets that would be too large to fit in memory at once. (Right now we can do that by fetching the Id column only, and then reading blocks of results with new queries, but that's inefficient.)
Probably, this should be a parameter in the DSN.
when i view the source code,i found the problem that if password include @
,do parseDSN function will work well?
such as remotetest:!@#111111@tcp(8.8.8.8)/xxxx/?xxx
,this example password is !@#111111
, the parseDSN will match password as !
or !@#111111
.if the match password is not !@#111111
, may be that problem is a bug.
I'm sorry my english is so bad~
This is Issue 8 moved from a Google Code project.
Added by 2012-07-02T07:08:30.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
MySQL-Server 5.1 Windows 7 64bit
Use golang 1.0.2
error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x30 pc=0x42b004]
goroutine 1 [running]:
database/sql.(*Rows).Next(0x0, 0x100000001, 0x6572656800000006, 0x0)
.....
rows is :
Invalid Result Packet-Type
Is this being worked on or... am i just being dumb? My database has empty datetime fields.. otherwise the package works fine.
This is Issue 14 moved from a Google Code project.
Added by 2012-10-12T00:31:05.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-High
<b>Problem summary:</b>
In connections.go mc.exec is masking the mc.insertId with 0. To be more clear, I am running an Exec to insert into a table and getting errors while trying to read the LastInsertId() back on the a result set. Unless I am mistaken, when doing an insert you should get a true result object back with a last insert id.
Here is a suggested patch to fix the issue.
--- connection.go.orig 2012-10-11 18:19:59.000000000 -0600
+++ connection.go 2012-10-11 18:20:40.000000000 -0600
@@ -197,7 +197,7 @@
return nil, e
}
- if mc.affectedRows == 0 {
+ if mc.affectedRows == 0 && mc.insertId == 0 {
return driver.ResultNoRows, e
}
@@ -222,7 +222,6 @@
}
mc.affectedRows = 0
- mc.insertId = 0
if resLen > 0 {
_, e = mc.readUntilEOF()
PS. Thanks for your code. It has been a pleasure to work with your driver.
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
MySQL-Server version: Custom Percona Build
Used Operation System (CenOS 5.8):
<b>Example code which reproduces the error (optional):</b>
Please see problem statement.
This is Issue 9 moved from a Google Code project.
Added by 2012-07-31T17:38:51.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Enhancement, Priority-Medium
<b>Problem summary:</b>
A table that has datetime fields can't be read as time.Time using Scan()
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
latest
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
Server version: 5.1.37 MySQL Community Server (GPL)
Golang: 1.0.2
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
OSX Mountain Lion
<b>Example code which reproduces the error (optional):</b>
Test case here: https://gist.github.com/3218753
Create a db from DNS String and run Query, like this
db, e := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/mysql?charset=utf8")
rows, e := db.Query("select * from test.tb")
I found the Query is the method of mysqlStmt, How can I use the Query of mysqlConn.
This is Issue 18 moved from a Google Code project.
Added by 2012-12-01T11:52:38.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Invalid).
Original labels: Type-Defect, Priority-High
<b>Problem summary:</b>
2012/12/01 06:39:42 &{0xf840059078 kevin:wrongpass@tcp(192.168.0.100:3306)/mysql
{0 0} [] false}
2012/12/01 06:39:42 <nil>
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
[MySQL] 2012/12/01 06:39:42 packets:78 EOF
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x50 pc=0x401281]
goroutine 1 [running]:
main.main()
D:/programming/db.go:32 +0x281
goroutine 2 [syscall]:
created by runtime.main
D:/dev/go/src/pkg/runtime/proc.c:225
goroutine 3 [syscall]:
syscall.Syscall6(0x774fa4d0, 0x5, 0x98, 0xf84004df00, 0xf840059208, ...)
D:/dev/go/src/pkg/runtime/zsyscall_windows_windows_amd64.c:97 +0x55
syscall.GetQueuedCompletionStatus(0x98, 0xf84004df00, 0xf840059208, 0xf840059200
, 0xffffffff, ...)
D:/dev/go/src/pkg/syscall/zsyscall_windows_amd64.go:506 +0x9f
net.(*resultSrv).Run(0xf840059108, 0x0)
D:/dev/go/src/pkg/net/fd_windows.go:123 +0x97
created by net.startServer
D:/dev/go/src/pkg/net/fd_windows.go:252 +0xfd
exit status 2
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
May 30, 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
mysqld Ver 5.1.66-0ubuntu0.11.10.2 for debian-linux-gnu on x86_64 ((Ubuntu))
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit, OS X</b>
<b>10.8):</b>
Ubuntu 12.04 64bit
<b>Example code which reproduces the error (optional):</b>
This is Issue 12 moved from a Google Code project.
Added by 2012-08-23T10:06:17.000Z by julian.morrison.
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
Query of "select max(id) from foo" returns a row even when the foo table is empty (rows.Next() returns true, QueryRows().Scan() doesn't return sql.ErrNoRows). The row's column has a value of "" which breaks the Scan() into a uint64. It ought to return no rows.
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
May 30, 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
MySQL-Server 5.5.24
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
Ubuntu 12.04 32bit
Hello Julien,
In previous revisions using *sql.RawBytes
in Scan() worked perfectly, but now it looks like even the wiki example does not work anymore.
According to my tests, the last revision that supported *sql.RawBytes
was a8a04cc28d45f986dbb9c4c2e76e805bf7b17787, but since 13d97656dab643725f7f2f6509dfab3763e44d6a it fails with the well known error:
panic: sql: Scan error on column index 0: unsupported driver -> Scan pair: uint64 -> *sql.RawBytes
Here is the full example I am using:
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "gotest:gopass@unix(/var/run/mysqld/mysqld.sock)/gotest")
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
sqls := []string{
"drop table if exists foo",
"create table foo (id bigint(20) unsigned not null auto_increment, primary key(id), name text)",
"delete from foo",
}
for _, sql := range sqls {
_, err = db.Exec(sql)
if err != nil {
fmt.Printf("%q: %s\n", err, sql)
return
}
}
for i := 0; i < 5; i++ {
db.Exec(`INSERT INTO foo (name) VALUES ('Hello')`)
}
rows, err := db.Query(`SELECT * from foo`)
// Get column names
columns, err := rows.Columns()
if err != nil {
panic(err.Error())
}
// Make a slice for the values
values := make([]sql.RawBytes, len(columns))
// rows.Scan wants '[]interface{}' as an argument, so we must copy the
// references into such a slice
// See http://code.google.com/p/go-wiki/wiki/InterfaceSlice for details
scanArgs := make([]interface{}, len(values))
for i := range values {
scanArgs[i] = &values[i]
}
// Fetch rows
for rows.Next() {
// get RawBytes from data
err = rows.Scan(scanArgs...)
if err != nil {
panic(err.Error())
}
// Now do something with the data.
// Here we just print each column as a string.
var value string
for i, col := range values {
// Here we can check if the value is nil (NULL value)
if col == nil {
value = "NULL"
} else {
value = string(col)
}
fmt.Println(columns[i], ": ", value)
}
fmt.Println("-----------------------------------")
}
}
I assume this *sql.RawBytes
must be a pain to support and that's why practically all sql drivers seem to have issues with it but do you think it could be worked around again without removing features from your package? is there any alternative to get a plain []byte
stream or *sql.RawBytes
instead of an automatic conversion?
Thanks,
Carlos
It is always empty, when the type of table's column is longtext. Is this a bug?
I'm using the driver in a backup program.
The restore part could really profit from "load data local infile" support, which would be even better if I can feed it from a Reader (so I can convert from a binary format to the required CSV format on the fly).
Please treat this as an enhancement request, I don't mind the support if it's only based on the local filesystem (which is the case for every other mysql connector I checked so far).
Hello Julien,
I ran into an issue today, I was trying to import a very big dataset into a MySQL table using your driver, it successfully inserted some items but then the server just killed the connection. I tracked the problem down, not sure about the cause but it seems that Go-SQL-Driver/MySQL
is opening a connection each time it makes a query instead of using the previously opened one.
Steps to reproduce:
1 - Set max_connections
to a low number, like 10, in my.cnf
2 - Reset MySQL
# systemctl restart mysqld
3 - Check active connections (2)
mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
4 - Run this program that would normally execute 100 simple queries.
package main
import (
"database/sql"
_ "github.com/Go-SQL-Driver/MySQL"
)
func main() {
db, err := sql.Open("mysql", "root:@/gotest?charset=utf8")
if err != nil {
panic(err)
}
defer db.Close()
for i := 0; i < 100; i++ {
_, err = db.Query("SELECT NOW()")
if err != nil {
panic(err)
}
}
}
5 - Watch the client dying:
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
[MySQL] 2013/02/13 15:55:58 packets:80 EOF
panic: driver: bad connection
goroutine 1 [running]:
main.main()
/home/xiam/gomysqlbug.go:20 +0x13b
goroutine 2 [syscall]:
created by runtime.main
/usr/lib/go/src/pkg/runtime/proc.c:221
goroutine 3 [syscall]:
syscall.Syscall6()
/usr/lib/go/src/pkg/syscall/asm_linux_amd64.s:40 +0x5
syscall.EpollWait(0xf800000006, 0xf84007b0c0, 0xa0000000a, 0xffffffff, 0xc, ...)
/usr/lib/go/src/pkg/syscall/zerrors_linux_amd64.go:1846 +0xa1
net.(*pollster).WaitFD(0xf84007b0b0, 0xf840041980, 0x0, 0x0, 0x0, ...)
/usr/lib/go/src/pkg/net/fd_linux.go:146 +0x110
net.(*pollServer).Run(0xf840041980, 0x0)
/usr/lib/go/src/pkg/net/fd.go:236 +0xe4
created by net.newPollServer
/usr/lib/go/src/pkg/net/newpollserver.go:35 +0x382
exit status 2
6 - Check active connections (it opened exactly 10, plus the current one)
mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Another way to reproduce:
# Going to the projects directory
$ cd $GOPATH/src/github.com/Go-SQL-Driver/MySQL
# Checking connection ID (2)
$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
...
^C
# Executing tests
$ go test
PASS
ok github.com/Go-SQL-Driver/MySQL 5.066s
# Check connections again, are we really using 29 connections?
$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31
...
Hope it helps.
Regards,
José Carlos
Go doesn't offer a way to see if the statement produced warnings (as far as I know). I thought about some way to access it but it doesn't seem possible through standard database/sql
.
Could we have a setting that treats warnings as errors? This would be something I'd enable in development to help avoid writing code that may cause problems. The driver would need to check for warnings after every statement. This data is transmitted in the protocol; it doesn't require a SHOW WARNINGS
statement. If there are warnings, a SHOW WARNINGS LIMIT 1
would get the first one, and the driver could return something like "statement caused $N warnings: $first_warning".
Thoughts?
I have the problem it opens many connections before closing them.
It should have a pool with max connection and never be able to get pass that. As i run the code, and gets the error with to many connections.
I'm very impressed with this package from the testing that I've done thus far. It appears to be very fast. Testing is in early stages. I'm currently testing in Windows and haven't tried it with Linux yet. I use a deferred function for Transaction Rollback. I'm not sure if it's possible for application program to test for "inTransaction". I would prefer to be able to test if there is an active transaction in the Transaction object, rather than rely on the application program to set a flag. It's better IMHO to use inherent data than to set flags - just one more possible error (bug). Alternatively, as a second choice, I would prefer that Rollback did not return an error where there is no active transaction. Another possible better solution (if possible) would be to set Tx to nil when either Commit or Rollback completed, because as far as I can see, Tx cannot be "used" after that. Although this is a minor complaint, it would be good IMHO if you could look at it. I see from the Golang documentation that any call to Tx after a Commit or Rollback returns ErrTxDone. Perhaps that is an argument to set Tx to nil (if possible). My preference would be to set Tx to nil.
I used to use the code from Google Code. After updating to the latest code in master, I'm getting the following error I didn't get previously:
sql: Scan error on column index 7: unsupported driver -> Scan pair: <nil> -> *string
I will investigate more, but perhaps in the meantime you know something about this already?
This is Issue 3 moved from a Google Code project.
Added by 2012-05-21T08:18:58.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Invalid).
Original labels: Type-Defect, Priority-Medium
<b>What steps will reproduce the problem?</b>
1. if the password has '@' inside, the DSN cannot be parsed correctly
<b>2.</b>
<b>3.</b>
<b>What is the expected output? What do you see instead?</b>
<b>What version of the product are you using? On what operating system?</b>
<b>Please provide any additional information below.</b>
@ is used to separate password and address. However, if the password itself has '@', the DSN cannot be parsed correctly.
This is Issue 1 moved from a Google Code project.
Added by 2012-05-14T12:46:58.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Enhancement, Priority-High, OpSys-All
<b>What steps will reproduce the problem?</b>
1. In query example at
http://goseeds.blogspot.com/2012/05/google-go-and-mysql-tutorial.html
2. duplicate the row up to 500 row in my_db.document table on mysql server.
<b>What is the expected output? What do you see instead?</b>
3. set the query return row limit from 10 to 410, the program runs ok. last line of output is "Total: 410".
4. set the query return row limit from 10 to 500, the program die of "driver: bad connection".
<b>What version of the product are you using? On what operating system?</b>
go version 1.0.1
mysql server 5.0.81
<b>Please provide any additional information below.</b>
Hi,
I use your driver in my https://github.com/hgfischer/mysqlsuperdump/ project and in the latest builds I'm getting this kind of error, when dumping a database at Amazon's RDS from a EC2 Ubuntu 12.10 64bits.
"panic: sql: Scan error on column index 0: unsupported driver -> Scan pair: int64 -> *sql.RawBytes"
The error comes after trying to select data from the following database structure:
CREATE TABLE `address_region` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`country_id` bigint(20) NOT NULL,
`symbol` varchar(2) NOT NULL,
`name` varchar(255) NOT NULL,
`slug` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_343B74C95E237E06F92F3E70` (`name`,`country_id`),
UNIQUE KEY `UNIQ_343B74C9ECC836F9F92F3E70` (`symbol`,`country_id`),
UNIQUE KEY `slug` (`slug`,`country_id`),
KEY `IDX_343B74C9F92F3E70` (`country_id`),
KEY `idx_name` (`name`),
KEY `idx_slug` (`slug`),
KEY `idx_symbol` (`symbol`),
KEY `idx_created_at` (`created_at`),
KEY `idx_updated_at` (`updated_at`),
CONSTRAINT `FK_343B74C9F92F3E70` FOREIGN KEY (`country_id`) REFERENCES `country` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;
With the following query:
SELECT id, country_id, symbol, name, slug, created_at, updated_at FROM `address_region`
And the stack trace from mysqlsuperdump is this:
goroutine 1 [running]:
main.checkError(0xf8400491e0, 0xf8400a57a0)
/var/lib/jenkins/workspace/mysqlsuperdump/mysqlsuperdump.go:90 +0x4e
main.dumpTableData(0xf840049600, 0xf840074160, 0xf8400449c0, 0xf840073600, 0x10000000e, ...)
/var/lib/jenkins/workspace/mysqlsuperdump/mysqlsuperdump.go:239 +0x6df
main.main()
/var/lib/jenkins/workspace/mysqlsuperdump/mysqlsuperdump.go:81 +0x3d6
I don't think it's a problem with mysqlsuperdump, since I've not changed the code between your driver updates. If something changed in the driver and my code is doing it wrong, please let me know.
This is Issue 16 moved from a Google Code project.
Added by 2012-10-28T06:12:01.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-Critical
<b>Problem summary:</b>
DB.Exec() always returns "no RowsAffected available after DDL statement" even if it affected some rows indeed.
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
May 30, 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
mysql Ver 14.14 Distrib 5.5.24, for osx10.6 (i386) using readline 5.1
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
Mac OS X 10.7.5
<b>Example code which reproduces the error (optional):</b>
// 1. Make sure the Test table in MyDatabase has a row with id 1.
// 2. Run the following code with go(version go1.0.3).
package main
import (
"fmt"
"database/sql"
_ "code.google.com/p/go-mysql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root:password@/MyDatabase?charset=utf8")
if err != nil {
panic(err)
}
if result, err := db.Exec("delete from Test where id=1"); err != nil {
panic(err)
} else {
fmt.Printf("result=%#v\n", result)
if affected, err := result.RowsAffected(); err != nil {
fmt.Println(err)
} else {
fmt.Printf("Deleted %v rows.\n", affected)
}
}
}
This is Issue 15 moved from a Google Code project.
Added by 2012-10-17T14:23:23.000Z by julian.morrison.
Please review that bug for more context and additional comments, but update this bug.
Closed (Duplicate).
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
I had a "too many open connections" error on MySQL. The sql.DB connections I had open started giving errors like
[MySQL] 2012/10/17 15:12:58 packets:102 write tcp 127.0.0.1:3306: broken pipe
They did not reconnect.
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
May 30, 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
MySQL-Server 5.5.24
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
Ubuntu 12.04 32bit
I am getting the following error when calling on my stored procedure
Error 1312: PROCEDURE mydb.GetAllNotes can't return a result set in the given context
I am calling on my stored procedure with this code
db.Query("CALL MyStoredProcedure()")
mysql> DESCRIBE foo;
+----------------+--------------+------+-----+-----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+-----------+----------------+
...
| created_at | datetime | YES | MUL | NULL | |
...
type MyFoo struct {
...
CreatedAt time.Time
...
}
rows, err := db.Query(
`
SELECT
...
foo.created_at,
...
FROM foo
WHERE ...
`,
)
err := rows.Scan(
...
&myFoo.CreatedAt,
...
sql: Scan error on column index 3: unsupported driver -> Scan pair: []uint8 -> *time.Time
This is Issue 6 moved from a Google Code project.
Added by 2012-06-21T16:02:00.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (WontFix).
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
After some inactivity I get the following error:
2012-06-21_12:53:05.71328 [MySQL] 2012/06/21 12:53:05 packets:102 write unix /var/run/mysqld/mysqld.sock: broken pipe
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
latest
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
Server version: 5.1.63-rel13.4 (Percona Server (GPL), 13.4, Revision 443)
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
Linux go-playground 2.6.32-344-ec2 #46-Ubuntu SMP Wed Mar 7 13:47:05 UTC 2012 x86_64 GNU/Linux
<b>Example code which reproduces the error (optional):</b>
I connect to the database through unix socket, dsn is roughly:
login:pass@unix(/var/run/mysqld/mysqld.sock)/stats?charset=utf8
After a short while all 10 connections are in broken pipe mode and will never be reconnected.
I have downloaded the latest version of the driver with
go get github.com/Go-SQL-Driver/MySQL
I am not getting errors is I use sql.NullString when loading null values but I am still getting the error for sql.NullFloat64
sql: Scan error on column index 4: converting string "" to a float64: strconv.ParseFloat: parsing "": invalid syntax
Is there only support for null strings? or should this be working for null float64?
D:\>go get github.com/go-sql-driver/mysql
# github.com/go-sql-driver/mysql
go\src\github.com\go-sql-driver\mysql\infile.go:102: undefined: driver.ErrBadConn
go\src\github.com\go-sql-driver\mysql\infile.go:115: undefined: driver.ErrBadConn
go\src\github.com\go-sql-driver\mysql\packets.go:33: undefined: driver.ErrBadConn
go\src\github.com\go-sql-driver\mysql\packets.go:41: undefined: driver.ErrBadConn
go\src\github.com\go-sql-driver\mysql\packets.go:70: undefined: driver.ErrBadConn
go\src\github.com\go-sql-driver\mysql\packets.go:90: undefined: driver.ErrBadConn
go\src\github.com\go-sql-driver\mysql\packets.go:125: undefined: driver.ErrBadConn
D:\>
This is Issue 11 moved from a Google Code project.
Added by 2012-08-20T10:38:39.000Z by julian.morrison.
Please review that bug for more context and additional comments, but update this bug.
Closed (Duplicate).
Original labels: Type-Enhancement, Priority-Medium
In particular time.Time for all the time and date types, big.Rat for all the fixnum types, and unsigned numbers all the way up to uint64. (We are having to work around this by using strings.)
I wrote a benchmark test program to test this driver, but the test result is not good.
Only 500 querys pre second,
mysqlslap can process 5000 querys pre second in same machine.
I checked the mysql log
mysqlslap's logs:
130218 17:19:05
1002 Connect [email protected] on
1003 Connect [email protected] on test
1003 Query SELECT * FROM users WHERE id = '00000'
1003 Query SELECT * FROM users WHERE id = '00001'
....
1003 Query SELECT * FROM users WHERE id = '00999'
1003 Quit
Go-MySQL-Driver's logs:
130218 17:18:32
2 Connect [email protected] on test
2 Query SET NAMES utf8
2 Prepare [1] SELECT * FROM users WHERE id = '00000'
2 Execute [1] SELECT * FROM users WHERE id = '00000'
3 Connect [email protected] on test
3 Query SET NAMES utf8
3 Prepare [1] SELECT * FROM users WHERE id = '00001'
3 Execute [1] SELECT * FROM users WHERE id = '00001'
....
1001 Connect [email protected] on test
1001 Query SET NAMES utf8
1001 Prepare [1] SELECT * FROM users WHERE id = '00999'
1001 Execute [1] SELECT * FROM users WHERE id = '00999'
This is Issue 17 moved from a Google Code project.
Added by 2012-11-21T11:21:16.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Invalid).
Original labels: Type-Review, Priority-High
file: connection.go
117 time.Sleep(diff)
when I use many mysql tables, this will sleep #number_of_table seconds.
This is Issue 2 moved from a Google Code project.
Added by 2012-05-21T08:15:55.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-High, OpSys-Windows
<b>What steps will reproduce the problem?</b>
1. on Windows
2. Query
<b>3.</b>
<b>What is the expected output? What do you see instead?</b>
expected output: success
actual output: driver: bad connection
<b>What version of the product are you using? On what operating system?</b>
<b>Please provide any additional information below.</b>
Suggested fix:
line 52 of packets.go
n, e := mc.netconn.Read(data)
if e != nil || n != int(pktLen) {
e = driver.ErrBadConn
}
Here, we assume Read only return when the data is filled. But at least on Go Windows version, it will return prematurely.
So maybe we can change the code to
n, e := mc.netconn.Read(data)
na := 0
for e == nil && n < int(pktLen) {
na, e = mc.netconn.Read(data[n:])
n += na
}
I've verified it on Windows, it works.
This is Issue 21 moved from a Google Code project.
Added by 2012-12-31T14:55:22.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-Medium
The DSN scheme requires you to specify a database to connect to. But it is perfectly valid (in general MySQL usage) to connect without specifying a database.
Can we set mysql read/write timeout,?
MYSQL_OPT_READ_TIMEOUT ..
Trying to ApacheBench test a basic page created with Go, and I get this error:
2013/03/05 23:27:03 http: panic serving ipaddress:58369: runtime error: slice bounds out of range
/usr/local/go/src/pkg/net/http/server.go:589 (0x43eb1b)
_func_004: buf.Write(debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0x410aab)
panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/runtime.c:128 (0x411577)
panicstring: runtime·panic(err);
/usr/local/go/src/pkg/runtime/runtime.c:91 (0x411448)
panicslice: runtime·panicstring("slice bounds out of range");
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/packets.go:133 (0x44b2a6)
com/Go-SQL-Driver/MySQL.(*mysqlConn).readInitPacket: mc.cipher = append(mc.cipher, data[pos:pos+12]...)
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/driver.go:46 (0x44a38a)
com/Go-SQL-Driver/MySQL.(*mysqlDriver).Open: err = mc.readInitPacket()
/usr/local/go/src/pkg/database/sql/sql.go:248 (0x4435bd)
(*DB).conn: return db.driver.Open(db.dsn)
/usr/local/go/src/pkg/database/sql/sql.go:310 (0x443b10)
(*DB).prepare: ci, err := db.conn()
/usr/local/go/src/pkg/database/sql/sql.go:295 (0x443a33)
(*DB).Prepare: stmt, err = db.prepare(query)
/usr/local/go/src/pkg/database/sql/sql.go:380 (0x444493)
(*DB).Query: stmt, err := db.Prepare(query)
/myfolder/test.go:13 (0x400cd0)
wwwHandler: result, e := db.Query("SELECT * FROM s WHERE sid=?",sid)
/myfolder/test.go:35 (0x401406)
_func_001: wwwHandler(w, r, db)
/usr/local/go/src/pkg/net/http/server.go:703 (0x432964)
HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:941 (0x4337b8)
(*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x432777)
(*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0x40ebb1)
goexit: runtime·goexit(void)
Here's my code:
package main
import (
"fmt"
"net/http"
"database/sql"
_ "github.com/Go-SQL-Driver/MySQL"
)
func wwwHandler(w http.ResponseWriter, r *http.Request, db *sql.DB) {
for i := 0; i < 10; i++ {
sid := 1
result, e := db.Query("SELECT * FROM s WHERE sid=?",sid)
if e != nil {
panic(e.Error())
}
result.Next()
var resultsid, created, posted, title, above_the_fold, below_the_fold sql.NullString
var draft_or_final bool
err := result.Scan(&resultsid,&created,&posted,&title,&above_the_fold,&below_the_fold,&draft_or_final)
if err != nil {
panic(err.Error())
}
fmt.Fprintf(w, "%s%s%s%s%s",resultsid.String,created.String,title.String,above_the_fold.String,below_the_fold.String)
}
}
func main() {
db, e := sql.Open("mysql", "username:password@/dbname")
if e != nil {
panic(e.Error())
}
defer db.Close()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
wwwHandler(w, r, db)
})
http.ListenAndServe(":80",nil)
}
This is Issue 4 moved from a Google Code project.
Added by 2012-05-25T02:25:57.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Task, Priority-Critical, Performance
In the current beta release Queries are conspicuously slow.
There seems to be a slow part somewhere at either fetching the result or at converting the result.
Some profiling and performance optimization is necessary here.
There appears to be a regression in the handling of DATE
values:
db-val: 2012-06-14
old-val: 2012-06-14
new-val: 56324-07-06
DATETIME
continues to work as expected
edit I new
refers to current master, old refers to code.google.com/p/go-mysql-driver/mysql
This is Issue 13 moved from a Google Code project.
Added by 2012-09-27T21:15:48.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (WontFix).
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
Any query that has an expected return (i.e. SELECT, SHOW, etc.) returns an EOF error on *sql.DB.Query() or *sql.DB.QueryRow(). CREATE TABLE and DROP TABLE work fine. Nonsense queries (e.g. on non-existant tables) and incorrect credentials generate the expected errors, so connecting to the DB isn't the problem.
Everything works fine on MySQL 5.0+
Used go-mysql-version (e.g. May 26, 2012):May 30, 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
MySQL-Server 4.1.21
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit):</b>
Server: CentOS 5.1, Client: OS X 10.8.2
<b>Example code which reproduces the error (optional):</b>
func main() {
dbs, err := sharddbs.GetDBs()
if err != nil {
panic(err)
}
for _, db := range dbs {
row := db.QueryRow("SHOW TABLES")
var result string
err = row.Scan(&result)
if err != nil {
panic(err) //panic happens here
}
fmt.Println(result)
}
}
Stack trace:
panic: EOF
goroutine 1 [running]:
main.main()
/Users/tamird/dev/go/src/15852/15852.go:18 +0x22c
----- stack segment boundary -----
goroutine 2 [syscall]:
created by runtime.main
/usr/local/Cellar/go/1.0.3/src/pkg/runtime/proc.c:221
goroutine 3 [syscall]:
syscall.Syscall6()
/usr/local/Cellar/go/1.0.3/src/pkg/syscall/asm_darwin_amd64.s:38 +0x5
syscall.kevent(0x14, 0x0, 0x0, 0xf84006d188, 0xa, ...)
/usr/local/Cellar/go/1.0.3/src/pkg/syscall/zsyscall_darwin_amd64.go:199 +0x88
syscall.Kevent(0xf800000014, 0x0, 0x0, 0xf84006d188, 0xa0000000a, ...)
/usr/local/Cellar/go/1.0.3/src/pkg/syscall/syscall_bsd.go:546 +0xa4
net.(*pollster).WaitFD(0xf84006d180, 0xf84008aac0, 0x0, 0x0, 0x0, ...)
/usr/local/Cellar/go/1.0.3/src/pkg/net/fd_darwin.go:96 +0x185
net.(*pollServer).Run(0xf84008aac0, 0x0)
/usr/local/Cellar/go/1.0.3/src/pkg/net/fd.go:236 +0xe4
created by net.newPollServer
/usr/local/Cellar/go/1.0.3/src/pkg/net/newpollserver.go:35 +0x382
exit status 2
This is Issue 22 moved from a Google Code project.
Added by 2013-01-05T09:28:30.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Duplicate).
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
I want to create database, but I can't create a dsn without dbname
<b>Go-MySQL-Driver version (e.g. May 26, 2012):</b>
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
<b>Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit, OS X</b>
<b>10.8):</b>
<b>Example code which reproduces the error (optional):</b>
This is Issue 19 moved from a Google Code project.
Added by 2012-12-08T04:37:11.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Closed (Duplicate).
Original labels: Type-Defect, Priority-Medium
<b>Problem summary:</b>
column index 3 is a field of DATETIME type, and here goes the error while calling rows.Scan()
`sql: Scan error on column index 3: unsupported driver -> Scan pair: []uint8 -> *time.Time`
Note that this driver works (https://github.com/ziutek/mymysql ) without any problem.
<b>Used go-mysql-version (e.g. May 26, 2012):</b>
Oct. 30 2012
<b>MySQL-Server version (e.g. MySQL-Server 5.5 or MariaDB 5.1):</b>
5.5.28-0
<b>Used Operation System (e.g. Windows 7 64bit, Ubuntu 12.04 64bit, OS X</b>
<b>10.8):</b>
ubuntu0.12.04.2
<b>Example code which reproduces the error (optional):</b>
This is a low-priority TODO, I'd like to wait until Brad's changes are in.
I got bitten by statments which can not be prepared. See MySQL documentation: SQL Syntax Allowed in Prepared Statements.
We should probably report errors in statments.go:Query(...) with len(args) > 0
if stmt.paramCount == 0
as an error caused by using prepared statements, right now it's a little confusing without background knowledge.
Currently, the error looks like sql: statement expects 0 inputs; got 1
.
While checking this, I also spotted a missing closing brace in an error in packets.go.
I hit this while trying to use
SHOW TABLES FROM `?`
which should be a legitimate way to explore the databases and tables on a server.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.