MySQL character encoding

Source: Internet
Author: User

First, edit the MySQL configuration file

MySQL configuration file:

Under Windows generally under the system directory or in the MySQL installation directory named My.ini

Linux is generally/etc/my.cnf

--Add three lines under the [Mysqld] tab

Default-character-set = UTF8

Character_set_server = UTF8

Lower_case_table_names = 1//table name is case insensitive (this is not encoded)

--Add a line under the [MySQL] tab

Default-character-set = UTF8

--Add a line under the [Mysql.server] tab

Default-character-set = UTF8

--Add a line under the [Mysqld_safe] tab

Default-character-set = UTF8

--Add a line under the [Client] tab

Default-character-set = UTF8

Second, restart the MySQL service

Windows can operate in Service Manager, or you can use the command line:

net stop MySQL Enter

net start MySQL return

The service name may not necessarily be MySQL, please press your own settings

Linux is now using service MySQL restart

If a startup failure occurs, check that the configuration file has no setup errors

Third, view settings results

Log on to the MySQL command line client: Open command line

Mysql–uroot–p Enter

Enter password

Enter MySQL after execution: show variables like "%char%";

The results should look similar to the following:

| character_set_client | UTF8 |

| character_set_connection | UTF8 |

| Character_set_database | UTF8 |

| Character_set_results | UTF8 |

| Character_set_server | UTF8 |

| Character_set_system | UTF8 |

| Character_sets_dir | /usr/share/mysql/charsets/|

If the encoding is still not UTF8, check the configuration file or use the MySQL command to set it up:

Set character_set_client = UTF8;

Set character_set_server = UTF8;

Set character_set_connection = UTF8;

Set character_set_database = UTF8;

Set character_set_results = UTF8;

Set collation_connection = Utf8_general_ci;

Set collation_database = Utf8_general_ci;

Set collation_server = Utf8_general_ci;

Some of the above commands are only valid for the current login, so they are not useful.

Iv. building a library to import data

Before importing the SQL script file, make sure that the script file and the content format are in UTF-8 encoded format.

Log in to MySQL command line with the above method, use the library name to enter the corresponding database

Set names UTF8;

Source SQL script file name;

V. Program connection string (this item is not related to MySQL settings, and is used for program development)

For older JDBC versions of drivers, the connection character creator can use a similar format:

Jdbc:mysql://127.0.1:3306/test?useunicode=true&characterencoding=utf-8

MySQL character encoding

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.