I am running python script to insert record in table. I am reading data from spreadsheet that contain cell with special characters.
In my script I am running following commands before executing below commands:
SET NAMES utf8mb4;
SET CHARACTER SET utf8mb4;
SET character_set_connection=utf8mb4;
SET collation_connection = utf8mb4_unicode_ci;
Here is my table structure:
CREATE TABLE `staging` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`d_date` date NOT NULL,
`m_date` date NOT NULL,
`market` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'US',
`cola` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`colb` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=265 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Table Encoding: UTF8MB4 Table Collation: UTF8MB4_UNICODE_CI
Environment Variables:
SHOW VARIABLES LIKE '%collation%';
collation_connection latin1_swedish_ci
collation_database utf8mb4_unicode_ci
collation_server utf8mb4_unicode_ci
SHOW VARIABLES LIKE '%char%';
character_set_client latin1
character_set_connection latin1
character_set_database utf8mb4
character_set_filesystem binary
character_set_results latin1
character_set_server utf8mb4
character_set_system utf8
character_sets_dir /usr/local/mysql-5.7.20-macos10.12-x86_64/share/charsets/
Query:
insert into staging (d_date, m_date, market, cola, colb )
values ('2019-07-18', '2019-07-01', 'US', 'ARCA', 'Sodius\xa0Consumer Auto');
Error:
_mysql_exceptions.OperationalError: (1366, "Incorrect string value: '\\xA0Consu...' for column 'colb' at row 1")
Expected Result is row should be inserted into the database.