Chinese garbled problem
When I first contacted mysql, the first thing that made me uncomfortable was mysql has many related solutions on Baidu.However, as a personal victim, I think it is necessary to post my feelings :
1.About mysql character set processing
MySQL uses binary and non-binary character formats when identifying data.The former is mainly used to identify pictures and sounds, the latter completes all the remaining functions, and for the latter, there is a problem of character set settings.
We know that the database is made by foreigners.They did not consider the encoding format when designing it.In order to support their own language in modern computer-popular countries, they have introduced their own encoding format.The following uses the mysql command List all codes in the world:
GBK, gb2312 and big5 are Chinese codes
GBK: Supports more than 21000 Chinese characters, including simplified and traditional, occupying 2 bytes
gb2312: Support more than 6,700 Chinese characters, occupying 2 bytes
big5: Support traditional character set, mainly support the characters from Hong Kong and Taiwan, traditional, more than 13000 Chinese characters, 2 bytes
In order to unify the format, the International Organization for Standardization created the UTF8 encoding, which is a format of unicode encoding, called the universal code, which supports specific solutions for all languages in the world:
First use the command line to view the character set:
Explain the principle of garbled code:
When we link to the mysql database, we actually have to go through the following steps:
Client->Link side->Database field side->Return side
It's in the map above
In these steps where the garbled code problem occurs, as long as one of the steps goes wrong, garbled characters will appear
When we use the program to link the mysql database externally, the client is our program software, so we need to set the client to GBK or gb2312, set it to UTF8 or GBK when linking, and set the database to gbk or utf8
Return to set to GBK, so that Chinese garbled characters will generally not appear
As shown in the figure below:
You can set it through the command line:
If you do not consider the injection problem, you can take the following methods:
This command sets the client, connection and return ends to be GBK;
You can also set one by one:
Set the character set when creating the library:
create database mydatabase default character set utf8;
Specify the character set of the table when creating the table:
create table user(name char(30) character set gbk) default character set gbk;
There are also the following settings:
Set the result set:
Set the connection character set:
Because we are now in the learning stage, regardless of the memory capacity issue, set it to UTF8 uniformly.If your program only supports Chinese, it is best to choose GBK encoding for your works for external distribution.....
If you follow the above method and still find that there is a problem with the running of the program, please check whether your program is also UNICODE encoded, I used to be because of this reason.
Starting service problem
I now assume that you have established a login user and password when installing the mysql database (mysql is free and can be downloaded from the official website)
The installed mysql database runs automatically after booting.If your mysql database service is accidentally shut down, you can take the following solutions:
Option 1: Right-click on the desktop computer icon,
Management-> Services and Applications-> Services Then find the mysql service item in the list, click the right mouse button to execute "Start", of course you can also stop the mysql service here.
Open cmd (command line) and execute the command:
Note: mysql55 here is the MYSQl database service name on my PC, and it must be executed according to the database service name of your PC...This service name is the service name you specified when installing the mysq database.