MySQL设置字符集CHARACTER SET

本文地址:http://www.cnblogs.com/yhLinux/p/4036506.html

my.cnf 配置文件中设置相关选项,改变为相应的character set。

 

 

设置数据库编码(sudo vi /etc/mysql/my.cnf):

[client]
default-character-set = utf8

[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci

参考资料:

  14.1.4 Character Set

  5.1.4 Server System Variables

  10.5, “Character Set Configuration”

  

  10.1 Character Set Support

  You can specify character sets at the server, database, table, and column level.

  10.1.3 Specifying Character Sets and Collations

  10.1.3.1 Server Character Set and Collation

  MySQL Server has a server character set and a server collation. These can be set at server startup on the command line or in an option file and changed at runtime.

  10.1.3.2 Database Character Set and Collation

  Every database has a database character set and a database collation.

  The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables. The server sets these variables whenever the default database changes. If there is no default database, the variables have the same value as the corresponding server-level system variables, character_set_server and collation_server.  

Specify character settings at server startup. To select a character set and collation at server startup, use the --character-set-server and --collation-server options. For example, to specify the options in an option file, include these lines:

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

These settings apply server-wide and apply as the defaults for databases created by any application, and for tables created in those databases.

You can force client programs to use specific character set as follows:

[client]
default-character-set=charset_name

This is normally unnecessary. However, when character_set_system differs from character_set_server or character_set_client, and you input characters manually (as database object identifiers, column values, or both), these may be displayed incorrectly in output from the client or the output itself may be formatted incorrectly. In such cases, starting the mysql client with --default-character-set=system_character_set—that is, setting the client character set to match the system character set—should fix the problem.

 

 

查看设置结果

更改my.cnf之前:

复制代码
mysql> SHOW VARIABLES LIKE '%char%'; +--------------------------+---------------------------------------------------------------+
| Variable_name            | Value | +--------------------------+---------------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.6.21-linux-glibc2.5-x86_64/share/charsets/ | +--------------------------+---------------------------------------------------------------+
复制代码

 设置之后,重启mysql服务($ sudo service mysql restart):

复制代码
mysql> SHOW VARIABLES LIKE '%char%'; +--------------------------+---------------------------------------------------------------+
| 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 | /usr/local/mysql-5.6.21-linux-glibc2.5-x86_64/share/charsets/ | +--------------------------+---------------------------------------------------------------+
复制代码

 

转载于:https://www.cnblogs.com/yhLinux/p/4036506.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值