mysql数据库中中文乱码解决方法:
mysql> status
-------------- mysql Ver 14.14 Distrib 5.5.29, for linux2.6 (i686) using readline 5.1 Connection id: 2 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.29-log MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /tmp/mysql.sock Uptime: 1 min 10 sec
2,设置server级字符集:
[client]
default-character-set=utf8 [mysqld] character_set_server=utf8
注:[mysqld]处也可使用default-character-set=utf8,如果启动mysql服务出错的话,就使用character_set_server=utf8。
mysql> create database mytest character set utf8;
4,修改已有数据库字符集:
mysql> alter database character set utf8;
5,设置表字符集:
mysql> create table mytable(id int auto_increment primary key) character set utf8;
6,修改表的字符集:
mysql> alter table mytable character set latin1;
如果数据中要存放中文字符, 推荐使用utf8。 还有就是修改字符集只对之后添加的数据有效,已存在的数据不会改变。 (责任编辑:IT) |