1. The backdrop of the pit
Previous development has been used in the SQL Server database, recently received an old project from the company, the my SQL database used to do a large part of the function, and now customers are required to carry out the migration of the original program and database server. The product manager gives an estimated timeFor 2 days, the new server needs to install the environment. In the MySQL 5.7 version installed on the server, the program deployment is basically smooth, the product manager enters the test stage and finds a strange thing. All the fuzzy query functions, including the Chinese, can not be queried to the data. Start a step by stepCause, code error is screened and excluded. Later, it was found that the character set of my SQL database was set up.
Two. Setting of environment variables
Since the my SQL database is used for the first time, and most operations require configuration of the environment variables, the following configuration is first performed on the server. The following steps are configured:
(1), my SQL installation path
Find the installation path of my SQL, by default: C:\Program Files\MySQL\MySQL Server 5.7\bin directory, and then copy
(Two), open the environment variable
Through the control panel, find the path in the environment variable settings, click Edit, there is a new on the right side, just paste the path just now.
(Three) reboot the my SQL service with the DOS command
net stop mysql57 --Open service net start mysql57 --Temporarily Out of Service
This page shows that our configuration has been completed.
Three, set of character sets
(1), default character set
MySQL After the default installation of the database, the default character set as shown below, this problem is relatively simple, but the solution is a more waste of time, blood and tears lessons. We first querying the current character set from the following statement:
show variables like 'character%'; --Query character set
(Two) set the character set
We know where the problem lies, and now we are trying to solve it. It is a waste of time to query most of the methods on the Internet. Now the following methods are summed up
(1)Find the my.ini file
The most simple and violent method is to find the my server service, copy the my.ini path, and find it in the corresponding disk symbol.
(2)Modify the my.ini file
Paste the following content into the bottom of the my.ini file, save
[mysqld] character-set-server=utf8 collation-server=utf8_general_ci [mysql] default-character-set = utf8 [mysql.server] default-character-set = utf8 [mysqld_safe] default-character-set = utf8 [client] default-character-set = utf8
(3)Restart my SQL service and check the modification effect
Remember to restart the my SQL service before it can take effect. Restart: a command line restart, as mentioned above; a service manager startup is shown below.
Now is the result we want, so far, the pits are over!