最新消息: 新版网站上线了!!!

mysql 默认编码设置

查看当前编码

mysql> show variables like "%character%";

mysql> show variables like "%collation%";

 

输出内容如下:

mysql> show variables like "%character%";

+--------------------------+---------------------------------------------------+

| 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       | C:\MySQL\MySQL Server 5.0\share\charsets\ |

+--------------------------+---------------------------------------------------+

8 rows in set (0.00 sec)

 

mysql> show variables like "%collation%";

+----------------------+-------------------+

| Variable_name        | Value             |

+----------------------+-------------------+

| collation_connection | latin1_swedish_ci |

| collation_database   | latin1_swedish_ci |

| collation_server     | latin1_swedish_ci |

+----------------------+-------------------+

3 rows in set (0.00 sec)

 

进入mysql安装目录编辑,Linux下一般是 /etc/my.cnf,编辑my.ini文件,设置如下内容

[client]

default-character-set=utf8

 

[mysql]

default-character-set=utf8

 

[mysqld]

default-character-set=utf8

character_set_server=utf8

 

[mysql.server]

default-character-set=utf8

 

[mysqld_safe]

default-character-set=utf8

 

编辑保存文件后重启MySql服务

Windows可在服务管理器中操作,也可使用命令行:

net stop mysql 回车

net start mysql 回车

服务名可能不一定为mysql,请按自己的设置

Linux下面可以用 service mysql restart

 

设置后的编码如下:

mysql> show variables like "%character%";

+--------------------------+---------------------------------------------------+

| Variable_name            | Value |

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8 |

| character_set_connection | utf8 |

| character_set_database   | utf8 |

| character_set_filesystem | binary |

| character_set_results    | utf8 |

| character_set_server     | utf8 |

| character_set_system     | utf8 |

| character_sets_dir       | C:\MySQL\MySQL Server 5.0\share\charsets\ |

+--------------------------+----------------------------------------------------+

8 rows in set (0.00 sec)

 

mysql> show variables like "%collation%";

+----------------------+-----------------+

| Variable_name        | Value           |

+----------------------+-----------------+

| collation_connection | utf8_general_ci |

| collation_database   | utf8_general_ci |

| collation_server     | utf8_general_ci |

+----------------------+-----------------+

3 rows in set (0.00 sec)

 
.....

转载请注明:谷谷点程序 » mysql 默认编码设置