Mysql Chinese garbled characters in Linux _ MySQL

Source: Internet
Author: User
In Linux, mysql has Chinese garbled characters. the default character set of MySQL after bitsCN.com is installed is latin1. to change its character set to what users need (such as utf8 ), you must modify the related configuration files. because the default installation directories of MySQL in linux are distributed in different files, you only need to modify the my. the INI file takes effect after it is restarted. so let's take a look at the MySQL database files, configuration files, and command files in different directories in linux:

1. the database directory where all the database files created are located
/Var/lib/mysql/

2. configuration file (mysql. server command and configuration file location)
/Usr/share/mysql

3. related commands (such as mysql mysqladmin)
/Usr/bin
4. startup script (for example, mysql startup command)
/Etc/rc. d/init. d/

View default character sets
# Mysql-u root-p
# (Enter the 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/|
+ -------------------------- + ---------------------------- +

Modify character set modification/etc/my. cnf file
#/etc/my.cnf[client]default-character-set=utf8[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0#default-character-set=utf8character-set-server=utf8init_connect='SET NAMES utf8'[mysql]no-auto-rehashdefault-character-set=utf8[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

Remember: add character-set-server = utf8 to mysqld instead of default-character-set = utf8.
Otherwise, The following error will be reported: Starting MySQL... The server quit without updating PID file [failed] lib/mysql/localhost. localdomain. pid). exception

Restart the MySQL server to make the settings take effect.
#/Etc/init. d/mysql restart
BitsCN.com

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.