--default-charset ), and starting from version 4.1 the developers added the ability to define encoding at different levels of the DBMS hierarchy (for the entire server, database, tables, columns).--with-charset and --with-collation :./configure --with-charset = cp1251 --with-collation = cp1251_general_ci
--character-set-server and --collation-server parameters:mysqld --character-set-server = cp1251 --collation-server = cp1251_bin
CREATE DATABASE dbname DEFAULT CHARACTER SET cp1251 COLLATE cp1251_bin;
CREATE TABLE tblname (col INT) DEFAULT CHARACTER SET cp1251 COLLATE cp1251_bin;
CREATE TABLE tblname (<br> column1 varchar (255), <br> column2 varchar (255) CHARACTER SET cp1251 COLLATE cp1251_general_ci <br>) DEFAULT CHARACTER SET cp1251 COLLATE cp1251_bin;
SHOW CREATE operator:mysql> SHOW CREATE TABLE tree_nodes; | tree_nodes | CREATE TABLE `tree_nodes` (<br> ... <br>) ENGINE = InnoDB <b> DEFAULT CHARSET = cp1251 COLLATE = cp1251_bin </ b> |
character_set_client - indicates the encoding in which data will be received from the client;character_set_connection - specifies in which encoding the data received from the client should be converted before executing the request;collation_connection - specifies how to compare among themselves the lines in the queries;character_set_results - indicates to the server that it is not necessary to recode the results of the query into a specific encoding before being issued to the client. mysql_query ("SET character_set_client = 'cp1251'"); <br> mysql_query ("SET character_set_connection = 'cp1251'"); <br> mysql_query ("SET character_set_results = 'cp1251'"); If the query and the data in the database are in the same encoding, and no transcoding of the result is required, then instead of setting character_set_client, character_set_connection, character_set_results, it is enough to execute: mysql_query ("SET NAMES 'cp1251'"); To view the default values ​​of these variables, you can use the SHOW VARIABLES operator:SHOW VARIABLES LIKE 'character_set%';
Source: https://habr.com/ru/post/10983/
All Articles