Pensaci:
- Stai memorizzando i dati nel database come
latin1
- I tuoi dati sono gestiti internamente da mysqld as
latin1
Se i dati provenienti dal sistema operativo o dalla connessione sono utf8, come lo gestirà mysqld?
Invece di indovinare o sperare per il meglio, è possibile modificare il comportamento del set di caratteri in arrivo. Ad eccezione di information_schemae mysql, prendi tutti i tuoi database e imposta il set di caratteri predefinito su utf8:
ALTER DATABASE dbname CHARACTER SET utf8;
Se hai una colllation specifica da seguire, procedi nel seguente modo:
ALTER DATABASE dbname COLLATE 'utf8_general_ci';
Ecco le regole di confronto tra cui scegliere:
mysql> select * from information_schema.collations where CHARACTER_SET_NAME = 'utf8';
+--------------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN |
+--------------------+--------------------+-----+------------+-------------+---------+
| utf8_general_ci | utf8 | 33 | Yes | Yes | 1 |
| utf8_bin | utf8 | 83 | | Yes | 1 |
| utf8_unicode_ci | utf8 | 192 | | Yes | 8 |
| utf8_icelandic_ci | utf8 | 193 | | Yes | 8 |
| utf8_latvian_ci | utf8 | 194 | | Yes | 8 |
| utf8_romanian_ci | utf8 | 195 | | Yes | 8 |
| utf8_slovenian_ci | utf8 | 196 | | Yes | 8 |
| utf8_polish_ci | utf8 | 197 | | Yes | 8 |
| utf8_estonian_ci | utf8 | 198 | | Yes | 8 |
| utf8_spanish_ci | utf8 | 199 | | Yes | 8 |
| utf8_swedish_ci | utf8 | 200 | | Yes | 8 |
| utf8_turkish_ci | utf8 | 201 | | Yes | 8 |
| utf8_czech_ci | utf8 | 202 | | Yes | 8 |
| utf8_danish_ci | utf8 | 203 | | Yes | 8 |
| utf8_lithuanian_ci | utf8 | 204 | | Yes | 8 |
| utf8_slovak_ci | utf8 | 205 | | Yes | 8 |
| utf8_spanish2_ci | utf8 | 206 | | Yes | 8 |
| utf8_roman_ci | utf8 | 207 | | Yes | 8 |
| utf8_persian_ci | utf8 | 208 | | Yes | 8 |
| utf8_esperanto_ci | utf8 | 209 | | Yes | 8 |
| utf8_hungarian_ci | utf8 | 210 | | Yes | 8 |
| utf8_sinhala_ci | utf8 | 211 | | Yes | 8 |
+--------------------+--------------------+-----+------------+-------------+---------+
22 rows in set (0.03 sec)
Potresti anche correre
mysql> show collation where charset='utf8';
+--------------------+---------+-----+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+--------------------+---------+-----+---------+----------+---------+
| utf8_general_ci | utf8 | 33 | Yes | Yes | 1 |
| utf8_bin | utf8 | 83 | | Yes | 1 |
| utf8_unicode_ci | utf8 | 192 | | Yes | 8 |
| utf8_icelandic_ci | utf8 | 193 | | Yes | 8 |
| utf8_latvian_ci | utf8 | 194 | | Yes | 8 |
| utf8_romanian_ci | utf8 | 195 | | Yes | 8 |
| utf8_slovenian_ci | utf8 | 196 | | Yes | 8 |
| utf8_polish_ci | utf8 | 197 | | Yes | 8 |
| utf8_estonian_ci | utf8 | 198 | | Yes | 8 |
| utf8_spanish_ci | utf8 | 199 | | Yes | 8 |
| utf8_swedish_ci | utf8 | 200 | | Yes | 8 |
| utf8_turkish_ci | utf8 | 201 | | Yes | 8 |
| utf8_czech_ci | utf8 | 202 | | Yes | 8 |
| utf8_danish_ci | utf8 | 203 | | Yes | 8 |
| utf8_lithuanian_ci | utf8 | 204 | | Yes | 8 |
| utf8_slovak_ci | utf8 | 205 | | Yes | 8 |
| utf8_spanish2_ci | utf8 | 206 | | Yes | 8 |
| utf8_roman_ci | utf8 | 207 | | Yes | 8 |
| utf8_persian_ci | utf8 | 208 | | Yes | 8 |
| utf8_esperanto_ci | utf8 | 209 | | Yes | 8 |
| utf8_hungarian_ci | utf8 | 210 | | Yes | 8 |
| utf8_sinhala_ci | utf8 | 211 | | Yes | 8 |
+--------------------+---------+-----+---------+----------+---------+
22 rows in set (0.00 sec)
mysql>
Per vedere il singolo set di caratteri di un database eseguire questo:
mysql> show create database sample;
+----------+-------------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------------+
| sample | CREATE DATABASE `sample` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
Per quanto riguarda le impostazioni, puoi provare questo:
Aggiungi le linee a my.cnf
[mysqld]
character_set_database=utf8
character_set_server=utf8
quindi riavviare mysql
Ne ho discusso il 1 ° agosto 2011: Character Set Encoding in a Table
CAVEAT (per server MySQL DB in Windows)
Questi comandi
ALTER DATABASE dbname CHARACTER SET utf8;
ALTER DATABASE dbname COLLATE 'utf8_general_ci';
non funziona nella versione Windows di MySQL a causa del modo in cui Windows blocca i file. Viene chiamato il file necessario db.optche si trova nella sottocartella del database in datadir.
Potrebbe essere necessario eseguire le seguenti operazioni:
- mysqldump quel database (nessun database crea informazioni, solo creazione di tabelle e INSERT)
- rilasciare quel database
- creare un database con il set di caratteri e le regole di confronto specifici
- ricaricare nella discarica in esso
EPILOGO
Indipendentemente da ciò che fai, esegui qualsiasi modifica su un Dev / Staging Server per vedere se ottieni gli effetti desiderati
AGGIORNAMENTO 2012-12-05 11:00 EDT
Le tue domande
Dovrei davvero cambiarlo?
Per garantire il corretto trattamento dei dati, potresti voler assicurarti di avere mele su mele. I dati preparati come set di caratteri e caricandoli in una tabella con il database probabilmente allineando i dati come se vedessero un altro set di caratteri probabilmente non visualizzerebbero i dati con il set di caratteri che mysqld vede quando vengono recuperati e inviati a una connessione DB. Prova a caricare il database su un Dev / Staging Server e prova a impostare i set di caratteri predefiniti.
Perché alcune impostazioni predefinite utilizzano, utf8ma alcune utilizzano quelle predefinite latin1?
Ciò dipende dalla versione del sistema operativo MySQL Binary. Le versioni di Windows possono avere latin1mentre le versioni di Linux possono usare utf8.