How To Change The Base Encoding

Table of contents:

How To Change The Base Encoding
How To Change The Base Encoding

Video: How To Change The Base Encoding

Video: How To Change The Base Encoding
Video: Как компьютер кодирует символы (кодировки, encodings) 2024, May
Anonim

The Mysql database management system, starting from version 4.1, supports working with encodings. The main problems with them arise when connecting a database with Php. In this case, the encoding of the content of the base and the connection must match.

How to change the encoding of the base
How to change the encoding of the base

Instructions

Step 1

Note that a common cause of problems with Mysql is that the default encoding for databases is set to latin1. Most of the connected clients are also configured for it, you enter data and view the results using it too. Although this encoding correctly displays the Cyrillic alphabet, the codes of the symbol table in it do not correspond to the real Cyrillic characters. Therefore, searching and sorting data can produce completely unpredictable results.

Step 2

Change the database encoding to one that correctly displays Cyrillic characters, for example, utf-8 or cp1251. To do this, convert the data from Latin1 encoding to cp1251. Do not use simple data conversion, as the character codes are incorrect. Therefore, you need to get rid of their encoding binding. To do this, convert the data and character type to binary data. Use the query Alter table "Enter table name" t1 change c1 c1 blob.

Step 3

Run a query to change the encoding of the Mysql database, for this use the following example: Alter table "Enter the table name" t1 change c1 c1 text chatacter set "Enter the name of the desired encoding, for example, cp1251". Not a single byte of data is physically changed, but the rule of forming characters changes. Subsequently, to change the database encoding, you can use a simple data conversion query.

Step 4

Please note that when you change the table encodings in a field that contains indexes, you must delete them and recreate them, i.e. rebuild in all database tables. When switching to encoding, make sure visual clients support unicode. For example, the SQLyog client incorrectly displays the contents of tables that store data in utf-8 encoding.

Recommended: