MySQL Presentation
MySQL Presentation
AGENDA
2
Server Process
4
Server Process
The mysqld (server program) process can be sliced into the following three layers:
Connection layer: Handles connections. This layer exists on all software (Web/mail/LDAP
server)
SQL layer: Processes SQL queries that are sent by connected applications
Storage layer: Handles data storage. Data can be stored in different formats and
structures on different physical media.
5
Connection Layer
Confidentia 66
l
Connection Layer
The connection layer accepts connections from applications over
several communication protocols
TCP/IP
UNIX sockets
Shared memory
Named pipes
TCP/IP works across the network. The other protocols listed above
support only local connections when the client and server are
running on the same machine. This layer maintains one thread
per connection. This thread handles query execution. Before a
connection can begin sending SQL queries, the connection is
authenticated by verification of username+password+client host
Confidentia 77
l
Communication Protocols
8
SQL Layer
9
SQL Layer
10
SQL Statement Processing
11
Storage Layer
12
Storage Engine: InnoDB
ACID Compliant
Atomicity/Consistency/Isolation/Durability
Full transactional support and multi-versioning
Read Uncommitted, Read Committed, Repeatable Read, Serializable
Foreign keys constraints
Locking and logging
Row-level and next-key locking
Consistent non-locking reads
Commit and rollback segments
Fault tolerance and table spaces
Large datasets, raw partitions
Online backups
Storage Engine: MyISAM
File based storage
.MYD – table data
.MYI – index data
.FRM – table definition (schema)
Easily maintained
Architecture-independent data
Files can be copied across platforms
Low overhead
No transactions
Large grained table level locking
Excels at mostly-read applications
One third the memory/disk footprint of transactional engines
Storage Layer
Data can be stored on disk, memory, and network. Each table in
a database can use any of the available storage engines. Disk
storage is cheap and persistent, where as memory is much faster.
InnoDB is the default storage engine. It provides transactions,
full-text indexing, and foreign key constraints, and is thus useful
for a wide mix of queries. It is multipurpose and supports read-
intensive, read/write, and transactional workloads.
Other storage engines include:
MyISAM: Useful for mostly read and little update of data
MEMORY: Stores all data in memory
NDB: Used by MySQL Cluster to provide redundant scalable topology for highly
available data
15
Storage Engine: Overview
16
Features Dependent on Storage Engine
• Storage medium
• Transactional capabilities
• Locking
• Backup and recovery
• Optimization
• Special features
– Full-text search
– Referential integrity
– Spatial data handling
17
How MySQL Uses Disk Space
18
How MySQL Uses Disk Space
Program files are stored under server installation directories,
along with the data directory. The program executable and log
files are created by the execution of the various client,
administrative, and utility programs. The primary use of disk
space is the data directory.
Server log files and status file contain information about
statements that the server processes. Logs are used for
troubleshooting, monitoring, replication, and recovery.
InnoDB log files for all databases reside at the data directory
level
InnoDB System Tablespace contains the data dictionary, undo
log, and buffers.
19
How MySQL Uses Disk Space
Each database has a single directory under the data directory,
regardless of what types of tables are created in the database.
The database directories store the following:
Data files: Storage engine – specific data files. These files can also include
metadata or index information, depending on the storage engine used.
Format files (.frm) : Contain a description of each table and/or view structure,
located in the corresponding database directory.
Triggers: Named database objects that are associated with a table and are
activated when a particular event occurs for the table.
The location of the data directory depends on the configuration, operating
system, installation package, and distribution. A typical location is /var/lib/mysql.
MySQL stores the system database (mysql) on disk. Mysql contains information
such as users, privileges, plugins, help lists, events, time-zone implementations,
and stored routines
20
How MySQL Uses Memory
Global
Allocated once
Shared by the server process and its threads
Session
Allocated for each thread
Dynamically allocated and deallocated
Used for handling query results
Buffer sizes per session
21
How MySQL Uses Memory
Memory allocation can be divided into the following two
categories:
Global (per-instance memory): Allocated once when the
server starts and frees when the server shuts down. This
memory is shared across all sessions.
When all the physical memory has been used up, the
operating system starts swapping. This has an adverse effect
on MySQL server performance and can cause the server to
crash.
Session (per-session memory): Dynamically allocated per
session (sometimes referred to as thread). This memory can
be freed when the session ends or is no longer needed.
22
Memory Structures
Server allocates memory in three different
categories:
23
Summary
24
Thank You
25