Home Database Mysql Tutorial Mysql 字符集设定

Mysql 字符集设定

Jun 07, 2016 pm 04:38 PM
mysql point character set set up

Mysql中的字符集的设定分为以下集中级别: 1. Mysql服务器级别的字符集设定 2. 数据库级别的字符集设定 3. 数据表级别的字符集设定 4. 数据列级别的字符集设定 每种字符集对应一种默认的排序方式,可以分别使用character set charset 以及collate collation来

Mysql中的字符集的设定分为以下集中级别:

1. Mysql服务器级别的字符集设定
2. 数据库级别的字符集设定
3. 数据表级别的字符集设定
4. 数据列级别的字符集设定

每种字符集对应一种默认的排序方式,可以分别使用character set charset 以及collate collation来对数据库,数据表,数据列设定。服务器级别的字符集与排序方式是内建的,在编译阶段设定的。可以通过系统变量来设置它们,这个很少涉及。

在创建数据库, 数据表,数据列时,设定一个默认的utf8字符集以及utf8_general_ci排序方式(字符集与排序方式必须兼容):

create database db_name character set utf8 collate utf8_general_ci;
create table tbl_name 
(
  column varchar(10) character set utf8 collate utf8_general_ci
) engine = InnoDB character set utf8 collate utf8_general_ci
Copy after login

可以通过查询information_schema中的character_sets以及collations数据表来获得支持的字符集以及排序方式。

也可以使用下列语句查询:

show character set;
show collation;
Copy after login

如果没有给数据列设置字符集,那么默认会使用数据表的字符集。如果没有给数据表设置字符集,那么默认会使用数据库的字符集。如果没有给数据库设置字符集,那么默认会使用数据库服务器的字符集。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

How to use MySQL backup and restore in PHP?

What are the application scenarios of Java enumeration types in databases? What are the application scenarios of Java enumeration types in databases? May 05, 2024 am 09:06 AM

What are the application scenarios of Java enumeration types in databases?

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into a MySQL table using PHP?

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Mar 05, 2025 pm 05:57 PM

Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node?

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

How to use MySQL stored procedures in PHP?

See all articles