Character encoding settings for MySQL database

Source: Internet
Author: User


Default login after MySQL show variables like '%character% ', appeared

MySQL "Show variables like '%character% ';

+--------------------------+----------------------------+

| variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | Latin1 |

| character_set_connection | Latin1 |

| Character_set_database | Latin1 |

| Character_set_filesystem | binary |

| Character_set_results | Latin1 |

| Character_set_server | Latin1 |

| Character_set_system | UTF8 |

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

+--------------------------+----------------------------+

1. Find the MySQL configuration file, copy to the ETC directory, the first step is very important

Use the Find command to locate the CNF file. Remember not to look for my.cnf because it does not necessarily exist, but should find *.cnf.

[Root@linuxserver classes] Find/-iname *.cnf-print

/usr/share/doc/mysql-server-4.1.12/my-medium.cnf

/usr/share/doc/mysql-server-4.1.12/my-huge.cnf

/usr/share/doc/mysql-server-4.1.12/my-innodb-heavy-4g.cnf

/usr/share/doc/mysql-server-4.1.12/my-large.cnf

/usr/share/doc/mysql-server-4.1.12/my-small.cnf

/usr/share/texmf/web2c/mktex.cnf

/usr/share/texmf/web2c/texmf.cnf

/usr/share/texmf/web2c/fmtutil.cnf

/usr/share/texmf/tex/jadetex/jadefmtutil.cnf

/usr/share/ssl/openssl.cnf

After you find it, copy one out.

Cp/usr/share/doc/mysql-server-4.1.12/my-large.cnf/etc/my.cnf

2. Open MY.CNF Modify Code

Vi/etc/my.cnf

Increase Default-character-set=utf8 under [client]

Increase the Default-character-set=utf8 under [mysqld]

At the same time, plus init_connect= ' Set NAMES UTF8 ' (set to connect the MySQL database with the UTF8 encoding, so that the MySQL database to run UTF8)

Restart MySQL, execute: sudo/etc/init.d/mysql stop then sudo/etc/init.d/mysql start

MySQL "Show variables like '%character% ';

+--------------------------+----------------------------+

| variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | UTF8 |

| character_set_connection | UTF8 |

| Character_set_database | UTF8 |

| Character_set_filesystem | binary |

| Character_set_results | UTF8 |

| Character_set_server | UTF8 |

| Character_set_system | UTF8 |

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

+--------------------------+----------------------------+

Even if you do the above changes if the direct database to create a table, and then stored in Chinese, will be taken out of the question mark. The solution is:

When you create a database, you indicate that the default character set is UTF8, such as:

Create DATABASE test default character set UTF8;

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.