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 protocol version %d. 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"
	"errors"
	"fmt"
	"io"
	"math"
	"time"
)
func (mc *mysqlConn) readPacket() ([]byte, error) {
	var prevData []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 data[3] != mc.sequence {
			if data[3] > mc.sequence {
				return nil, ErrPktSyncMul
			}
			return nil, ErrPktSync
		}
		mc.sequence++
		if pktLen == 0 {
			if prevData == nil {
				errLog.Print(ErrMalformPkt)
				mc.Close()
				return nil, driver.ErrBadConn
			}
			return prevData, nil
		}
		data, err = mc.buf.readNext(pktLen)
		if err != nil {
			errLog.Print(err)
			mc.Close()
			return nil, driver.ErrBadConn
		}
		if pktLen < maxPacketSize {
			if prevData == nil {
				return data, nil
			}
			return append(prevData, data...), nil
		}
		prevData = append(prevData, data...)
	}
}
func (mc *mysqlConn) writePacket(data []byte) error {
	pktLen := len(data) - 4
	if pktLen > mc.maxAllowedPacket {
		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
		if mc.writeTimeout > 0 {
			if err := mc.netConn.SetWriteDeadline(time.Now().Add(mc.writeTimeout)); err != nil {
				return err
			}
		}
		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
	}
}