Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Not a Bug
-
Affects Version/s: 5.5.30
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:gentoo 64-bit, python with MySQLdb module
Description
If you truncate a table, then repopulate that table and disconnect from db, the data in this table is lost.
I've attached a python script which demonstrates this behavior. The steps involved in the script:
1. drop existing test_mariadb table
2. create test_mariadb table and populate with zeros in each field
3. truncate test_mariadb table
4. repopulate test_mariadb table with ones
5. close connection
6. reopen connection
7. select and print table data, which shows an empty set
This same script run on a mysql server ultimately returns a populated set as expected.
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Hi John,
Your script creates a table without specifying the table engine explicitly. In 5.5 (both MariaDB and MySQL) the default storage engine is InnoDB, unless it's set otherwise. InnoDB is a transactional engine.
Upon connection, python sets autocommit = 0. It's not in your script, it's done automatically.
On step 4 from the description, you start a new transaction by running INSERT, and then continue it by SELECT.
But you never execute COMMIT or issue any statement which would do the commit implicitly, such as a DDL. You just close the connection, so the transaction rolls back.
So, when you connect again and try to read from the table, naturally it is empty.
Now, if you are saying it does not work like that with MySQL, it can be on one of two reasons.
1. You are running it on MySQL 5.1, which has MyISAM as a default engine. It's not transactional, so once you executed INSERT, the data is there and stays there.
2. You are running it on MySQL 5.5 with default storage engine set to MyISAM (or anything else that is not transactional).
You can fix it by adding COMMIT before closing the connection.
Alternatively, if you don't mean the table to be transactional, you can add ENGINE=MyISAM to the CREATE statement.
Alternatively, if you don't want InnoDB to be the default engine, you can change it globally in your server.
Please let us know if the explanation is sufficient.
Thanks.