Rechercher dans le manuel MySQL

13.3.7 SET TRANSACTION Syntax

  1.     transaction_characteristic [, transaction_characteristic] ...
  2.  
  3. transaction_characteristic: {
  4.     ISOLATION LEVEL level
  5.   | access_mode
  6. }
  7.  
  8. level: {
  9. }
  10.  
  11. access_mode: {
  12.      READ WRITE
  13.    | READ ONLY
  14. }

This statement specifies transaction characteristics. It takes a list of one or more characteristic values separated by commas. Each characteristic value sets the transaction isolation level or access mode. The isolation level is used for operations on InnoDB tables. The access mode specifies whether transactions operate in read/write or read-only mode.

In addition, SET TRANSACTION can include an optional GLOBAL or SESSION keyword to indicate the scope of the statement.

Transaction Isolation Levels

To set the transaction isolation level, use an ISOLATION LEVEL level clause. It is not permitted to specify multiple ISOLATION LEVEL clauses in the same SET TRANSACTION statement.

The default isolation level is REPEATABLE READ. Other permitted values are READ COMMITTED, READ UNCOMMITTED, and SERIALIZABLE. For information about these isolation levels, see Section 15.7.2.1, “Transaction Isolation Levels”.

Inhoudsopgave Haut

Transaction Access Mode

To set the transaction access mode, use a READ WRITE or READ ONLY clause. It is not permitted to specify multiple access-mode clauses in the same SET TRANSACTION statement.

By default, a transaction takes place in read/write mode, with both reads and writes permitted to tables used in the transaction. This mode may be specified explicitly using SET TRANSACTION with an access mode of READ WRITE.

If the transaction access mode is set to READ ONLY, changes to tables are prohibited. This may enable storage engines to make performance improvements that are possible when writes are not permitted.

In read-only mode, it remains possible to change tables created with the TEMPORARY keyword using DML statements. Changes made with DDL statements are not permitted, just as with permanent tables.

The READ WRITE and READ ONLY access modes also may be specified for an individual transaction using the START TRANSACTION statement.

Inhoudsopgave Haut

Transaction Characteristic Scope

You can set transaction characteristics globally, for the current session, or for the next transaction only:

  • With the GLOBAL keyword:

    • The statement applies globally for all subsequent sessions.

    • Existing sessions are unaffected.

  • With the SESSION keyword:

    • The statement applies to all subsequent transactions performed within the current session.

    • The statement is permitted within transactions, but does not affect the current ongoing transaction.

    • If executed between transactions, the statement overrides any preceding statement that sets the next-transaction value of the named characteristics.

  • Without any SESSION or GLOBAL keyword:

    • The statement applies only to the next single transaction performed within the session.

    • Subsequent transactions revert to using the session value of the named characteristics.

    • The statement is not permitted within transactions:

      1. Query OK, 0 rows affected (0.02 sec)
      2.  
      3. ERROR 1568 (25001): Transaction characteristics can't be changed
      4. while a transaction is in progress

A change to global transaction characteristics requires the CONNECTION_ADMIN or SUPER privilege. Any session is free to change its session characteristics (even in the middle of a transaction), or the characteristics for its next transaction (prior to the start of that transaction).

To set the global isolation level at server startup, use the --transaction-isolation=level option on the command line or in an option file. Values of level for this option use dashes rather than spaces, so the permissible values are READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, or SERIALIZABLE.

Similarly, to set the global transaction access mode at server startup, use the --transaction-read-only option. The default is OFF (read/write mode) but the value can be set to ON for a mode of read only.

For example, to set the isolation level to REPEATABLE READ and the access mode to READ WRITE, use these lines in the [mysqld] section of an option file:

[mysqld]
transaction-isolation = REPEATABLE-READ
transaction-read-only = OFF

At runtime, characteristics at the global, session, and next-transaction scope levels can be set indirectly using the SET TRANSACTION statement, as described previously. They can also be set directly using the SET statement to assign values to the transaction_isolation and transaction_read_only system variables:

  • SET TRANSACTION permits optional GLOBAL and SESSION keywords for setting transaction characteristics at different scope levels.

  • The SET statement for assigning values to the transaction_isolation and transaction_read_only system variables has syntaxes for setting these variables at different scope levels.

The following tables show the characteristic scope level set by each SET TRANSACTION and variable-assignment syntax.

Table 13.9 SET TRANSACTION Syntax for Transaction Characteristics

Syntax Affected Characteristic Scope
SET GLOBAL TRANSACTION transaction_characteristic Global
SET SESSION TRANSACTION transaction_characteristic Session
SET TRANSACTION transaction_characteristic Next transaction only

Table 13.10 SET Syntax for Transaction Characteristics

Syntax Affected Characteristic Scope
SET GLOBAL var_name = value Global
SET @@GLOBAL.var_name = value Global
SET PERSIST var_name = value Global
SET @@PERSIST.var_name = value Global
SET PERSIST_ONLY var_name = value No runtime effect
SET @@PERSIST_ONLY.var_name = value No runtime effect
SET SESSION var_name = value Session
SET @@SESSION.var_name = value Session
SET var_name = value Session
SET @@var_name = value Next transaction only

It is possible to check the global and session values of transaction characteristics at runtime:

  1. SELECT @@GLOBAL.transaction_isolation, @@GLOBAL.transaction_read_only;
  2. SELECT @@SESSION.transaction_isolation, @@SESSION.transaction_read_only;

Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-set-transaction.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut