MySQL Basic
MySQL Basic
MySQL Architecture
Common Tools
Examples
Antnio Amorim, Carlos Jesus. CU1 - DBWorkshop 9-10 /Feb/09
MySQL Overview
What is MySQL?
MySQL, the most popular Open Source SQL database management system, is developed,
distributed, and supported by MySQL AB. MySQL AB is a commercial company, founded in 1995 by
the MySQL developers. It is a second generation Open Source company that unites Open Source
values and methodology with a successful business model.
The MySQL software delivers a very fast, multi-threaded, multi-user, and robust SQL (Structured
Query Language) database server. MySQL Server is intended for mission-critical, heavy-load
production systems as well as for embedding into mass-deployed software. MySQL is a registered
trademark of MySQL AB.
wits
The MySQL software is Dual Licensed. Users can choose to use the MySQL software as an Open
Source product under the terms of the GNU General Public License or can purchase a standard
commercial license from MySQL AB.
The company name was given after co-founder Monty Widenius's daughter, My, the SQL is
Structured Query Language., AB is Sweedish for limited partnership.
MySQL Overview
What does it do?
wits
The MySQL Database Software is a client/server system that consists of a multi-threaded SQL server that supports different backends, several different client programs
and libraries, administrative tools, and a wide range of application programming interfaces (APIs).
MySQL Architecture
Three layer model:
The application layer contains common network
services for connection handling, authentication and
security. This layer is where different clients interact with
MySQL these clients can written in different API's:.NET,
Java, C, C++, PHP, Python, Ruby, Tcl, Eiffel, etc...
The Logical Layer is where the MySQL intelligence
resides, it includes functionality for query parsing, analysis,
caching and all built-in functions (math, date...). This layer
also provides functionality common across the storage
engines.
wits
MySQL Architecture
Each client connection gets its own thread within the server
process.
When clients (applications) connect to the MySQL server, the server
needs to authenticate them.
Before even parsing the query, though, the server consults the
query cache, which only stores SELECT statements, along with
their result sets.
The storage engine does affect how the server optimizes query.
MySQL Architecture
Atomicity
Consistency
Isolation
Durability
: Each transaction block is treated as a single instruction, all of the block must succeed or none.
: Only valid data is written to the database, and the resulting state is valid.
: While performing operations in a transaction block, other transactions don't see our changes.
: If the transaction returns a successful state it is persisted to the database.
MySQL Architecture
Storage engines:
MySQL supports several storage engines that act as handlers for different table types. MySQL storage
engines include both those that handle transaction-safe tables and those that handle non-transactionsafe tables.
MySQL Installation
Windows Installation wizard: http://dev.mysql.com/downloads/mysql/5.1.html#win32
Linux:
Debian Based: apt-get install mysql-server-5.0
RPM based:
YUM Based:
Macintosh:
http://dev.mysql.com/downloads/mysql/5.1.html#macosx
MySQL Overview
MySQL Files:
In Linux the configuration file is typically located at /etc/mysql/my.cnf, but may vary for
the different Linux flavours, this also applies to the database files them selves which are
located in the /var/lib/MySQL.
Regardless of the storage engine, every MySQL table you create is represented, on disk, by
a .frm file, which describes the tables format (i.e. the table definition). The file bears the
same name as the table, with a .frm extension. The .frm format is the same on all
platforms but in the description of the .frm format that follows, the examples come from
tables created under the Linux operating system.
/var/lib/mysql/db.frm
#Table definition
/var/lib/mysql/db.MYD
/var/lib/mysql/db.MYI
/var/lib/mysql/ibdata1
wits
MySQL
Command Line tools
On Linux the a user can interact with MySQL using the command line,
in this interaction a user can create, update, delete and modify a
MySQL database using the following command line tools
mysql: general database and table interaction:
mysql -u username -ppassword -h localhost db_name
mysqldump: database backup
mysqldump db_name > outputfile
mysqlbinlog: binary log processing
mysqlbinlog logfile_1 logfile_2 ... logfile_n > out.sql
mysqlbinlog logfile_1 logfile_2 ... logfile_n | mysql
mysql_install_db: database restore
mysql_install_db
Phpmyadmin is a browser
tool developed in php,
that
allows
you
to
manage
a
mysql
database.
test control:
dbbenchmark.properties.mysql_elem
gaia.cu1.tools.db.username=username
gaia.cu1.tools.db.password=password
gaia.cu1.tools.db.driver=com.mysql.jdbc.Driver
gaia.cu1.tools.db.url=jdbc:mysql://localhost:3306/gaia_test?rewriteBatchedStatements=true
MySQL queries
Create a database:
create database database_name;
Display databases:
show databases;
Selecting a database
use database_name
Display tables:
show tables
Create a table:
create table create table person
(id int, person varchar (32) )
engine=engine_name
Deleting a table:
Drop table table_name
Q&A
Books:
OreIlly High Performance MySQL Second Edition Jun 2008
OReilly MySQL in a Nutshell 2nd Edition
More on MySQL-cluster and other studies:
SIM Studies at the GAIA WIKI
The technical note:
GAIA-C1-TN-SIM-CDJ-001-1.pdf
GAIA-C1-TN-SIM-AAB-001-01.pdf
Antnio Amorim, Carlos Jesus. CU1 - First Database Testing Meeting, 20/Nov/08