Error 1273 but my schema don't contain utf8mb4_0900_ai_ci
Question:
I have developed an app in python with SQLAlchemy. My MySQL test database is in version 8.0 and my product database is in 5.7. I did the migration between the database and there is no error. But when I connect to the product database, I obtain the error "1273 (HY000): Unknown collation: ‘utf8mb4_0900_ai_ci’".
However, my structure don’t contain "utf8mb4_0900_ai_ci". There is only "utf8mb4_general_ci".
I specify that this error occurs only when I connect to the product database.
Connection to database:
engine = create_engine('mysql+mysqlconnector://user:***********@**********:3306/amatdb?charset=utf8mb4')
SQL example
DROP TABLE IF EXISTS `alembic_version`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `alembic_version` (
`version_num` varchar(32) NOT NULL,
PRIMARY KEY (`version_num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
Thank you in advance for your help
Answers:
Fixed : Just add "&collation=utf8mb4_general_ci’"
engine=create_engine('mysql+mysqlconnector://user:***********@**********:3306/amatdbcharset=utf8mb4&collation=utf8mb4_general_ci')
If you are using Flask with Flask-SQLAlchemy, then the create_engine() method couldn’t be accessed and changed easily (I didn’t find any way to do that). Then the workaround is to change the connector version to 8.0.16
mysql-connector-python==8.0.16
The default collation utf8mb4_0900_ai_ci
was set in the version 8.0.17
, so it works if you use any version before 8.0.17
If you are using xampp maria db, just change the version of mysql connector to an older one, prior to version 8.0.17 that will work
I have developed an app in python with SQLAlchemy. My MySQL test database is in version 8.0 and my product database is in 5.7. I did the migration between the database and there is no error. But when I connect to the product database, I obtain the error "1273 (HY000): Unknown collation: ‘utf8mb4_0900_ai_ci’".
However, my structure don’t contain "utf8mb4_0900_ai_ci". There is only "utf8mb4_general_ci".
I specify that this error occurs only when I connect to the product database.
Connection to database:
engine = create_engine('mysql+mysqlconnector://user:***********@**********:3306/amatdb?charset=utf8mb4')
SQL example
DROP TABLE IF EXISTS `alembic_version`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `alembic_version` (
`version_num` varchar(32) NOT NULL,
PRIMARY KEY (`version_num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
Thank you in advance for your help
Fixed : Just add "&collation=utf8mb4_general_ci’"
engine=create_engine('mysql+mysqlconnector://user:***********@**********:3306/amatdbcharset=utf8mb4&collation=utf8mb4_general_ci')
If you are using Flask with Flask-SQLAlchemy, then the create_engine() method couldn’t be accessed and changed easily (I didn’t find any way to do that). Then the workaround is to change the connector version to 8.0.16
mysql-connector-python==8.0.16
The default collation utf8mb4_0900_ai_ci
was set in the version 8.0.17
, so it works if you use any version before 8.0.17
If you are using xampp maria db, just change the version of mysql connector to an older one, prior to version 8.0.17 that will work