[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: MariaDB problemen met UTF-8



On Sun, Jan 21, 2024 at 11:10:49PM +0100, Paul van der Vlis wrote:
> Hallo,
> 
> Ik probeer een database te importeren in MariaDB,

A.u.b. iets `head -n 42 de_database_dump` laten zien
zodat duidelijk wordt wat de character_set van de database is.


> maar dit geeft een foutmelding:
> -----
> ERROR 1366 (22007) at line 139029: Incorrect string value: '\xF0\x9F\x91\x89
> S...' for column `edagenda`.`wp_posts`.`post_content` at row 1
> -----
> 
> '\xF0\x9F\x91\x89' blijkt een 4-bit UTF-8 teken, het blijkt een handje te
> zijn: '👉'. Ik blijk erop te kunnen zoeken en vervangen, maar dan lukt het
> importeren nog steeds niet en is er weer een ander teken met dit soort
> problemen.

Tja,  character sets.

 
> Als ik in de SQL code kijk dan wordt "utf8mb4_unicode_520_ci" gebruikt bij
> het aanmaken van de tabellen.

"tabellen"  en wat heeft de destination aan charset???


> Ik heb dit met zoek en vervang al geprobeerd
> te vervangen door 'utf8mb4_general_ci' maar dat helpt niet.
> 
> Zoiets is het dus na zoek en vervang:
> ----
> CREATE TABLE `wp_posts` (
>   `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
>   `post_author` bigint(20) unsigned NOT NULL DEFAULT '0',
>   `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
>   `post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
>   `post_content` longtext COLLATE utf8mb4_general_ci NOT NULL,
>   `post_title` text COLLATE utf8mb4_general_ci NOT NULL,
>   `post_excerpt` text COLLATE utf8mb4_general_ci NOT NULL,
>   `post_status` varchar(20) COLLATE utf8mb4_general_ci NOT NULL DEFAULT
> 'publish',
>   `comment_status` varchar(20) COLLATE utf8mb4_general_ci NOT NULL DEFAULT
> 'open',
>   `ping_status` varchar(20) COLLATE utf8mb4_general_ci NOT NULL DEFAULT
> 'open',
>   `post_password` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT
> '',
>   `post_name` varchar(200) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
>   `to_ping` text COLLATE utf8mb4_general_ci NOT NULL,
>   `pinged` text COLLATE utf8mb4_general_ci NOT NULL,
>   `post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
>   `post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
>   `post_content_filtered` longtext COLLATE utf8mb4_general_ci NOT NULL,
>   `post_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
>   `guid` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
>   `menu_order` int(11) NOT NULL DEFAULT '0',
>   `post_type` varchar(20) COLLATE utf8mb4_general_ci NOT NULL DEFAULT
> 'post',
>   `post_mime_type` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT
> '',
>   `comment_count` bigint(20) NOT NULL DEFAULT '0',
>   PRIMARY KEY (`ID`),
>   KEY `post_name` (`post_name`(191)),
>   KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
>   KEY `post_parent` (`post_parent`),
>   KEY `post_author` (`post_author`)
> ) ENGINE=InnoDB AUTO_INCREMENT=9000 DEFAULT CHARSET=utf8mb4
> COLLATE=utf8mb4_general_ci;
> ---------
> 
> Ik heb wat testjes gedaan zoals hier voorgesteld:
> https://sebhastian.com/mysql-incorrect-string-value/

DR


> Maar als ik een tabel test aanmaak dan doet-ie dat goed:
> ---
> MariaDB [edagenda]> CREATE TABLE `Test` (
>   `names` varchar(255)
> )
> MariaDB [edagenda]> SHOW CREATE TABLE Test \G
>        Table: Test
> Create Table: CREATE TABLE `Test` (
>   `names` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
> DEFAULT NULL
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
> 1 row in set (0,000 sec)
> -----
> 
> Echter, als ik dan een speciaal teken invoer gaat het niet goed:
> ----
> MariaDB [edagenda]> INSERT INTO Test VALUES('𓁴');
> ERROR 1366 (22007): Incorrect string value: '\xF0\x93\x81\xB4' for column
> `edagenda`.`Test`.`names` at row 1
> MariaDB [edagenda]> INSERT INTO Test VALUES('a');
> Query OK, 1 row affected (0,004 sec)
> ----
> 
> Iemand een idee?
> 

Alleen een wild idee:   De database client (connectie) heeft
zijn eigen idee over wat de charset moet zijn.



Groeten
Geert Stappers
-- 
Silence is hard to parse


Reply to: