Skip to main content

Turn off Auto commit in MySql

What is auto commit in mysql: 

When we run DML query in mysql for example we have insert any value into table or update value in table, after each DML statement mysql auto commits the changes by default, that means we cannot rollback the changes we have made. This is called auto commit functionality.

To prevent that we can stop this "auto commit" in mysql in following ways:

Permanent Turing off of auto commit:
Open /etc/mysql/my.cnf file in linux environment using sudo privileges as:

$> sudo gedit /etc/mysql/my.cnf 

and type the following lines in bottom of the file and save it.

[client]
init-command='set autocommit=0'
then restart mysql using following command:

$> sudo service mysql restart


Session wise Turing off auto commit:

type the below command in mysql promt:

mysql > set autocommit=0;

And then if you do below operation then you can realize how changes are not getting persistent:

mysql> select * from student ;
+----+------+
| id | name |
+----+------+
|  1 | Amit |
|  2 | Smit |
|  3 | Lmit |
|  4 | Dmit |
+----+------+

mysql> insert into student values(5,'Cmit');
mysql> rollback;
mysql> select * from student ;
+----+------+
| id | name |
+----+------+
|  1 | Amit |
|  2 | Smit |
|  3 | Lmit |
|  4 | Dmit |
+----+------+


But if you run the following sql:

mysql> select * from student ;
+----+------+
| id | name |
+----+------+
|  1 | Amit |
|  2 | Smit |
|  3 | Lmit |
|  4 | Dmit |
+----+------+

mysql> insert into student values(5,'Cmit');
mysql> commit;
mysql> select * from student ;
+----+------+
| id | name |
+----+------+
|  1 | Amit |
|  2 | Smit |
|  3 | Lmit |
|  4 | Dmit |
|  5 | Cmit |
+----+------+

Comments

Popular posts from this blog

Goodness of Fit Test for normal and poisson distribution

Meaning of Goodness of fit test: We find out which distribution fits the sample data the most. And this is achieved using chi-square distribution (Snedecor and Cochran, 1989). How to apply: There are 4 steps to follow: State the hypothesis:  Data follows a distribution or not Criteria to reject null hypothesis: if Χ 2  > Χ 2 (k,1-α) then reject null hypothesis. Analyze sample data: Compute the chi-square value using below formula: ∑(Oi- Ei) 2 /Ei        : Oi is observed frequency and Ei is expected frequency Interpret the results: Declare the results after comparing the values of Χ 2 and Χ 2 (k,1-α), where k is degree of freedom and  α is significance level. Degree of Freedom: It is  =  n - 1 - m m: number of parameter in the distribution. So in case of normal distribution m is 2 ( μ ,α) and in case of poisson dist. m is = 1 ( λ). Example 1: Goodness of fit test for Normal Distribution Year wise data is given about number of car accidents, find out w

classification of database indexing

Dense Index: For every records we are having one entry in the index file. Sparse Index: Only one record for each block we will have it in the index file. Primary Index ( Primary Key + Ordered Data )  A primary index is an ordered file whose records are fixed length size with 2 fields. First field is same as primary key and the second field is pointer to the data block.  Here index entry is created for first record of each block, called ‘block anchor’. Number of index entries thus are equal to number of blocks Average number of block accesses are = logB (worst case) + 1 (best case),  So on average it will be O(logB) The type of index is called sparse index because index is not created for all the records, only the first records of every block the entry is made into the index file. Example on Primary Index Number of Records = 30000, Block Size = 1024 Bytes, Strategy = Unspanned, Record Size = 100 Bytes, Key Size = 6 Bytes, Pointer Size = 9 Bytes, Then find avera

Red Black Tree Insertion in Java

Red Black Tree is a binary search tree. With extra property with each node having color either RED or BLACK. It has following properties: Every node is either RED or BLACK Root element will have BLACK color. Every RED node has BLACK children. Every path from root to leaf will have same number of BLACK nodes. We have few theorems over RB tree: Note: Height of RB tree is θ(logn). Insertion: Insertion in RB tree is little tricky as compared to BST, we have following cases to insert a node in RB tree: When tree is null just insert the node and it will be root, color will be BLACK. To insert an element first find its position: if key <= node.key then move to left else move to right Once we find the correct place to insert, we insert the node with color RED. But if the parent of the node just inserted has color RED then it will violate 3 property. So we have to fix this issue. We call it double RED problem, we resolve it using following few cases. DOUBLE R