Get the App
SLTechnology News&Howtos  ›  Database  › 

How to set character set in MYSQL

Shulou Source: shulou.com Published: 2022-05-31 21:06:13 09月13日 Update

Today, I will talk to you about how to set the character set in MYSQL. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Server level:

Set up in my.cnf

Mysql > show variables like 'character_set_server'

+-+ +

| | Variable_name | Value |

+-+ +

| | character_set_server | utf8 |

+-+ +

Database level:

Mysql > show variables like 'character_set_database'

+-+ +

| | Variable_name | Value |

+-+ +

| | character_set_server | utf8 |

+-+ +

Table level:

Create table test (name varchar (100)) charset = utf8 collate=utf8_bin

Mysql > show create table test

+- -+

| | Table | Create Table |

+- -+

| | test | CREATE TABLE `test` (

`name` varchar (100) COLLATE utf8_bin DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |

+- -+

Field level:

Create table test (name varchar (100) charset utf8 collate utf8_bin)

The character set of the database is utf8, how to enter Chinese characters on linux terminal.

1. Set the encoding format to utf8 in linux terminal

two。 Set the environment variable to utf8

LANG= "zh_CN.utf8"

LC_ALL= "zh_CN.utf8"

LANG= "en_US.utf8"

LC_ALL= "en_US.utf8"

Export LANG

Export LC_ALL

3. Set the mysql connection property to utf8

Set names utf8

Here are the test results:

1. Set up a test table.

Create table test (name varchar (30))

two。 Edit sql statement script

More test.sql

Set names utf8

Insert into test values ('Chinese')

Insert into test values ('Chinese II')

Insert into test values ('character set')

3. Execute sql

Mysql-uroot-p-- database=mydb < test.sql

Enter password:

Mysql-uroot-- database=mydb-e'select * from test'

+-+

| | name |

+-+

| | Chinese |

| | Chinese two |

| | character set |

+-+

After reading the above, do you have any further understanding of how to set the character set in MYSQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Characters character sets Chinese content data databases tests variables fields properties more servers formats environment knowledge articles results coding scripts industries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information Docker Shulou Tech Info Redmi