func (mc *mysqlConn) readPacket() ([]byte, error) {
	var payload []byte
	for {
		data, err := mc.buf.readNext(4)
		if err != nil {
			errLog.Print(err)
			mc.Close()
			return nil, driver.ErrBadConn
		}
		pktLen := int(uint32(data[0]) | uint32(data[1])<<8 | uint32(data[2])<<16)
		if pktLen < 1 {
			errLog.Print(ErrMalformPkt)
			mc.Close()
			return nil, driver.ErrBadConn
		}
		if data[3] != mc.sequence {
			if data[3] > mc.sequence {
				return nil, ErrPktSyncMul
			}
			return nil, ErrPktSync
		}
		mc.sequence++
		data, err = mc.buf.readNext(pktLen)
		if err != nil {
			errLog.Print(err)
			mc.Close()
			return nil, driver.ErrBadConn
		}
		isLastPacket := (pktLen < maxPacketSize)
		if isLastPacket && payload == nil {
			return data, nil
		}
		payload = append(payload, data...)
		if isLastPacket {
			return payload, nil
		}
	}
}
Packets documentation:
http://dev.mysql.com/doc/internals/en/client-server-protocol.html
Read packet to buffer 'data'
package mysql
import (
	"bytes"
	"crypto/tls"
	"database/sql/driver"
	"encoding/binary"
	"errors"
	"fmt"
	"io"
	"math"
	"time"
)