In various PostgreSQL vs. MySQL comparisons I’ve seen many mentions of problems with data integrity in MySQL. Is this currently still an issue?
Particularly for web applications using MySQL, are there tricks to making sure data integrity is maintained? Or with new versions is this true ‘out of the box’ with no additional configuration required?
By default MySQL created myisam engine tables, which does not support transactions or foreign keys, you need to explicitly force transactional innodb engine while creating a table.
By default MySQL accepts invalid data, like date ‘2010-02-30’, silently truncates too long textual data, too big numbers etc. But you can change it for INNODB tables using
SET sql_mode = 'STRICT_TRANS_TABLES';on mysql 5.0.2 and up – see “Constraints on Invalid Data”.MySQL does not support check constraints at all, so you can not for example:
range;
address or valid url);
numbers and minus etc.);
or empty text data.
So all data validation has to be done in client application. Which is harder to do and more error-prone.
All of this is not a problem in PostgreSQL.