SlideShare ist ein Scribd-Unternehmen logo
1 von 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)

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

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)