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

Mysql database coding

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. View the current database code

show variables like '%character%';

You can see the default character_set_database encoding format, here you can see that the default is latin1.

Modify the encoding method of a database and enter it under the database, such as greenpass.

Modified to GB2312 encoding mode:

mysql>use greenpass;

mysql>alter database greenpass character set gb2312;

mysql>show variables like 'character_set_database';

Modified to utf-8 encoding mode:

mysql> alter database greenpass character set UTF8;

mysql> flush privileges;

mysql>show variables like 'character_set_database';

II. Modify the configuration file

- Add the following under the [mysqld] label:

default-character-set = utf8

character_set_server = utf8

Note: If something like "default-character-set=GBK" already exists under this label, just modify it.

--Add a line under the [mysql] tag

default-character-set = utf8

--Add a line under the [mysql.server] tag

default-character-set = utf8

--Add a line under the [mysqld_safe] label

default-character-set = utf8

--Add a line under the [client] label

default-character-set = utf8

Restart the MySQL service.

3. Database code verification

After entering mysql, execute: show variables like "% character %";

The result should look something like this:

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

If there are still codes other than utf8, check the configuration file, or use the mysql command to set:

set character_set_client = utf8;

set character_set_server = utf8;

set character_set_connection = utf8;

set character_set_database = utf8;

set character_set_results = utf8;

set collation_connection = utf8_general_ci;

set collation_database = utf8_general_ci;

set collation_server = utf8_general_ci;

In addition:

To create a database, you can use the following command:

create database app_relation character set utf8;

use app_relation;

source app_relation.sql;

The command to modify the database encoding is:

alter database app_relation character set utf8;

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