Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set character set in MYSQL

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report