MySQL View database encoding

Source: Internet
Author: User
Tags mysql version mysql view

MySQL default encoding is Latin1, does not support Chinese, to support noon need to change the default code of the database to GBK or UTF8.

1, need to log in as root user can view the database encoding method (the command logged in as root User: >mysql-u root–p, then two times to enter the root user's password), to view the database encoding command: >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/|
+--------------------------+----------------------------+ from the above information, the database is encoded as latin1, which needs to be modified to GBK or UTF8; character_set _client for client-side encoding, character_set_connection for connection use, encoding for character_set_database database, character_set_results result set encoding ; character_set_server database server encoding, as long as the above four uses the same encoding method, there will be no garbled problem. Another command to view the database encoding: >show variables like ' collation% '; 2, Linux system, modify the MySQL database default encoding step is: ü Stop MySQL Run
/etc/init.d/mysql start (stop) to start and stop the server ümysql the main profile is MY.CNF, the general directory for/etc/mysqlvar/lib/mysql/Place is the database table folder, where MySQL is equivalent to WI Ndows under MySQL Date folder u when we need to modify the MySQL database default encoding, need to edit the my.cnf file for encoding modification, under Linux to modify the MySQL configuration file my.cnf, file location default/etc/my.cnf file

Locate the client configuration [clients] below to add
Default-character-set=utf8 default character set is UTF8
When you find [mysqld] Add
Default-character-set=utf8 default character set is UTF8
init_connect= ' Set NAMES UTF8 ' (set to use UTF8 encoding when connecting to MySQL database, so that the MySQL database runs as UTF8)

After modification, restart MySQL, re-query the database code can be found to change the encoding: >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/|
+--------------------------+----------------------------+

This method is also valid for the standard MySQL version, and for/etc/my.cnf files, you need to my-large.cnf a copy of the Mysql/support-files folder from CP to/ETC/MY.CNF 3, The MySQL database can be removed and reinstalled in the Windows system, and can be set up directly with the MySQL server Instance Config Wizard during installation 4, when the MySQL database server already has data that is not suitable to remove the reload, You can specify how the database is encoded individually. The way MySQL specifies encoding is very flexible and diverse, you can specify the table-level encoding, row-level encoding, and even specify the field-level encoding.  The following example shows two ways to specify the encoding when creating a database: 1) Create db ms_db CHARACTER SET UTF8 COLLATE utf8_general_ci;2) create exists netctoss default Character set Utf8;5, if you are using an external access method, you can determine the requested encoding format in the connection such as: Jdbc:mysql://localhost:3306/mysql? Useunicode=true&characterencoding=utf-8 (Note: Do not appear any spaces, otherwise error) 6, execute script: Specify encoding format set names GBK (note, not UTF-8) Can be modified before execution: After execution: from the execution of the command before and after the set names GBK can only modify Character_set_client, character_set_connection, character_set_results encoding mode , and this modification is window-level, only valid for this window, open another window modification is invalid. It can also be found that the underlying encoding of the database has not changed, and after inserting the data, it is persisted in UTF8 encoding mode.

MySQL View database encoding

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.