How to modify the default classification of MySQL character set encoding under Linux

Source: Internet
Author: User

The default character set for MySQL installed is latin1, in order to change its character set to user-required (such as UTF8), it must change its relevant configuration file, because the Linux under the default installation directory of MySQL under different files; not in the same directory as Windows, Just modify the My.ini file, and then it will take effect; So let's look at Linux MySQL database files, configuration files and command files in separate directories:
1, the database directory, the database files that are created in this directory
/var/lib/mysql/

2. Configuration file (Mysql.server command and configuration file location)
/usr/share/mysql

3, related commands (such as MySQL mysqladmin, etc.)
/usr/bin

4. startup script (e.g. MySQL startup command)
/etc/rc.d/init.d/


Viewing the default character set
#mysql-U root-p
# (Enter password)
Mysql> Show variables like ' character_set% ';
+--------------------------+----------------------------+
| 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/|
+--------------------------+----------------------------+
To modify a character set:
1. Find out if there are my.cnf files in the/etc directory;
#ls-L | grep my.cnf (Find out if a my.cnf file exists in/etc)
2. If there is no need to copy from/usr/share/mysql, one to/etc, there are five suffix. cnf files in the/usr/share/mysql directory, respectively my-huge.cnf MY-INNODB-HEAVY-4G.CNF MY-LARGE.CNF my-medium.cnf my-small.cnf, from which I randomly copy one to/etc directory and change it to my.cnf file, I chose MY-MEDIUM.CNF:
#cp/usr/share/mysql/my-medium.cnf/etc/my.cnf
3. Modify the My.cnf file, add Default-character-set=utf8 ([client] [mysqld] [MySQL] in three places in the file.
#vi/etc/my.cnf
The changes are as follows: (red for added parts)
[Client]
#password = Your_password
Port = 3306
Socket =/var/lib/mysql/mysql.sock
Default-character-set=utf8 (verified as if this step does not have to be set to achieve the effect)
[Mysqld]
Port = 3306
Socket =/var/lib/mysql/mysql.sock
Skip-locking
Key_buffer = 16M
Max_allowed_packet = 1M
Table_cache = 64
Sort_buffer_size = 512K
Net_buffer_length = 8K
Read_buffer_size = 256K
Read_rnd_buffer_size = 512K
Myisam_sort_buffer_size = 8M
Default-character-set=utf8
init_connect= ' SET NAMES UTF8 '

[MySQL]
No-auto-rehash
Default-character-set=utf8
Save exit;
4. Restart the MySQL server to make the contents of its settings effective
#/etc/init.d/mysql restart
5. Re-login to MySQL;
# mysql-u Root-p
# (Enter password)
Mysql> Show variables like ' character_set% ';
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 | (all generated UTF8, success haha ha)
| 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/|
+--------------------------+----------------------------+

MySQL start and stop operations:
Available via #/etc/init.d/mysql [Start | stop | restart] (Implementation start, stop, restart)
You can also #service MySQL [start | stop | restart] (achieve start, stop, restart)
*********************************
Also: If you try to insert Chinese in the database before you modify the character set, after you have modified the character set, in the database where you inserted the Chinese (it may not be a problem in the other database),
The results from the show variables like ' character_set% ' query can be as follows:
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | Latin1 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+

How to modify the default classification of MySQL character set encoding under Linux

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.