MySQL set the default encoding for the database

Source: Internet
Author: User
Tags mysql in
When installing MySQL, if you do not choose the encoding method, then the system will default to select Latin1 encoding, in the console window of MySQL input show variables like ' char% ' can view the database system's default encoding set, as follows:



We can see that the default encoding of the system is Latin1 encoding, Latin1 is iso-8859-1 alias, some environment writing Latin-1. The ISO-8859-1 encoding is single byte encoded and backwards compatible with ASCII. Chinese encoding is not supported, if you do not explicitly specify the encoding method when creating a database or a table, the database will be encoded by default, and then you will be garbled when inserting Chinese data. But how can we manually modify the default encoding of a database if we have to manually specify the encoding method every time we build a database or a key table?

1. Close the MySQL service, manually stop the MySQL service in the service, or enter net stop MySQL in the cmd window.

2. Then go to your MySQL installation directory to find the My.ini file, if it is an initialized database, then change the MY-DEFAULT.COF to MY.COF, then find the file [MySQL], add the following two lines in its next line
Character_set_server=gbk
init_connect= ' SET NAMES gbk '
or directly in the My.ini directly add the line.
As follows:


3. Save, then reboot, check again and we can see that the system default encoding has changed.


MySQL set the default encoding for the database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.