General installation of the MySQL program process, there is a step to choose MySQL default encoding format, Cheng think Latin1 encoding format, of course, you can choose the third option, manually select GBK or UTF8 encoding format to support Chinese data. Such as:
Now that the problem comes out, after the installation is complete, you want to change the default MySQL encoding format (so that every time you create a new database to specify its encoding format of trouble), what to do?
1: How to view MySQL-related encoding format default values
In cmd, enter the command "mysql–u root–p" to connect to the MySQL database as root
Then there are two ways to view the encoding format:
1)show variables like ' character% ';
2)show variables like ' collation% ';
2: Since you can use the command to view, of course, can also be modified with the command
A little explanation:
Character_set_client: Client encoding method;
Character_set_connection: The encoding used when establishing the connection;
Character_set_database: Encoding of the database;
Character_set_result: Encoding of the result set;
Character_set_server: Encoding of the database server;
I: Execute command:set NAMES ' UTF8 ';
This command is equivalent to executing the following three commands:
SET character_set_client = UTF8;
SET character_set_results = UTF8;
SET character_set_connection = UTF8;
However, the encoding format of this setting is valid only for the current Connection (window), that is, another DOS window is connected to the MySQL database for viewing, the encoding format is unchanged.
II: Database, table, field, either set its default encoding format at creation time, or modify it later [excerpt from Easybean's blog]
1) Create database dbname character set UTF8;
ALTER DATABASE dbname character set UTF8;
2) CREATE TABLE Tname (...) default Charset=utf8;
ALTER TABLE type character set UTF8;
3) CREATE table Tname (flag_deleted enum (' Y ', ' n ') character set UTF8 NOT null default ' N ')
ALTER TABLE type modify TYPE_NAME varchar (character set UTF8;
3: Relatively good, but also suggested, but the final pressure of the grinding of the axis of the method of the debut, as follows ...
Modify the MySQL configuration file My.ini.
In the window system, the MySQL configuration file is in the MySQL installation directory under the My.ini file, but may be installed after the completion, in the directory of wood has My.ini files, but the following these files:
At this time, you can download a My.ini file on the internet and put it in the directory, or in the C: \ProgramData\mysql\mysql Installer directory is
Choose one of the versions of My-template-x.x.ini renamed to My.ini, which can be placed in the installation directory. As for the details of the My.ini in the specific configuration can be.
My.ini configuration file modification details [from Easybean's blog]:
I: Under the [mysqld] tab, add
Default-character-set=utf8
Character_set_server=utf8
Lower_case_table_names=1//table name is case insensitive (this is not encoded)
II: Under the [MySQL] tab, add
Default-character-set=utf8
III: Under the [mysql.server] tab, add
Default-character-set=utf8
IV: Under the [mysql_safe] tab, add
Default-character-set=utf8
V: Under the [Client] tab, add
Default-character-set=utf8
4: Execute in DOS window
net stop Mysqlservice //shutdown MySQL Service
net stop Mysqlservice //start MySQL service
Then look at the MySQL default encoding format, whether to change the success! Changed successfully, Kong Higong ^_^, unsuccessful I again explore one or two, the following left a problem, study together ha! (Last trick you can reload MySQL and then set it up in the installation step)
Note:
1: string when connecting MySQL database, design the encoding type as shown below
Jdbc:mysql://127.0.0.1:3306/dbname?useunicode=true&characterencoding=utf-8
What encoding formats are supported by 2:mysql, view%mysql%\share\charsets\index.xml
3:mysql configuration file load order [excerpt from [email protected]]
C:/windows/my.cnf-->c:/windows/my.ini-->c:/my.cnf-->c:/my.ini--> $installdir/my.ini (%MySQL_HOME%/ My.ini)-->defaults-extra-file=path