func (mc *mysqlConn) readInitPacket() ([]byte, error) {
	data, err := mc.readPacket()
	if err != nil {
		return nil, err
	}
	if data[0] == iERR {
		return nil, mc.handleErrorPacket(data)
	}
	if data[0] < minProtocolVersion {
		return nil, fmt.Errorf(
			"Unsupported MySQL Protocol Version %d. Protocol Version %d or higher is required",
			data[0],
			minProtocolVersion,
		)
	}
	pos := 1 + bytes.IndexByte(data[1:], 0x00) + 1 + 4
	cipher := data[pos : pos+8]
	pos += 8 + 1
	mc.flags = clientFlag(binary.LittleEndian.Uint16(data[pos : pos+2]))
	if mc.flags&clientProtocol41 == 0 {
		return nil, ErrOldProtocol
	}
	if mc.flags&clientSSL == 0 && mc.cfg.tls != nil {
		return nil, ErrNoTLS
	}
	pos += 2
	if len(data) > pos {
		pos += 1 + 2 + 2 + 1 + 10
		cipher = append(cipher, data[pos:pos+12]...)
		var b [20]byte
		copy(b[:], cipher)
		return b[:], nil
	}
	var b [8]byte
	copy(b[:], cipher)
	return b[:], nil
}
****************************************************************************
Initialisation Process                            *
****************************************************************************
Handshake Initialization Packet
http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake
package mysql
import (
	"bytes"
	"crypto/tls"
	"database/sql/driver"
	"encoding/binary"
	"fmt"
	"io"
	"math"
	"time"
)
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
			} else {
				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
		}
	}
}
func (mc *mysqlConn) writePacket(data []byte) error {
	pktLen := len(data) - 4
	if pktLen > mc.maxPacketAllowed {
		return ErrPktTooLarge
	}
	for {
		var size int
		if pktLen >= maxPacketSize {
			data[0] = 0xff
			data[1] = 0xff
			data[2] = 0xff
			size = maxPacketSize
		} else {
			data[0] = byte(pktLen)
			data[1] = byte(pktLen >> 8)
			data[2] = byte(pktLen >> 16)
			size = pktLen
		}
		data[3] = mc.sequence
		n, err := mc.netConn.Write(data[:4+size])
		if err == nil && n == 4+size {
			mc.sequence++
			if size != maxPacketSize {
				return nil
			}
			pktLen -= size
			data = data[size:]
			continue
		}
		if err == nil {  
			errLog.Print(ErrMalformPkt)
		} else {
			errLog.Print(err)
		}
		return driver.ErrBadConn
	}
}