Modify the default mysql encoding for Ubuntu
BitsCN.com
Modify the mysql configuration fileTo make the character set settings of the database and the server operating system consistent.
Vi/etc/my. cnf settings (if this file is not found, create one)
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
Default-character-set = utf8 (the key sentence is added so that the database is stored in utf8 by default)
After modification, restart the database.
Run the mysql-u root-p command again to enter the database system, and run the show variables like 'character _ set _ % 'command to view the following content:
+ -------------------------- + ----------------------------------------------------------------------- +
| Variable_name | Value |
+ -------------------------- + ----------------------------------------------------------------------- +
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database |Utf8|
| Character_set_filesystem | binary |
| Character_set_results | latin1 |
| Character_set_server |Utf8|
| Character_set_system |Utf8|
| Character_sets_dir |/usr/local/mysql-5.1.20-beta-linux-i686-glibc23/share/mysql/charsets/|
+ -------------------------- + ----------------------------------------------------------------------- +
Utf8 has been used for key projects, but this is not enough,Make sure that the client uses the utf8 character set for operations..
Use the following command to log on: mysql -- default-character-set = utf8-u root-p
Run the show variables like 'character _ set _ % 'command again:
+ -------------------------- + ----------------------------------------------------------------------- +
| 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/local/mysql-5.1.20-beta-linux-i686-glibc23/share/mysql/charsets/|
+ -------------------------- + ----------------------------------------------------------------------- +
In this way, the commands sent by the client are all in the utf8 format. for example, if you create a database and a table, utf8 encoding is used by default, and you do not need to specify it again.
It should be noted that if a database has been created before the encoding is modified, you need to delete the original database and recreate the database.
BitsCN.com