本文地址: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/ |
+--------------------------+---------------------------------------------------------------+

MySQL设置字符集CHARACTER SET的更多相关文章

  1. MySQL设置字符集为UTF8(Windows版)

    Windows版MySQL设置字符集全部为utf8的方式 MySQL安装目录下的my.ini文件 [client]节点 default-character-set=utf8    (增加) [mysq ...

  2. docker方式mysql设置字符集

    在docker上部署mysql时,mysql的默认字符集是latin1,这样如果日后有中文会出现异常,不能存储等,因为latin1是不支持中文的. 所以需要将字符集调整为utf8. 方法: 首先启动m ...

  3. mysql 设置字符集

    可以用:show create table table_name查看建表信息 也可用: show create database database_name查看建库信息 mysql> creat ...

  4. 为 MySQL 设置默认字符集(UTF-8)避免产生乱码

    环境:Windows 7+Wamp Server+MySQL 5.7.9 查看MySQL默认编码: SHOW VARIABLES LIKE 'character%' character_set_cli ...

  5. 查看和设置MySQL数据库字符集(转)

    查看和设置MySQL数据库字符集作者:scorpio 2008-01-21 10:05:17 标签: 杂谈 Liunx下修改MySQL字符集:1.查找MySQL的cnf文件的位置find / -ina ...

  6. mysql:设置字符集utf8mb4 支持emoji字符

    为什么要把数据库的字符集设置成utf8mb4呢?以前一直用的都是utf8啊? 答案在这里:utf8适用于不使用移动设备的互联网交互,utf8mb4适用于当前的移动设备互联网开发,因为移动设备中常常会有 ...

  7. mysql 设置查看字符集

    MySQL查看和修改字符集的方法   一.查看字符集 1.查看MYSQL数据库服务器和数据库字符集 方法一:show variables like '%character%';方法二:show var ...

  8. CentOS6.8安装mysql并设置字符集编码

    一.安装: 1. 首先以root用户进入系统 2. 输入命令: yum install mysql mysql-server -y 等待安装完成. 3. 启动MySQL,输入命令: /etc/init ...

  9. 修改mysql默认字符集的方法

    +--------------------------+---------------------------------+ | Variable_name | Value | +---------- ...

随机推荐

  1. (整理)PowerDesign与EF的文档说明

    最近通过PowerDesign->SQLServer->VS的方式,将数据库设计.创建.实体模型生成等环节打通,发现VS中的Model竟然没有说明,然后就在园子里找了一下,发现了园友的文章 ...

  2. 第五百八十二天 how can I 坚持

    好吧,是我错了,昨天,做好自己就行了,别人怎么样是别人的事,永远保持一颗单纯向上的心. 时间过得真快,明天又周六了.. 睡觉.

  3. python之fabric(二):执行模式(转)

    执行模式 执行模式可以让你在多个主机上执行多个任务. 执行策略: 默认fabric是单个有序地执行方法,其行为如下: 1. 创建一系列任务,通过fab任务执行要执行的任务: 2. 根据主机列表定义,去 ...

  4. arcgis desktop按ctrl键后地图乱移的解决办法

    习惯使用快捷键的,经常会按下ctrl. 但在arcmap中,按下ctrl后,地图乱移.分析发现变为鼠标导航状态,也就是鼠标偏离地图中心,地图就会往鼠标所在方向移动. 解决办法:1. 以前按下esc键, ...

  5. VC++模态对话框和非模态对话框

    MFC中有两种类型的对话框:模态对话框和非模态对话框.  模态对话框是指当其显示时,程序会暂停执行,直到关闭这个模态对话框后,才能继续执行程序中其他任务.非模态对话框是指当其显示时,允许转而执行程序中 ...

  6. 一个很酷的加载loading效果--IT蓝豹

    一个很酷的加载loading效果,自定义LeafLoadingView实现,LeafLoadingView继承view, 本例子主要由以下几点构成 (1):RotateAnimation实现叶子旋转 ...

  7. socket编程相关的结构体和字节序转换、IP、PORT转换函数

    注意:结构体之间不能直接进行强制转换, 必须先转换成指针类型才可以进行结构体间的类型转换, 这里需要明确的定义就是什么才叫强制转换. 强制转换是将内存中一段代码以另一种不同类型的方式进行解读, 因此转 ...

  8. scala学习心得3

    在scala中可以定义函数字面量参数,定义方式如下:

  9. git init 和 git init --bare 的区别

    http://blog.csdn.net/ljchlx/article/details/21805231 概念  裸仓储 :不可以在上面做git操作    the operation must be ...

  10. SQL时间戳的使用

    SQL时间戳的使用 一直对时间戳这个概念比较模糊,相信有很多朋友也都会误认为:时间戳是一个时间字段,每次增加数据时,填入当前的时间值.其实这误导了很多朋友. 1.基本概念 时间戳:数据库中自动生成的唯 ...