SET @tableExists := (
    SELECT COUNT(*)
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'nfse_debug'
);

SET @sql := IF(@tableExists = 0,
'CREATE TABLE nfse_debug (
    id INT NOT NULL AUTO_INCREMENT,
    chave VARCHAR(50) NOT NULL,
    valor VARCHAR(50) NOT NULL,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;',
'SELECT "Tabela nfse_debug já existe, nada a fazer."'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;