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
参考资料:
10.5, “Character Set Configuration”
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=—that is, setting the client character set to match the system character set—should fix the problem.system_character_set
查看设置结果
更改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的更多相关文章
- MySQL设置字符集为UTF8(Windows版)
Windows版MySQL设置字符集全部为utf8的方式 MySQL安装目录下的my.ini文件 [client]节点 default-character-set=utf8 (增加) [mysq ...
- docker方式mysql设置字符集
在docker上部署mysql时,mysql的默认字符集是latin1,这样如果日后有中文会出现异常,不能存储等,因为latin1是不支持中文的. 所以需要将字符集调整为utf8. 方法: 首先启动m ...
- mysql 设置字符集
可以用:show create table table_name查看建表信息 也可用: show create database database_name查看建库信息 mysql> creat ...
- 为 MySQL 设置默认字符集(UTF-8)避免产生乱码
环境:Windows 7+Wamp Server+MySQL 5.7.9 查看MySQL默认编码: SHOW VARIABLES LIKE 'character%' character_set_cli ...
- 查看和设置MySQL数据库字符集(转)
查看和设置MySQL数据库字符集作者:scorpio 2008-01-21 10:05:17 标签: 杂谈 Liunx下修改MySQL字符集:1.查找MySQL的cnf文件的位置find / -ina ...
- mysql:设置字符集utf8mb4 支持emoji字符
为什么要把数据库的字符集设置成utf8mb4呢?以前一直用的都是utf8啊? 答案在这里:utf8适用于不使用移动设备的互联网交互,utf8mb4适用于当前的移动设备互联网开发,因为移动设备中常常会有 ...
- mysql 设置查看字符集
MySQL查看和修改字符集的方法 一.查看字符集 1.查看MYSQL数据库服务器和数据库字符集 方法一:show variables like '%character%';方法二:show var ...
- CentOS6.8安装mysql并设置字符集编码
一.安装: 1. 首先以root用户进入系统 2. 输入命令: yum install mysql mysql-server -y 等待安装完成. 3. 启动MySQL,输入命令: /etc/init ...
- 修改mysql默认字符集的方法
+--------------------------+---------------------------------+ | Variable_name | Value | +---------- ...
随机推荐
- ini 文件
INI文件是一个无固定标准格式的配置文件.它以简单的文字与简单的结构组成,常常使用在视窗操作系统,或是其他操作系统上,许多程序也会采用INI文件做为设置程序之用.视窗操作系统后来以注册表的形式替换掉I ...
- python发邮件
# -*- coding:utf- -*- import smtplib,os,sys,string import mimetypes from email import Encoders from ...
- Windows资源管理器 已停止工作
解决方案:http://jingyan.baidu.com/article/5225f26b6aa830e6fa0908a8.html
- Linux系统man查询命令等级及意义
1:用户命令,可由任何人启动的 2:系统调用,由内核提供的函数 3:库函数 4:设备,/dev目录下的特殊文件 5:文件格式描述,例如/etc/passwd 6:游戏 7:杂项,例如宏命令包.惯例等 ...
- Android IOS WebRTC 音视频开发总结(七三)-- 我为什么走上了创业这条不归路?
本文主要介绍自己为什么选择创业,文章最早发表在我们的微信公众号上,支持原创,详见这里, 欢迎关注微信公众号blackerteam,更多详见www.rtc.help 2016.06.01对公司来说是个很 ...
- Linux操作系统奥秘01-系统引导(MBR - 硬盘的0磁道)
Boot:1.系统PowerOn 2.BIOS在完成硬件初始化以及POST 3.BIOS加载MBR 4.GRUB->GRUB or kernal MBR MBR即主引导记录,是在BIOS中选择的 ...
- 自动生成form Scripts
运行脚本: begin xxx_plsql_generator_pkg2.form_view_iud_p(p_block_name =>'CONTRACT_T' ,p_table_name =& ...
- [Tomcat 源码分析系列] (附件) : setclasspath.bat 脚本
@echo off rem Licensed to the Apache Software Foundation (ASF) under one or more rem contributor lic ...
- asp.net GDI+绘制矩形渐变
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- CommonUtils
package com.utils; import java.lang.reflect.Field; import java.math.BigDecimal; import java.sql.Time ...