@rickzimm
The issue here is the routine that queries keys table to check if the key exist is returning they don’t so, it tries to insert. I suspect the keys table is corrupt so try to run
CHECK TABLE `keys`;
ALTER TABLE `keys` ENGINE = InnoDB;
-
OPTIMIZE TABLE `keys`;
This will really recreate and analyze instead FLUSH TABLE `keys`;
btw: check your collations