Modify the mysql configuration file to make the character set settings of the database and server operating system consistent.
vi /etc/my.cnf settings (if this file is not found, create a new one)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/MySQL/MySQL. Socks
Default character set=utf8 (the key sentence added makes the database store in utf8 by default)
Of course, after modification, the database must be restarted.
Use the mysql -u root -p command again to enter the database system and display the variables like "character_set_%"; the command displays the following content:
- -
| Variable name|value|
- -
| character_set_client | latin1 |
| character _ set _ connection | latin1
|Character set database|utf8
| character _ set _ file system |Binary
| character_set_results | latin1 |
|Character set server|utf8
|Character set system|utf8
| character _ set _ dir |/usr/local/MySQL-5.1.20-beta-Linux-i686- glibc 23/share/MySQL/charset/|
- -
It was found that the key project has used utf8, but this is not enoughIt is also necessary to ensure that the client also uses the utf8 character set To operate .
When logging in, use the following command: MySQL-default-character-set=utf8-u root-p
Use again like "character_set_%" to display variables; command to view the results Becomes:
- -
|Variable name|Value|
- -
| character_set_client | utf8 |
| character _ set _ connection | utf8 |
| character_set_database | utf8 |
| character _ set _ file system |binary
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character _ set _ dir |/usr/local/MySQL-5.1.20-beta-Linux-i686-glibc 23/share/MySQL/charset/|
The above is the detailed content of How to modify mysql default encoding in Ubuntu. For more information, please follow other related articles on the PHP Chinese website!