数据库中中文乱码解决:
设置server级,db级,table级使用的字符集为utf8。
设置方法:
查看mysql字符集状态:
先使用客户端工具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
设置server级字符集:
编辑 /etc/my.cnf文件
- [client]
- default-character-set=utf8
- [mysqld]
- character_set_server=utf8
设置db级字符集:
创建数据库是指定:
mysql> create database mytest character set utf8;
修改已有数据库字符集:
- mysql> alter database character set utf8;
创建表时指定:
- mysql> create table mytable(id int auto_increment primary key) character set utf8;
修改表的字符集:
- mysql> alter table mytable character set latin1;
还有就是修改字符集只对之后添加的数据有效,已存在的数据不会改变