SlideShare une entreprise Scribd logo
1  sur  16
MySQL
Dept. of Computing Science, University of Aberdeen 2
In this lecture you will learn
• The main subsystems in MySQL
architecture
• The different storage engines or table
types in MySQL
• How you can define the storage engine
or table type to be used for your tables
• How you can improve the performance
of your queries
Dept. of Computing Science, University of Aberdeen 3
Introduction
• MySQL is an open source RDBMS
• Main Features
– Server-client architecture
– Available for a variety of platforms including Windows and
Linux
– Multiple storage engines
• Users/applications can select the storage engine for their
database
– Based on their requirements
• Can even mix and match different engines within the same
database
– Supports ANSI SQL
– Version 5.0 is the current stable release
– Version 5.0 supports certain spatial data types
Dept. of Computing Science, University of Aberdeen 4
MySQL Architecture
• Primary subsystems
– The Query Engine
– The Storage Manager
– The Buffer Manager
– The Transaction Manager
– The Recovery Manager
• Support components
– The Process Manager
• Connectivity functionality
– Function Libraries
• General functions used by all the subsystems
Dept. of Computing Science, University of Aberdeen 5
MySQL Architecture
Operating System
Storage ManagerInnoDB
(transactional)
MyISAM
(default)
Memory
(In-memory)
NDB
(Clustered)
Buffer Manager Transaction Manager
Recovery ManagerQuery Engine
Dept. of Computing Science, University of Aberdeen 6
Query Engine
• Three components
– Syntax parser
• Translates SQL query to an internal form, RAT
• Correctness of the syntax is established
• User privileges are used to verify if the query makes legal
references to tables (or fields)
– Query optimizer
• Selects the most efficient query execution plan
– Execution component
• Executes the query by making calls to other modules
Dept. of Computing Science, University of Aberdeen 7
The Storage Manager
• Responsible for file organization and indexing
• Interfaces with the OS to write to disk all of the data, such as
– User tables, indexes and logs
• The component that makes MySQL special by
– Offering different types of storage engines (or table types)
• Advantages of multiple storage engines
– When new engines are added to the server, the server architecture
allows supporting older file formats
– Changes to storage engines do not cause changes elsewhere in
MySQL
– Different users/applications have a choice in the storage engine
used
– Easier to introduce new storage media (compact flash) which may
require different approach
Dept. of Computing Science, University of Aberdeen 8
Storage Engines
• MyISAM (default)
– extensions to the traditional ISAM
– No support for transactions
– No referential integrity
• InnoDB (Transactional)
– Supports transactions with ‘ACID’ properties
– Supports referential integrity
• Memory (In-memory)
– Tables of this type are stored in RAM; therefore fast
– But data will be lost in the event of a crash
• NDB (Clustered) – advanced storage method - not
here
• You will be using mostly MyISAM or InnoDB
Dept. of Computing Science, University of Aberdeen 9
Buffer Manager
• Manages memory management issues
– Between query engine and memory manager
• Maintains Query Cache which
– Stores the result sets of queries
– Repeated queries are answered directly from query cache
• New records are cached in before being written to
disk
• Query cache is unique to MySQL
• Is responsible for enhanced response times
– Studies show that MySQL works as fast as Oracle and SQL
server (Microsoft’s RDBMS server)
Dept. of Computing Science, University of Aberdeen 10
Recovery Manager
• Performs data recovery in the event of
loss of data
• Different for different storage engines
(or table types)
• InnoDB table provides recovery
management
• MyISAM table provides fixes to data
inconsistencies due to server outage
Dept. of Computing Science, University of Aberdeen 11
Transaction Management
• Performs locking and transaction management
• Different for different storage engines (or
table types)
• InnoDB table supports
– transaction management where transactions obey
‘ACID’ requirements
– row and table level locking
– All isolation levels
• MyISAM table supports
– Table level locking
Dept. of Computing Science, University of Aberdeen 12
Specifying the table type
• When you create a table you can specify the table type (storage
engine) for that table
• For example
CREATE TABLE test (id int(5) Primary Key, name varchar(25)) TYPE =
InnoDB;
• You can alter the type of an existing table to a different type
• For example
ALTER TABLE test TYPE = MyISAM;
• A single MySQL database can have tables of different types
• If you don’t require transactions, it is best to use MyISAM
• You can use SHOW TABLE STATUS to display information
about a table
• For example to display information about table called test
SHOW TABLE STATUS like ‘test’ G
Dept. of Computing Science, University of Aberdeen 13
Performance related issues
• MySQL allows users to ask for information about how their
select queries are processed using EXPLAIN
• EXPLAIN is the command to be added before your select
statement
• For example
mysql> explain select * from client where ClientNo='CR74';
+--------+------+---------------+------+---------+------+------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+------+---------------+------+---------+------+------+-------------+
| client | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
+--------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
Please note that the ‘possible_keys’ field is NULL – which means no index
defined
Please note that the ‘rows’ field is 4 – which means 4 rows (which is all the
rows client table has) which requires examination
Dept. of Computing Science, University of Aberdeen 14
Example continued
• Now add the index to the client table
mysql> alter table client add index(ClientNo);
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0
• Now rerun the previous select query asking for explanation
mysql> explain select * from client where ClientNo='CR74';
+--------+------+---------------+----------+---------+-------+------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+------+---------------+----------+---------+-------+------+-------------+
| client | ref | ClientNo | ClientNo | 6 | const | 1 | Using where |
+--------+------+---------------+----------+---------+-------+------+-------------+
1 row in set (0.00 sec)
•Please note that now only one row needs to be examined and
the query therefore runs faster
•Please also note that this table now has an index
Dept. of Computing Science, University of Aberdeen 15
Further performance
enhancements
• You can improve the performance of your query further by
defining smaller indexes
• In the previous example ClientNo is used as the index
– it is five characters long
– therefore defining only part of the clientNo as the index may not
make much difference
• When longer fields are used as indexes
– It helps to define the index on part of the field (ref: slide 16)
• Query Optimizer in MySQL inspects all the indexes before
selecting one for use in query processing
• You can help MySQL by running the following statement to help
in the process of selecting the correct index
ANALYZE TABLE client;
• You can also instruct MySQL to reclaim space lost due to
deletion of records (holes)
OPTIMIZE TABLE client;
Dept. of Computing Science, University of Aberdeen 16
Example showing the use of
shorter indexes
mysql> explain select * from client where Lname = 'Ritchie';
+--------+------+---------------+------+---------+------+------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+------+---------------+------+---------+------+------+-------------+
| client | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
+--------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> alter table client add index(Lname(3));
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> explain select * from client where Lname = 'Rit';
+--------+------+---------------+-------+---------+-------+------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+------+---------------+-------+---------+-------+------+-------------+
| client | ref | Lname | Lname | 4 | const | 1 | Using where |
+--------+------+---------------+-------+---------+-------+------+-------------+
1 row in set (0.00 sec)

