I have a problem with MySQL workbench 6.0 CE, I will describe it the most explained possible:
MySQL Workbench always set my session variable ##tx_isolation to "REPEATABLE READ" and the only way to change this variable is using SET tx_isolation='READ-COMMITTED';.
What I want is that when I launch workbench the default session variable for tx_isolation is 'READ-COMMITTED' and not 'REPEATABLE-READ'; yes, I've changed the global variable tx_isolation and it's 'READ-COMMITTED' but session one is not.
Ej:
SELECT ##Global.tx_isolation, ##tx_isolation;
returns: 'READ-COMMITTED', 'REPEATABLE-READ' respectively.
Note: If I query the same code as above in MySQL command line, both variables are set to 'READ-COMMITTED', that's why I think it's a problem with MySQL Workbench and not the server.
Thanks for the help.
This is an old question, but still I have the same bug.
According to doc (https://dev.mysql.com/doc/refman/5.7/en/innodb-transaction-isolation-levels.html#isolevel_repeatable-read), Default Isolation Level is REPEATABLE-READ.
This mean that a snapshot of the database is made on the FIRST read of the transaction. Every other read of this transaction will show you the data of the snapshot.
So you need to end the transaction (commit or roll-back) to get a new snapshot on the next read.
My colleagues who set MySQL Workbench on AutoCommit don't see the repeatable-read behaviour. We figured out it's because after each SELECT, the transaction is closed and a new snapshot is created.
So, as the bug is still not corrected (as Sithsu mentionned), a workaround would be :
switch to autocommit for new snapshots to be automatically created
or commit/rollback after each SELECT to create a new snapshot
Related
I am facing a problem where I am trying to add data from a python script to mysql database with InnonDB engine, it works fine with myisam engine of the mysql database. But the problem with the myisam engine is that it doesn't support foreign keys so I'll have to add extra code each place where I want to insert/delete records in database.
Does anyone know why InnonDB doesn't work with python scripts and possible solutions for this problem ??
InnoDB is transactional. You need to call connection.commit() after inserts/deletes/updates.
Edit: you can call connection.autocommit(True) to turn on autocommit.
Python DB API disables autocommit by default
Pasted from google (first page, 2nd result)
MySQL :: MySQL 5.0 Reference Manual :: 13.2.8 The InnoDB ...
By default, MySQL starts the session for each new connection with autocommit ...
dev.mysql.com/.../innodb-transaction-model.html
However
Apparently Python starts MySQL in NON-autocommit mode, see:
http://www.kitebird.com/articles/pydbapi.html
From the article:
The connection object commit() method commits any outstanding changes in the current transaction to make them permanent in the database. In DB-API, connections begin with autocommit mode disabled, so you must call commit() before disconnecting or changes may be lost.
Bummer, dunno how to override that and I don't want to lead you astray by guessing.
I would suggest opening a new question titled:
How to enable autocommit mode in MySQL python DB-API?
Good luck.
On Linux, I thought my MySQL queries were somehow not working, because a query would not show any progress in the amount of data being entered into a table. Is there a way the data available to the MySQL command line can be refreshed without exiting and re-entering the command line?
I have been searching around, but so far have only seen running mysql -e and putting that into a bash loop. I like to stay in the MySQL command line and run other commands like describe tables.
What you're seeing is probably the result of a long-running REPEATABLE-READ transaction. Until you begin a new transaction, you can see only data that was committed at the time you started your current transaction.
Normally, the mysql client operates in autocommit mode. That is, every SQL statement implicitly starts and commits its own transaction. In this mode, you should always see current data every time you query. You apparently are not using autocommit mode.
You can turn on autocommit:
mysql> SET SESSION autocommit=1;
Or you can start a new transaction at your convenience:
mysql> BEGIN;
Another option is to operate within a READ-COMMITTED transaction. This means your transaction does not need to preserve a repeatable view of data from the time you started your transaction. It always views the most recently committed changes, even while your transaction is ongoing.
mysql> SET SESSION tx_isolation='READ-COMMITTED';
mysql> BEGIN;
(Note: MySQL 8.0.3 changed the name of tx_isolation to transaction_isolation.)
The link #JimmyB posted in a comment above about transaction isolation levels is helpful reading.
We have been seeing a lot of errors recently:
ActiveRecord::TransactionIsolationConflict: Transaction isolation conflict detected: Lock wait timeout exceeded; try restarting transaction
Not able to figure out the reasoning behind it. But noticed one thing in our code which is trying to lock a record outside transaction:
acc = Account.lock.find acc_id
Above code is not inside any transaction and is used just to check that the other transaction which also obtains the same lock is finished or not. Any thoughts on if this can be the culprit ?
The InnoDB use row level locking for better concurrency when huge write load. Engine takes some precautions to get rid of phantom reads, one of these is gap_lock, which may be causing this problem. Use
SHOW ENGINE INNODB STATUS
to analyze about gap_lock.
If this is proble, you can try following options
Change the ISOLATION level to READ COMMITTED.
set innodb_locks_unsafe_for_binlog = 1. This will disables the gap locks except for foreign-key constraint checking or duplicate-key checking.
Use show innodb status again to analyse what is going on. If required optimise your code to avoid locking
If above does not work, try to increase lock_wait_timeout globally
SET GLOBAL innodb_lock_wait_timeout = 120;
Or for a session
SET innodb_lock_wait_timeout = 120;
Check your config again, if still not updated then set again global variables
show variables like '%wait_timeout%';
show variables like '%tx_isolation%';
SELECT ##GLOBAL.tx_isolation, ##tx_isolation;
Please check what is being configured on your MySQL server for innodb_lock_wait_timeout and lock_wait_timeout.
You can do this by running the following command
show global variables like '%lock_wait_timeout';
Which of those parameters is in use depends on your version of MySQL and the engine of the table
from the documentation:
# select * from accounts where id=1 for update
Account.lock.find(1)
for update means - acquire a lock for write.
Probably your transaction takes more time than configured on your DB, and the checking request that tries to verify the original transaction was finished - getting this error as the time for waiting runs out.
I am using toad for mysql, but when I try to execute update the simple statement like
UPDATE CART SET AID = 10005 WHERE ID = 10007; it show me the error:
Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and
at least one table uses a storage engine limited to row-based logging.
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
But the weird thing is it's working well in web application and other tools like HeidiSQL, Oracle sqldeveloper.
Any one knows about this? is there any configuration of Toad for Mysql? thanks a lot.
Execute the following before your update statement:
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITED
We just switched our MySQL database from MyIsam to Innodb, and we are seeing an odd issue arise in Django. Whenever we make a database transaction, the existing sessions do not pick it up...ever. We can see the new record in the database from a mysql terminal, but the existing django sessions (ie a shell that was already open), would not register the change. For example:
Shell 1:
>>> my_obj = MyObj.objects.create(foo="bar")
>>> my_obj.pk
1
Shell 2 (was open before the above)
>>> my_obj = MyObj.objects.filter(pk=1)
[]
Shell 3 (MySQL):
mysql> select id from myapp_my_obj where id = 1;
id
1
Does anyone know why this might be happening?
EDIT: To clarify, Shell 2 was opened before Shell 1, then I make the create Shell 1, then I try to view the object that I created in Shell 2.
EDIT2: The big picture is that I have a celery task that is being passed the primary key from the object that is created. When I was using MyISAM, it found it every time, and now it throws ObjectDoesNotExist, even though I can see that the object is created in the database.
Your create() command commits the transaction for the current shell, but doesn't do anything to the transaction in the second shell.
https://docs.djangoproject.com/en/dev/topics/db/transactions/
Your second thread that can't see what's done in the first because it is in a transaction of its own. Transactions isolate the database so that when a transaction is committed, everything happens at a single point in time, including select statements. This is the A in ACID. Try running
from django.db import transaction; transaction.commit()
in the second shell. That should commit the current transaction and start a new one. You can also use transaction.rollback() to acheive the same thing if you haven't modified anything in the db in the current shell.
Edit Edit:
You may need to grab your specific db connection to make this work. Try this:
import django.db
django.db.connection._commit()
More information about this problem here:
http://groups.google.com/group/django-users/msg/55fa3724d2754013
The relevant bit is:
If you want script1.py (using an InnoDB table) to see committed updates from
other transactions you can change the transaction isolation level like so:
from django.db import connection
connection.cursor().execute('set transaction isolation level read
committed')
Alternatively you can enable the database's version of auto-commit, which
"commits" queries as well as updates, so that each new query by script1 will
be in its own transaction:
connection.cursor().execute('set autocommit=1')
Either one allows script1 to see script2's updates.
So, the tl;dr is that you need to set your InnoDB transaction isolation to READ-COMMITTED.