HeidiSQL query window displaying German text strings with encoding issues

johnpaolo's profile image johnpaolo posted 2 weeks ago in General Permalink

Hi everyone, I am using HeidiSQL to maintain a remote database for a localization project targeting German users. I am currently trying to run test queries on a table containing user-submitted FAQs to ensure special characters like ü and ß are indexed properly. When I run a SELECT statement on the database, the following text records return with broken characters in the HeidiSQL grid viewer: • Warum ist der Führerschein so teuer geworden? • Wie viele Fahrstunden braucht man für B? • Wie viel kostet 45 Minuten Fahrstunde? Specifically, when checking long-tail exact matches like Führerschein kaufen ohne Prüfung? Ist das legal?, the German characters break completely into weird symbols. The application backend pulls data from our web server at [europathconsult.eu], where the text renders fine. Is this an issue with how the HeidiSQL text grid renders high-diacritic European strings, or do I need to explicitly adjust my session client encoding options within the connection manager? Thanks for any advice!

ansgar's profile image ansgar posted 2 weeks ago Permalink

This is in almost any case an encoding issue in the application which writes to the database. HeidiSQL is purely working in UTF-8 mode.

To get more specific you should post some more details about the database server and version. And the CREATE TABLE code of your FAQ table should be helpful.

johnpaolo's profile image johnpaolo posted 2 weeks ago Permalink

Thank you for the quick response! That makes perfect sense if HeidiSQL forces UTF-8 by default. To answer your questions, here are the technical details of the environment I am currently using for the project: • Database Server: MariaDB 10.6.15-MariaDB (hosted on a Linux remote server) • Connection Type: Standard TCP/IP via an SSH Tunnel configured inside HeidiSQL Here is the exact CREATE TABLE structure for the FAQ table where we store these localized German strings for the europathconsult.eu portal layout:

CREATE TABLE `cms_faq_content` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `category_id` INT(11) NOT NULL,
  `question_string` VARCHAR(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,
  `answer_text` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,
  `is_active` TINYINT(1) DEFAULT 1,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Looking closely at the export structure I just generated to paste here, I think I see the exact issue you pointed out. Even though the database default charset is set to utf8mb4, the individual columns (question_string and answer_text) seem to have been inadvertently created using CHARACTER SET latin1 COLLATE latin1_swedish_ci during an earlier migration phase. This explains why phrases like "Warum ist der Führerschein so teuer geworden?" and "Führerschein kaufen ohne Prüfung? Ist das legal?" are rendering with corrupted diacritics when HeidiSQL pulls them through a pure UTF-8 channel. If I use the HeidiSQL Table Editor tab to directly alter the column collations to utf8mb4_unicode_ci, will HeidiSQL safely convert the existing records in the grid, or do I risk permanently breaking the characters already saved in those rows? Thanks again for pointing me in the right direction!

ansgar's profile image ansgar posted 2 weeks ago Permalink

A latin1 column is not a problem per se — MySQL/MariaDB converts between column charset and client charset automatically, and HeidiSQL connects in UTF-8, so properly stored latin1 text displays correctly. The broken characters indicate your rows contain UTF-8 bytes which were written through a connection with a wrong charset (typically PHP doing SET NAMES latin1 while sending UTF-8) — the classic double encoding. Your website still looks fine because the PHP backend does the same wrong thing in both directions.

Check what's actually stored before touching anything:

SELECT id, question_string, HEX(question_string)
FROM cms_faq_content WHERE question_string LIKE '%hrerschein%';

If ü shows up as FC in the hex output, your data is genuine latin1, and changing the charset to utf8mb4 in the table editor is safe — the server will convert the existing rows correctly. (Changing only the collation never converts any data, but that's not what you want here.)

If you see C3BC instead, the stored data is UTF-8 in disguise. In that case do NOT just switch the charset, that would permanently bake the mojibake in. Instead re-interpret the stored bytes without converting them, in two steps:

ALTER TABLE cms_faq_content MODIFY question_string VARBINARY(255);
ALTER TABLE cms_faq_content MODIFY question_string VARCHAR(255)
  CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- for answer_text: TEXT -> BLOB -> TEXT

And make sure whatever writes to these columns uses a utf8mb4 connection from then on (mysqli_set_charset('utf8mb4') or equivalent), otherwise you'll get the same mess again. Take a mysqldump backup before the ALTERs in both cases.

Please login to leave a reply, or register at first.