Contenu connexe

Tendances

MySQL DBA OCP 1Z0-883
MySQL DBA OCP 1Z0-883MySQL DBA OCP 1Z0-883
MySQL DBA OCP 1Z0-883Kwaye Kant
 
MonetDB :column-store approach in database
MonetDB :column-store approach in databaseMonetDB :column-store approach in database
MonetDB :column-store approach in databaseNikhil Patteri
 
MySQL and bioinformatics
MySQL and bioinformatics MySQL and bioinformatics
MySQL and bioinformatics Arindam Ghosh
 
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guruIBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guruRavikumar Nandigam
 
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage enginesLearn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage enginesEduonix Learning Solutions
 
MySQL 简要介绍
MySQL 简要介绍MySQL 简要介绍
MySQL 简要介绍YUCHENG HU
 
IBM DB2 LUW/UDB DBA Training by www.etraining.guru
IBM DB2 LUW/UDB DBA Training by www.etraining.guruIBM DB2 LUW/UDB DBA Training by www.etraining.guru
IBM DB2 LUW/UDB DBA Training by www.etraining.guruRavikumar Nandigam
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinStåle Deraas
 

Tendances (13)

MySQL DBA OCP 1Z0-883
MySQL DBA OCP 1Z0-883MySQL DBA OCP 1Z0-883
MySQL DBA OCP 1Z0-883
 
MySQL database
MySQL databaseMySQL database
MySQL database
 
MonetDB :column-store approach in database
MonetDB :column-store approach in databaseMonetDB :column-store approach in database
MonetDB :column-store approach in database
 
