Ashish Jagtap
Ashish Jagtap

Reputation: 2819

How to handle umlauts in a MySQL `WHERE` clause?

My Table collation is utf8_general_ci and character set is utf8. If I run a query like the following, it does not show me any value.

SELECT * FROM mytable WHERE myfield = "Björn Borg"
OR myfield = "FrüFrü & Tigerlily";

So how I can fetch the values from table ?

Upvotes: 1

Views: 2473

Answers (2)

Maksym Polshcha
Maksym Polshcha

Reputation: 18358

The problem can be in your connection charset. Try to run

SET NAMES 'utf8mb4'

And then your query.

Upvotes: 1

Sprachprofi
Sprachprofi

Reputation: 1259

There are more places where MySQL defines character sets, including at the column level.

To check the database settings: SHOW VARIABLES LIKE 'char%'; SHOW VARIABLES LIKE 'collation%';

To check the table settings: SHOW CREATE TABLE tablename;

To check the individual columns: SHOW FULL COLUMNS IN tablename;

If you created a database with the wrong encoding, you will have to change every single occurence of a bad charset in all of these.

Upvotes: 0

Related Questions