Home > Database > Mysql Tutorial > body text

How to change mysql default encoding to UTF8

coldplay.xixi
Release: 2020-09-11 15:57:56
Original
4281 people have browsed it

How to change the default encoding of mysql to UTF8: first add [default-character-set=utf8] to the client field; then add [character-set-server=utf8] to the mysqld field; finally restart The mysql service will take effect.

How to change mysql default encoding to UTF8

Related learning recommendations: mysql tutorial

Change the default encoding of mysql Method for UTF8:

windows:

a. WIN R net stop mysql Close the mysql service

b. Copy my-dafault .ini, rename it to my.ini, enter it

UBUNTU:

** sudo vim /etc/mysql/my.cnf **进入
Copy after login

Perform the following operations:

1. Add default-character-set=utf8 in the [client] field, as follows:

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
Copy after login

2. Add character-set-server=utf8 in the [mysqld] field, as follows:

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8
Copy after login

3. Add default-character-set=utf8 in the [mysql] field, as follows:

[mysql]
no-auto-rehash
default-character-set=utf8
Copy after login

After the modification is completed, service mysql restart restarts the mysql service to take effect. Note: There is a difference between the [mysqld] field and the [mysql] field. No one has reported this online.

Note: show variables like 'character%' can view the mysql encoding method. After the modification is completed, it will look like this:

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
Copy after login

If you want to know more about programming learning, please pay attention to the php training column!

The above is the detailed content of How to change mysql default encoding to UTF8. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template