Permanently modify MySQL character encoding

1. Log in to the database and view the database character encoding table:
View encoding SQL:
SHOW VARIABLES LIKE'character%';
show variables like'char%';
Insert picture description here

2. Exit the database, modify the mysql configuration file, and change the character encoding of the database:
vi /etc/my.cnf
Insert picture description here
3. After entering the configuration file, add the following code, then save and exit

default-character-set=utf8
character-set-server=utf8
collation-server=utf8_unicode_ci

Insert picture description here

4. Restart the database service, log in to the database: systemctl restart mysql.service
Insert picture description here
Note:
start mysql command: service mysql start
stop mysql command: service mysql stop
view mysql status: service mysql status
restart mysql: service mysql restart

5. Check the coding table again to confirm that the modification is complete:
SHOW VARIABLES LIKE'character%';
Insert picture description here

Guess you like

Origin blog.csdn.net/w13716207404/article/details/103326953