How to solve the problem of garbled code in MySQL database
This article introduces the relevant knowledge of "how to solve MySQL database garbled code problem". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Add charset setting when creating database/table
1. Building a library
2. Table construction
client display
locale
Confirm whether the locale setting is UTF8 mode. Generally, there is no problem on the server side, but only on the client side. Or some clients have problems, often there are problems with client display settings.
mysql setup
Use show variables like ' %character%' to confirm that modifying character_set_database and character_set_server in general can modify settings only in the current session
Use mysql command to set character set within session scope
1. Local settings
It only works in the current session and is set as follows:
2. Global settings
Multiple sessions function in the following ways:
Of course, session mode will be invalid after database restart, and it needs to be persisted. The same settings should be set in mysql's configuration file my.cnf.
In this way, when creating a database or database table, the default is the specified utf8
If it is purely a display problem, it is also likely that character_set_results is set to display in many cases.
Use show variables like ' %character%' to confirm, and if the settings are incorrect, resolve them as follows
database data export import
1. Database data export
Database export using mysqldump generally uses the following command
If garbled, you can add the following Option
mysqldump -u username-p user password--default-character-set=utf8 database name> mysqlbackup.sql
If you have blob types, you need to export mysqldump using the hex-blob option
2. Database data import
If there is a problem when importing, you can also consider adding character level settings.
mysql -u user name-p user password--default-character-set=utf8 database name