Mysql Chinese garbled characters in Linux

Source: Internet
Author: User

The default Character Set of installed MySQL is latin1. To change the character set to what you need (such as utf8), you must change the related configuration file; in linux, the default installation directory of MySQL is distributed in different files. Unlike in windows, you only need to modify 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

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.