1. Introduction
1) create table table_name (column_declaration) charset utf8;
2) set names gbk;
Comments:
1) What's the meaning?
2) What's the difference?
2. Charset
1) Charset hierarchy: (Server>Database>Table>Column)
1) Server default charset
2) Database default charset
3) Table default charset
4) Column default charset
2) Charset hierarchy policy:
1) If we didn't declare the charset for a specific level, then its charset inherit from its parent's.
2) If we didn't declare the charset for server, the server can never start.
3) Comprehension for Translator:
1) Client/Console have its own charset
2) Translator has its own charset
3) Database has its own charset
4) Translator:
1) Translator has to know the input data's charset ---> In the figure above, the charset from client/console is gbk. ---> character_set_client = gbk;
2) Translator has to know the transit data's charset ---> In the figure above, the charset for transit data is utf-8 marked as red. ---> character_set_connection = utf8;
3) Translator has to know the database/table charset ---> In the figure above, the charset for database is utf-8. ---> create table table_name (column_delcaration) charset utf8;
4) Translator has to know the output data's charset ---> In the figure above, the charset for output is gbk. ---> character_set_results = gbk;
Comments: If character_set_client, character_set_connection, character_set_results is the same value of N. Then we can use "set names N" for short.
5) When will garbled occurs?
1) Character_set_client is not according to the truth. The data input from console is in charset of gbk. If we declared character_set_client = utf8, garbled occured.
2) Character_set_results is not according to the truth. The data output to webpage is in charset of utf8. If we declared character_set_client = gbk, garbled occured.
6) When will data loss?
1) Character_set_connection/database-charset is smaller than the charset of data passed from client.
Eg: gbk->lartin1->gbk: During the procession of translating from client to transit data, data loss!
gbk->gbk->lartin1: Durint the processon of translating from transit data to database, data loss!
7) Real world problem:
1) For some reason, the data store in database as charset gbk and cannot be modified.
2) Data passed from client is php with charset of utf8.
3) Solution: set names utf8; crate table table_name(column_declaration) charset gbk;
3. Collation
1) Introduction
# Create table create table temp(name varchar(12)); # Insert data insert into temp values('a'), ('B'), ('c'), ('D'); # Order data select * from temp order by name asc; +------+ | name | +------+ | a | | B | | c | | D | +------+ # Q: a->97, B->66. Why a < B? # A: Refer to collation.
2) What is collaton?
1) In order to order data in a table according to a column, we must specify a rule for this. And the rule is just the collation.
3) What is the relationship between charset and collation?
1) One charset may have many collations.
# Command for show collation show collation # Command for show collation for utf8 show collation like 'utf8%' # utf8 has about 40 collations.
2) Default collation for utf8 is 'utf8_general_ci': Is case insensitive.
'utf8_bin': Order by binary code.(ASCII Code)
# Create table create table temp2(name varchar(11)) charset utf8 collate=utf8_bin; # Insert data insert into temp2 values('a'), ('B'), ('c'), ('D'); # Order data select * from temp2 order by name asc; +------+ | name | +------+ | B | | D | | a | | c | +------+
相关推荐
-DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE...
> -DDEFAULT_COLLATION=gbk_chinese_ci \ > -DENABLED_LOCAL_INFILE=ON \ > -DWITH_INNOBASE_STORAGE_ENGINE=1 \ > -DWITH_FEDERATED_STORAGE_ENGINE=1 \ > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ > -DMYSQL_UNIX_...
### Linux环境下MySQL 5.5.10的安装与配置详解 #### 一、环境准备与cmake安装 为了在Linux环境下顺利安装MySQL 5.5.10,首先需要确保具备以下条件: 1. **操作系统**: 假设当前环境为RHEL 5 (Red Hat Enterprise ...
-DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/oradata/mysql/var \ -DMYSQL_TCP_PORT=3306 # 编译并安装 make && make...
非科班出身程序员刷题 /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 ...跳过权限验证登录MySQL ...mysql.user ...charset_name ...collation_name -- 查看已有库 show data
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-charset=utf8 --with-collation=utf8_general_ci --with-secure-auth --with-zlib-...
编译安装 MySQL:`./CONFIGURE --WITH-CHARSET=GBK --WITH-COLLATION=GBK_CHINESE_CI --WITH-EXTRA-CHARSET=GB2312,BIG5,UTF-8,BINARY,ASCII --PREFIX=/USR/LOCAL/MYSQL` 配置 MySQL 编译参数,指定支持的字符集和...
-DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=all \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -...
-DDEFAULT_COLLATION=utf8_general_ci ``` 以上配置项中包含了MySQL的各种特性启用与禁用,例如MyISAM存储引擎、InnoDB存储引擎、内存表引擎、读取行功能等。 4. **编译安装MySQL**:完成配置后,执行`make && ...
-DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ -DMYSQL_USER=mysql \ -DWITH_DEBUG=0 ``` 这里指定了 MySQL 的安装路径、数据目录、Unix socket 文件位置等参数,并...
DMYSQL_DATA=/home/mysql/data -DMYSQL_UNIX_ADDR=/home/mysql/data/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_...
cmake ../mysql-8.0.33 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci ``` 7. **编译和安装**: 现在可以编译和安装MySQL了: `...
./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=latin1 ``` 5. 执行`make`命令来编译源代码: ``` make ``` 6. 完成编译后,执行`make...
MySQL的字符集支持主要涉及两个方面:**字符集(Character set)**和**排序方式(Collation)**。字符集定义了如何存储和表示不同的字符,而排序方式则决定了如何比较这些字符。 MySQL对字符集的支持非常细致,可以...
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci` - `CMAKE_INSTALL_PREFIX`用于指定安装路径。 - `DEFAULT_CHARSET`和`DEFAULT_COLLATION`用于设置默认...
./configure --prefix=/usr/local/mysql --with-perl --with-charset=utf8 --with-collation=utf8_general_ci ``` 3. 编译和测试: ``` make make test ``` 4. 安装MySQL: ``` make install ``` 5. ...
`-DEFAULT_CHARSET=gbk`和`-DEFAULT_COLLATION=gbk_chinese_ci`指定了默认的字符集和排序规则;其他选项则开启了不同的存储引擎。 ##### 4. 编译与安装 ``` # make # make install ``` 通过`make`命令进行编译,...