truncate() is another statement with implicit commit(). It used to work inside a transaction, but after migrating to Amazon RDS for MySQL - AWS MySQL 8, the script started throwing this error.