Broad Network


MySQL Protocol Basics for PurePerl

Writing MySQL Protocol Packets in PurePerl – Part 2

Writing a Perl Module

Foreword: In this part of the series, I talk about MySQL Protocol Basics for PurePerl.

By: Chrysanthus Date Published: 27 Jan 2015

Introduction

This is part 2 of my series, Writing MySQL Protocol Packets in PurePerl. PurePerl stands for Pure Perl, meaning Perl software without C software underneath. When a user connects to the MySQL server and uses a database, a set of technical rules is respected. These rules are together called the MySQL Protocol. Remember, the MySQL server is software that produces and maintains the databases. For the user to communicate with the server, there has to be client software. In practice, the communication is between the client software and the server and not really between the user (human client) and the server. The MySQL protocol is applied between the client software and the server. In this part of the series, I talk about MySQL Protocol Basics for PurePerl.

You should have read the previous part of the series before coming here as this is a continuation.

Connection States
Communication between the client software and the server is in two phases called the Authentication Phase and the Query Phase. Communication is done in data packets, which are of different lengths. A packet is a series of bytes (characters). In a conversation, packets are form, and they moved between client and server. The following is a flow diagram of the packets (except for connect which is not a packet).

The Authentication Phase
In the authentication phase, the client software connects to the server (software) using a socket and port; this connection process does not really use a packet. If the server accepts the connection, it sends a greeting (handshake) packet to the client. The second arrow in the diagram shows this. The greeting packet contains a scrambled message from the server.  

In a special way, the client software combines the scramble message with the password of the user. This combination and the user name is sent in a packet, by the client, to the server as a Credentials (authentication) packet. After processing the packet, the server (software) sends either an OK packet or an ERROR packet to the client (Auth-Result in diagram). The OK packet here, indicates to the client that he is accepted to converse. The ERROR packet means either there was an error in the credentials packet or the human user is not known by the server.

The user may not be conscious of these four communication processes (arrows in diagram). All he knows is that, he has to type in his username and password in the client program, and send the information to the server; he then waits to know whether or not he has been accepted to carry out his conversation. However, deep down in the communication, those 4 low level programming processes musts take place. These are indicated by the top four arrows in the diagram.

The Query Phase
If the client software is accepted to converse, it goes into a cycle of conversation. This phase is indicated by the last two states in the diagram above. The client sends a query (command) packet to the server. The server replies with one or more result packets.

That is it for this part of the series. We stop here and continue in the next part.

Chrys

Related Links

Internet Sockets and Perl
Perl pack and unpack Functions
Writing MySQL Protocol Packets in PurePerl
Developing a PurePerl MySQL API
Using the PurePerl MySQL API
More Related Links
Perl Mailsend
PurePerl MySQL API
Perl Course - Professional and Advanced
Major in Website Design
Web Development Course
Producing a Pure Perl Library
MySQL Course

BACK NEXT

Comments

Become the Writer's Fan
Send the Writer a Message