MySQL DBA
MySQL DBAMySQL DBA
MySQL DBA
 
Mysql database
Mysql databaseMysql database
Mysql database
 
MySQL and bioinformatics
MySQL and bioinformatics MySQL and bioinformatics
MySQL and bioinformatics
 
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guruIBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
 
MySQL vs MonetDB Bencharmarks
MySQL vs MonetDB BencharmarksMySQL vs MonetDB Bencharmarks
MySQL vs MonetDB Bencharmarks
 
MySQL vs. MonetDB
MySQL vs. MonetDBMySQL vs. MonetDB
MySQL vs. MonetDB
 
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage enginesLearn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
 
MySQL 简要介绍
MySQL 简要介绍MySQL 简要介绍
MySQL 简要介绍
 
IBM DB2 LUW/UDB DBA Training by www.etraining.guru
IBM DB2 LUW/UDB DBA Training by www.etraining.guruIBM DB2 LUW/UDB DBA Training by www.etraining.guru
IBM DB2 LUW/UDB DBA Training by www.etraining.guru
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublin
 

En vedette

Connections II Overview - August 2013 Webinar
Connections II Overview - August 2013 WebinarConnections II Overview - August 2013 Webinar
Connections II Overview - August 2013 WebinarUSGSA
 
Project Bramenvla
Project BramenvlaProject Bramenvla
Project Bramenvlawoosklda
 
Htc one deals ppt 2
Htc one deals ppt 2Htc one deals ppt 2
Htc one deals ppt 2oddysmith
 

En vedette (7)

Glenwood
GlenwoodGlenwood
Glenwood
 
Kortom
KortomKortom
Kortom
 
Connections II Overview - August 2013 Webinar
Connections II Overview - August 2013 WebinarConnections II Overview - August 2013 Webinar
Connections II Overview - August 2013 Webinar
 
Project Bramenvla
Project BramenvlaProject Bramenvla
Project Bramenvla
 
Orcid-nasig-presentation
Orcid-nasig-presentationOrcid-nasig-presentation
Orcid-nasig-presentation
 
Kad English Magazine Issue1
Kad English Magazine Issue1Kad English Magazine Issue1
Kad English Magazine Issue1
 
Htc one deals ppt 2
Htc one deals ppt 2Htc one deals ppt 2
Htc one deals ppt 2
 

Similaire à My sql

Collaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsCollaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsNelson Calero
 
My sql introduction for Bestcom
My sql introduction for BestcomMy sql introduction for Bestcom
My sql introduction for BestcomIvan Tu
 
My S Q L Introduction for 1 day training
My S Q L  Introduction for 1 day trainingMy S Q L  Introduction for 1 day training
My S Q L Introduction for 1 day trainingIvan Tu
 
Microsoft sql server database administration
Microsoft sql server database administrationMicrosoft sql server database administration
Microsoft sql server database administrationRahul Singh
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMahesh Salaria
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerIDERA Software
 
MariaDB ColumnStore
MariaDB ColumnStoreMariaDB ColumnStore
MariaDB ColumnStoreMariaDB plc
 
Database Systems Design, Implementation, and Management
Database Systems Design, Implementation, and ManagementDatabase Systems Design, Implementation, and Management
Database Systems Design, Implementation, and ManagementOllieShoresna
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manualMir Majid
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsTuyen Vuong
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)Gustavo Rene Antunez
 
MariaDB 10 Tutorial - 13.11.11 - Percona Live London
MariaDB 10 Tutorial - 13.11.11 - Percona Live LondonMariaDB 10 Tutorial - 13.11.11 - Percona Live London
MariaDB 10 Tutorial - 13.11.11 - Percona Live LondonIvan Zoratti
 
Designing, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons LearnedDesigning, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons LearnedDenny Lee
 
Data Warehouse Logical Design using Mysql
Data Warehouse Logical Design using MysqlData Warehouse Logical Design using Mysql
Data Warehouse Logical Design using MysqlHAFIZ Islam
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Antonios Chatzipavlis
 

Similaire à My sql (20)

Collaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsCollaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAs
 
Fudcon talk.ppt
Fudcon talk.pptFudcon talk.ppt
Fudcon talk.ppt
 
My sql introduction for Bestcom
My sql introduction for BestcomMy sql introduction for Bestcom
My sql introduction for Bestcom
 
My S Q L Introduction for 1 day training
My S Q L  Introduction for 1 day trainingMy S Q L  Introduction for 1 day training
My S Q L Introduction for 1 day training
 
Microsoft sql server database administration
Microsoft sql server database administrationMicrosoft sql server database administration
Microsoft sql server database administration
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source Database
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
 
Sql Server2008
Sql Server2008Sql Server2008
Sql Server2008
 
MariaDB ColumnStore
MariaDB ColumnStoreMariaDB ColumnStore
MariaDB ColumnStore
 
Database Systems Design, Implementation, and Management
Database Systems Design, Implementation, and ManagementDatabase Systems Design, Implementation, and Management
Database Systems Design, Implementation, and Management
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manual
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and Concepts
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)
 
MariaDB 10 Tutorial - 13.11.11 - Percona Live London
MariaDB 10 Tutorial - 13.11.11 - Percona Live LondonMariaDB 10 Tutorial - 13.11.11 - Percona Live London
MariaDB 10 Tutorial - 13.11.11 - Percona Live London
 
Designing, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons LearnedDesigning, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons Learned
 
Nosql data models
Nosql data modelsNosql data models
Nosql data models
 
Data Warehouse Logical Design using Mysql
Data Warehouse Logical Design using MysqlData Warehouse Logical Design using Mysql
Data Warehouse Logical Design using Mysql
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
 

Dernier

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

