Set MySQL database encoding to UTF-8

Source: Internet
Author: User
Tags mysql command line

1. Edit the MySQL configuration file

MySQL configuration file under Windows generally under the system directory or in the MySQL installation directory named my.ini, can be searched, Linux is generally/etc/my.cnf

--Add the following to the [Mysqld] tab:

Default-character-set = UTF8

Character_set_server = UTF8

Note: If something like "DEFAULT-CHARACTER-SET=GBK" already exists under this tab, just modify it.

--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

2. Restart 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

3. View Settings results
Log on to the MySQL command line client: Open command line

Mysql–uroot–p Enter

Enter password

Execute after entering MySQL: Show variables like "% character%";
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;

Other than that:

You can use the following command when you create a database:

Create database app_relation character set UTF8;

Use app_relation;

SOURCE App_relation.sql;

The commands to modify the database encoding are:

ALTER DATABASE app_relation character set UTF8;

Set MySQL database encoding to UTF-8

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.