473,503 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InnoDB autocommit and locks

Hello,

I have 2 questions regarding InnoDB tables:

1. In the MySQL manual, it states that
"MySQL begins each client connection with autocommit mode enabled by
default. When autocommit is enabled, MySQL does a commit after each SQL
statement if that statement did not return an error."

Does using BEGIN override this behavior? In other words, with
autocommit on, does BEGIN open up a new transaction and stop committing
until an explicit COMMIT command? Or do I need to turn autocommit off
before multi-query transactions?

2. I have been reading the examples for LOCK IN SHARE MODE and FOR
UPDATE in the manual, but I am still confused as to when I should use
one as opposed to the other. I have gone through tutorials but many
just use the same examples as the manual. I'm sure I'm just missing
something small, but if someone could give a simple example of the
difference between the two, that would be very helpful as the difference
to me seems very suttle.

Thanks in advance.
Jul 17 '05 #1
1 3619
Marcus wrote:
Hello,

I have 2 questions regarding InnoDB tables:

1. In the MySQL manual, it states that
"MySQL begins each client connection with autocommit mode enabled by
default. When autocommit is enabled, MySQL does a commit after each SQL
statement if that statement did not return an error."

Does using BEGIN override this behavior? In other words, with
autocommit on, does BEGIN open up a new transaction and stop committing
until an explicit COMMIT command? Or do I need to turn autocommit off
before multi-query transactions?
Perhaps you are looking in another manual. The official online manual is
rather clear on that.
http://dev.mysql.com/doc/mysql/en/in...utocommit.html
[quote]
If the connection has autocommit enabled, the user can still perform a
multiple-statement transaction by starting it with an explicit START
TRANSACTION or BEGIN statement and ending it with COMMIT or ROLLBACK.
[end quote]

So, yes, yes and no.

2. I have been reading the examples for LOCK IN SHARE MODE and FOR
UPDATE in the manual, but I am still confused as to when I should use
one as opposed to the other. I have gone through tutorials but many
just use the same examples as the manual. I'm sure I'm just missing
something small, but if someone could give a simple example of the
difference between the two, that would be very helpful as the difference
to me seems very suttle.


Not sure what examples would be better than the ones in the manual, they
are probably as good as they get. I assume you read this page:
http://dev.mysql.com/doc/mysql/en/in...ing-reads.html

It is not the real/whole story, but perhaps it is easier if you see it
like:..
"FOR UPDATE" is used when you have the intention of updating the rows in
the table you select from, and "LOCK IN SHARE MODE" is used when they
(the selected rows) just are needed for an update elsewhere, and reading
can be shared by many.
/Bent
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1699
by: Marc Slemko | last post by:
Suppose I have an innodb table in 4.0.14 and do: LOCK TABLE maggie INSERT INTO maggie values(123, 'simpson'); UNLOCK TABLES As soon as I issue LOCK TABLE, any transaction in progress is...
0
3209
by: Steve McWilliams | last post by:
Hello, I am relatively new to MySql (4.0.14) but I have read through the relevent documentation and am still confused about how row level locking behaves with InnoDB tables. I created a...
3
949
by: Andy Tran | last post by:
I built a system using mysql innodb to archive SMS messages but the innodb databases are not keeping up with the number of SMS messages coming in. I'm looking for performance of 200 msgs/sec where...
1
5523
by: Rajesh Kapur | last post by:
Hello, We are on MySQL 4.0.21 on linux. We use InnoDB tables and foreign key constraints extensively. The mysqldump backs up the database tables in alphabetical order with foreign key...
2
3511
by: Alex | last post by:
I was hoping someone could confirm my understanding of how InnoDB handles deadlocks (error 1213) and timeouts (error 1206). The way I understand it, with AUTOCOMMIT=0, if I issue 3 SQL statements...
0
2294
by: shakahshakah | last post by:
Just started investigating InnoDB after having used MyISAM tables in the 4.0.12 version, almost immediately ran into a locking issue with INSERTs, DELETEs, and transactions. Given the following...
0
1416
by: Kevin Edwards | last post by:
Hi, all Running a query via Command Editor from a DB2UDB V8 Windows2000 client, if I cancel the executing query the query seems to just carry on anyway (unlike Command Center which used to...
1
1501
by: fjm | last post by:
Hi all, I have a question regarding php and mysql. What I have is a php backup script that dumps the data in the form of INSERT INTO ... I am using innodb and foreign key constraints. When...
0
2686
by: Caper | last post by:
Hello everyone, I am a bit confused about Innodb deadlock and the "SELECT…FOR UPDATE” statement. 1. Here is a deadlock example 1) Create actor table CREATE TABLE actor(actor_id INT...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.