环境:ubuntu 6.10 系统编码 utf8
mysql5 编码 utf8
phpmyadmin 编码 utf8
系统默认为utf8编码,mysql编译的时候默认编译为utf8
1、配置phpmyadmin
sudo gedit /var/www/phpmyadmin/config/config.inc.php
修改并添加相应的选项
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'xxx';/* xxx对应root密码*/
以root用户进入http://127.0.0.1/phpmyadmin/
2、登录时选择字符集为 UTF-8 Unicode (utf8)
3、建表然后插入数据正常
4、以命令行进入mysql
mysql -u root -p
use test//选择数据库
show tables
select * from test
结果显示乱码
说明命令行底下的编码跟phpmyadmin的编码不对称
6、以mysql --default-character-set=utf8 -u root -p登录
查看表显示正常
7、将编码写入配置文件
sudo gedit /etc/mysql/my.cnf
添加
[client]
default-character-set=utf8
8、重启mysql
在phpmyadmin和shell下插入和显示数据都正常。
mysql5 编码 utf8
phpmyadmin 编码 utf8
系统默认为utf8编码,mysql编译的时候默认编译为utf8
1、配置phpmyadmin
sudo gedit /var/www/phpmyadmin/config/config.inc.php
修改并添加相应的选项
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'xxx';/* xxx对应root密码*/
以root用户进入http://127.0.0.1/phpmyadmin/
2、登录时选择字符集为 UTF-8 Unicode (utf8)
3、建表然后插入数据正常
4、以命令行进入mysql





说明命令行底下的编码跟phpmyadmin的编码不对称
6、以mysql --default-character-set=utf8 -u root -p登录
查看表显示正常
7、将编码写入配置文件
sudo gedit /etc/mysql/my.cnf
添加

default-character-set=utf8
在phpmyadmin和shell下插入和显示数据都正常。