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.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
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!