1024programmer Mysql How to change mysql default encoding to UTF8

How to change mysql default encoding to UTF8

The method of changing the default encoding of mysql to UTF8: first add [default-character-set=utf8] in the client field; then add [character-set-server=utf8] in the mysqld field; finally restart The mysql service takes effect.

Related learning recommendation: mysql tutorial

The method of changing the default encoding of mysql to UTF8 :

windows:

a. WIN+R net stop mysql close mysql service

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

UBUNTU:

**  sudo vim /etc/mysql/my.cnf **Enter

Perform the following operations:

1. In [client ] field, add default-character-set=utf8, as follows:

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

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

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

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

After the modification is completed, service mysql restart will take effect after restarting the mysql service. Note: There is a difference between the [mysqld] field and the [mysql] field. No one has reported this on the Internet.

Note: show variables like 'character%' can view the mysql encoding method, after the modification is completed, it looks 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/ |
 +--------------------------+----------------------  ------+

Want to learn more programming learning, please pay attention to the PHP training column!

The above is the detailed content of how to change the default encoding of mysql to UTF8. For more information, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-to-change-mysql-default-encoding-to-utf8/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索