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 UTF-8 Encoding in MYSQL Database

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

Share

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

It is believed that many inexperienced people don't know what to do about how to set up UTF-8 code in MYSQL database. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

First, check the current database code.

Use the statement:

Show variables like'% character%'

Show variables like'%collation%'

Second, if this is not the case, you need to set the mysql encoding to utf-8. The specific steps are as follows:

If "MySql Sever Instance Configuration Wizard" is installed when installing MySQL, you only need to start

The program can be set up accordingly. As described in the screenshot below, the default encoding needs to be set to utf8

If you don't have the program, you need to modify the mysql code manually.

1. Edit the configuration file of MySql

The configuration file Windows of MySql is usually called my.ini under the system directory or the installation directory of MySql. You can

Search, usually / etc/my.cnf under Linux

-- add the following under the [mysqld] tag:

Default-character-set = utf8

Character_set_server = utf8

Note: if something like "default-character-set=GBK" already exists under this tag, you just need to 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] tag

Default-character-set = utf8

-- add a line under the [client] tag

Default-character-set = utf8

2. Restart the MySql service

Windows can be operated in the service manager or by using the command line:

Net stop mysql enter

Net start mysql enter

The service name may not be mysql. Please press your own setting.

You can use service mysql restart under Linux.

If startup failure occurs, check the configuration file for setting errors

3. View the results of the settings

Log in to the MySql command line client: open the command line

Mysql-uroot-p enter

Enter password

Execute: show variables like "% character%" after entering mysql

The display 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 is still a code that is not utf8, check the configuration file, or you can set it using the mysql command:

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:

You can use the following command when establishing a database:

Create database app_relation character set utf8

Use app_relation

Source app_relation.sql

The command to modify the database code is:

Alter database app_relation character set utf8

1. SET NAMES 'utf8'

It is equivalent to the following three instructions:

SET character_set_client = utf8

SET character_set_results = utf8

SET character_set_connection = utf8

After reading the above, have you mastered how to set the UTF-8 code in the MYSQL database? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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