Settare mysql utf8

Di Default molte distribuzioni Linux , installano mysql con default character set settano a latin1.

Per modificare questo valore e impostarlo in utf8 :

alla fine di [client] section, aggiungi:

Code:
default-character-set = utf8

alla fine di  [mysqld] section, aggiungi:

Code:
character-set-server = utf8

restart mysql

Code:
> sudo /etc/init.d/mysql restart

per verificare :

Code:
> mysql -u root -p
mysql> show variables like '%char%';

dovresti vedere :

Code:
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       | 
| character_set_connection | utf8                       | 
| character_set_database   | utf8                       | 
| character_set_filesystem | binary                     | 
| character_set_results    | utf8                       | 
| character_set_server     | utf8                       | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
Code:
default-character-set = utf8

at the end of [mysqld] section, add:

Code:
character-set-server = utf8

then restart your mysql server:

Code:
> sudo /etc/init.d/mysql restart

and make sure it says OK with

Code:
* Starting MySQL database server mysqld

then check if it all works out

Code:
> mysql -u root -p
mysql> show variables like '%char%';

you should see the following:

Code:
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       | 
| character_set_connection | utf8                       | 
| character_set_database   | utf8                       | 
| character_set_filesystem | binary                     | 
| character_set_results    | utf8                       | 
| character_set_server     | utf8                       | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)