Upload
remote-mysql-dba
View
218
Download
0
Embed Size (px)
Citation preview
7/21/2019 9)Locking in Mysql
1/15
MySQL LOCKING
7/21/2019 9)Locking in Mysql
2/15
Ajenda
Locking in MySQL
Internal Locking
Table level Locking
Row level Locking
External Locking
Dead Lock
7/21/2019 9)Locking in Mysql
3/15
About Us
Karthik.P.R, Senior MySQL DBA,
Bharath Kumar.P, MySQL DBA
Blog : remotemysqldba.blogspot.in
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
4/15
Remotemysqldba.blogspot.in
Locking In MySQL
It places a lock on data on behalf of one client to restrict access by other clients to the
data until the lock has been released.
The effect of locking is to serialize access to
data so that when multiple clients want to perform
conflicting operations, each must wait its turn.
The locks are needed as the data is read / write by
multiple sessions are users.
To reduce the contention of queries waiting for a single resource locking is needed.
To overcome the contention . MySQL has two type of locks namely
1) Internal Locking.
2) External Locking.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
5/15
Remotemysqldba.blogspot.in
Internal Locking
Internal Locking:
It is performed inside the server itself to avoid the contention by multiple
threads. It does not involve any programs.
Internal Locking Types:
The internal locking is of two types namely .
a) Table level locking
b) Row level locking
The internal locking is maintained within the mysql itself. It helps in managing
the contention between the connections.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
6/15
Remotemysqldba.blogspot.in
Table level Locking
MyISAM , memory and Merge engine uses the table level locking.
The table level locking is dead lock free .
Web application that needs more selects with few inserts and deletes to a few
specific tables.
MyISAM is tuned for this type of web applications.
Advantages
- It good for making many selects .
- Uses less resource while comparing to Row-level-locking
- Dead lock free.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
7/15Remotemysqldba.blogspot.in
Table level Locking
Disadvantages
- Cannot be used in transaction .
- It causes the delay in the update statements if the tables are huge
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
8/15Remotemysqldba.blogspot.in
Table level Locking
Read locks and write locks occurs in mysql.
When a read lock is acquired on the table , other connections can also
make the select on the table.
If write lock is acquired on the table. Only one connection can make the
Write operation ( update, delete ) on the table.
The update queries have the high priority while comparing to the select
queries.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
9/15Remotemysqldba.blogspot.in
Table level Locking
The locking contention can be monitored using the status variables .
table_locks_immediate
table_locks_waited
Table_locks_immediate : The number of locks that are granted immediately on
the request for it.
Table_locks_waited : The number of locks that are granted after waiting .
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
10/15Remotemysqldba.blogspot.in
Row level locking
The row level locking is the characteristic feature of the InnoDB/XtraDB
storage engine.
It locks only the selected range of rows.
The locking of the rows depend on the where clause of the query.
Advantages :
-Supports the transaction.
-A few conflict occurs.
-Possible to lock single row for a long time.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
11/15Remotemysqldba.blogspot.in
Row level locking
Disadvantages :
-Consumes more system resource .
-Slower when a larger part of the table is locked.
-Dead locks occurs.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
12/15Remotemysqldba.blogspot.in
External Locking
External locking is the use of file system locking to manage contention for
MyISAM database tables by multiple processes.
External locking is used in situations where a single process such as the
MySQL server cannot be assumed to be the only process that requires access
to tables.
If you run multiple servers that use the same database directory (not
recommended), each server must have external locking enabled.
External locking affects server performance because the server must
sometimes wait for other processes before it can access tables.
External locking is unnecessary if you run a single server to access a given
data directory.
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
13/15Remotemysqldba.blogspot.in
Dead Lock
Dead is a situation in which two or more competing actions are each
waiting for the other to finish, and thus neither ever does.
A condition that occurs when twoprocesses are each waiting for the
other to complete before proceeding. The result is that both
processes hang. Deadlocks occur most commonly
in multitaskingand client/serverenvironments. Ideally, the programs
that are deadlocked.
Two transaction waiting for a rows which are locked by each other .
http://remotemysqldba.blogspot.in/http://www.webopedia.com/TERM/P/process.htmlhttp://www.webopedia.com/TERM/H/hang.htmlhttp://www.webopedia.com/TERM/M/multitasking.htmlhttp://www.webopedia.com/TERM/C/client_server_architecture.htmlhttp://www.webopedia.com/TERM/C/client_server_architecture.htmlhttp://www.webopedia.com/TERM/M/multitasking.htmlhttp://www.webopedia.com/TERM/H/hang.htmlhttp://www.webopedia.com/TERM/P/process.htmlhttp://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
14/15Remotemysqldba.blogspot.in
Dead Locking
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/7/21/2019 9)Locking in Mysql
15/15Remotemysqldba.blogspot.in
THANK YOU
http://remotemysqldba.blogspot.in/http://remotemysqldba.blogspot.in/