My sql

  • 2. Dept. of Computing Science, University of Aberdeen 2 In this lecture you will learn • The main subsystems in MySQL architecture • The different storage engines or table types in MySQL • How you can define the storage engine or table type to be used for your tables • How you can improve the performance of your queries
  • 3. Dept. of Computing Science, University of Aberdeen 3 Introduction • MySQL is an open source RDBMS • Main Features – Server-client architecture – Available for a variety of platforms including Windows and Linux – Multiple storage engines • Users/applications can select the storage engine for their database – Based on their requirements • Can even mix and match different engines within the same database – Supports ANSI SQL – Version 5.0 is the current stable release – Version 5.0 supports certain spatial data types
  • 4. Dept. of Computing Science, University of Aberdeen 4 MySQL Architecture • Primary subsystems – The Query Engine – The Storage Manager – The Buffer Manager – The Transaction Manager – The Recovery Manager • Support components – The Process Manager • Connectivity functionality – Function Libraries • General functions used by all the subsystems
  • 5. Dept. of Computing Science, University of Aberdeen 5 MySQL Architecture Operating System Storage ManagerInnoDB (transactional) MyISAM (default) Memory (In-memory) NDB (Clustered) Buffer Manager Transaction Manager Recovery ManagerQuery Engine
  • 6. Dept. of Computing Science, University of Aberdeen 6 Query Engine • Three components – Syntax parser • Translates SQL query to an internal form, RAT • Correctness of the syntax is established • User privileges are used to verify if the query makes legal references to tables (or fields) – Query optimizer • Selects the most efficient query execution plan – Execution component • Executes the query by making calls to other modules
  • 7. Dept. of Computing Science, University of Aberdeen 7 The Storage Manager • Responsible for file organization and indexing • Interfaces with the OS to write to disk all of the data, such as – User tables, indexes and logs • The component that makes MySQL special by – Offering different types of storage engines (or table types) • Advantages of multiple storage engines – When new engines are added to the server, the server architecture allows supporting older file formats – Changes to storage engines do not cause changes elsewhere in MySQL – Different users/applications have a choice in the storage engine used – Easier to introduce new storage media (compact flash) which may require different approach
  • 8. Dept. of Computing Science, University of Aberdeen 8 Storage Engines • MyISAM (default) – extensions to the traditional ISAM – No support for transactions – No referential integrity • InnoDB (Transactional) – Supports transactions with ‘ACID’ properties – Supports referential integrity • Memory (In-memory) – Tables of this type are stored in RAM; therefore fast – But data will be lost in the event of a crash • NDB (Clustered) – advanced storage method - not here • You will be using mostly MyISAM or InnoDB
  • 9. Dept. of Computing Science, University of Aberdeen 9 Buffer Manager • Manages memory management issues – Between query engine and memory manager • Maintains Query Cache which – Stores the result sets of queries – Repeated queries are answered directly from query cache • New records are cached in before being written to disk • Query cache is unique to MySQL • Is responsible for enhanced response times – Studies show that MySQL works as fast as Oracle and SQL server (Microsoft’s RDBMS server)
  • 10. Dept. of Computing Science, University of Aberdeen 10 Recovery Manager • Performs data recovery in the event of loss of data • Different for different storage engines (or table types) • InnoDB table provides recovery management • MyISAM table provides fixes to data inconsistencies due to server outage
  • 11. Dept. of Computing Science, University of Aberdeen 11 Transaction Management • Performs locking and transaction management • Different for different storage engines (or table types) • InnoDB table supports – transaction management where transactions obey ‘ACID’ requirements – row and table level locking – All isolation levels • MyISAM table supports – Table level locking
  • 12. Dept. of Computing Science, University of Aberdeen 12 Specifying the table type • When you create a table you can specify the table type (storage engine) for that table • For example CREATE TABLE test (id int(5) Primary Key, name varchar(25)) TYPE = InnoDB; • You can alter the type of an existing table to a different type • For example ALTER TABLE test TYPE = MyISAM; • A single MySQL database can have tables of different types • If you don’t require transactions, it is best to use MyISAM • You can use SHOW TABLE STATUS to display information about a table • For example to display information about table called test SHOW TABLE STATUS like ‘test’ G
  • 13. Dept. of Computing Science, University of Aberdeen 13 Performance related issues • MySQL allows users to ask for information about how their select queries are processed using EXPLAIN • EXPLAIN is the command to be added before your select statement • For example mysql> explain select * from client where ClientNo='CR74'; +--------+------+---------------+------+---------+------+------+-------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +--------+------+---------------+------+---------+------+------+-------------+ | client | ALL | NULL | NULL | NULL | NULL | 4 | Using where | +--------+------+---------------+------+---------+------+------+-------------+ 1 row in set (0.00 sec) Please note that the ‘possible_keys’ field is NULL – which means no index defined Please note that the ‘rows’ field is 4 – which means 4 rows (which is all the rows client table has) which requires examination
  • 14. Dept. of Computing Science, University of Aberdeen 14 Example continued • Now add the index to the client table mysql> alter table client add index(ClientNo); Query OK, 4 rows affected (0.05 sec) Records: 4 Duplicates: 0 Warnings: 0 • Now rerun the previous select query asking for explanation mysql> explain select * from client where ClientNo='CR74'; +--------+------+---------------+----------+---------+-------+------+-------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +--------+------+---------------+----------+---------+-------+------+-------------+ | client | ref | ClientNo | ClientNo | 6 | const | 1 | Using where | +--------+------+---------------+----------+---------+-------+------+-------------+ 1 row in set (0.00 sec) •Please note that now only one row needs to be examined and the query therefore runs faster •Please also note that this table now has an index
  • 15. Dept. of Computing Science, University of Aberdeen 15 Further performance enhancements • You can improve the performance of your query further by defining smaller indexes • In the previous example ClientNo is used as the index – it is five characters long – therefore defining only part of the clientNo as the index may not make much difference • When longer fields are used as indexes – It helps to define the index on part of the field (ref: slide 16) • Query Optimizer in MySQL inspects all the indexes before selecting one for use in query processing • You can help MySQL by running the following statement to help in the process of selecting the correct index ANALYZE TABLE client; • You can also instruct MySQL to reclaim space lost due to deletion of records (holes) OPTIMIZE TABLE client;
  • 16. Dept. of Computing Science, University of Aberdeen 16 Example showing the use of shorter indexes mysql> explain select * from client where Lname = 'Ritchie'; +--------+------+---------------+------+---------+------+------+-------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +--------+------+---------------+------+---------+------+------+-------------+ | client | ALL | NULL | NULL | NULL | NULL | 4 | Using where | +--------+------+---------------+------+---------+------+------+-------------+ 1 row in set (0.00 sec) mysql> alter table client add index(Lname(3)); Query OK, 4 rows affected (0.03 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> explain select * from client where Lname = 'Rit'; +--------+------+---------------+-------+---------+-------+------+-------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +--------+------+---------------+-------+---------+-------+------+-------------+ | client | ref | Lname | Lname | 4 | const | 1 | Using where | +--------+------+---------------+-------+---------+-------+------+-------------+ 1 row in set (0.00 sec)