Home >Database >Mysql Tutorial >How to change mysql encoding to utf8

How to change mysql encoding to utf8

WBOY
WBOYOriginal
2022-03-01 16:35:1710984browse

How to change mysql encoding to utf8: 1. Open and modify the mysql configuration file "my.ini"; 2. Add "default-character-set = utf8" under the "mysqld" label; 3. Re- Just start the mysql service.

How to change mysql encoding to utf8

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to change mysql encoding to utf8

1. Edit the configuration file of MySql

The configuration file of MySql under Windows is usually in the system directory or in The name of the MySql installation directory is my.ini, which can be searched. Under Linux, it is usually /etc/my.cnf

--Add the following content under the [mysqld] tag:

default-character-set = utf8
character_set_server = utf8

Note: If there is already content similar to "default-character-set=GBK" under this tag, 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] tag

default-character-set = utf8

-- Add a line under the [client] tag

default-character-set = utf8

2. Restart the MySql service

Windows can be found in the service To operate in the manager, you can also use the command line:

net stop mysql Enter

net start mysql Enter

The service name may not necessarily be mysql, please press your own Settings

Under Linux, you can use service mysql restart

If startup fails, please check if there are any setting errors in the configuration file

3. Check the setting results

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

mysql –uroot –p Enter

Enter the password

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

In addition:

You can use the following command when creating a database:

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;

Recommended learning: mysql video tutorial

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

Statement:
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