bitsCN.com
安装完的MySQL的默认字符集为 latin1 ,为了要将其字符集改为用户所需要的(比如utf8),就必须改其相关的配置文件;由于linux下MySQL的默认安装目录分布在不同的文件下;不像windows一样放在同一目录下,只需修改其中的my.ini文件,重起后就生效了;所以先来看看linux下MySQL的数据库文件、配置文件和命令文件分别在不同的目录 :
1、数据库目录,其所创建的数据库文件都在该目录下
/var/lib/mysql/
2、配置文件 (mysql.server命令及配置文件所在地)
/usr/share/mysql
3、相关命令(如mysql mysqladmin等)
/usr/bin
4、启动脚本(如mysql启动命令)
/etc/rc.d/init.d/
查看默认字符集
#mysql -u root - p
#(输入密码)
mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
修改字符集修改 /etc/my.cnf文件
#/etc/my.cnf[client]default-character-set=utf8[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0#default-character-set=utf8character-set-server=utf8init_connect='SET NAMES utf8'[mysql]no-auto-rehashdefault-character-set=utf8[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid