Fix MySQL Chinese garbled characters in Linux

Source: Internet
Author: User

Operating system environment:

RHEL4.6 and MySQL 6

Symptom:

Tomcat is installed on this computer as a web server, and a project is deployed to connect to the mysql database through jdbc. However, Chinese input and output are garbled.

Solution:

1. Find the mysql configuration file

The mysql configuration file is/etc/my. cnf. However, this file does not exist. Because the MySQL installation method you may use is different from the one mentioned on the Internet, you may not be able to find/etc/my. cnf. Therefore, you need to use the find command to find the cnf file. Remember not to go to my. cnf because it does not necessarily exist, but should look for *. cnf.

# Find/-iname '*. cnf'-print
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/mysql-test/std_data/ndb_config_mycnf2.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/mysql-test/std_data/ndb_config_mycnf1.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/mysql-test/std_data/bug15328.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/support-files/my-huge.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/support-files/my-large.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/support-files/my-medium.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/support-files/my-innodb-heavy-4G.cnf
/Usr/local/mysql-6.0.4a-alpha-linux-i686-glibc23/support-files/my-small.cnf
/Usr/share/ssl/openssl. cnf

Copy one.
# Cp/usr/local/mysql/support-files/my-large.cnf/etc/my. cnf

2. Open my. cnf to modify the encoding.

# Vi/etc/my. cnf

Add under [mysqld]
Default-character-set = utf8

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

3. Restart mysql

Use unused commands to restart your mysql instance based on the method in which you install mysql. If you have configured the mysqld auto-start mode, you can execute
#/Etc/rc. d/init. d/mysql restart
To restart.
Or you can configure mysql as a system service.
# Service mysql restert

However, if you only follow INSTALL-BINARY to start mysql, such
Shell> bin/mysqld_safe -- user = mysql &
You may need to find the mysql process and kill it. For example
# Ps-aux | grep mysql
Warning: bad syntax, perhaps a bogu '-'? See/usr/share/doc/procps-3.2.3/FAQ
Root 24246 0.0 0.0 4532 1076 pts/7 S/bin/sh bin/mysqld_safe -- user = mysql
Mysql 24273 0.0 1.0 305872 43712 pts/7 S/usr/local/mysql/bin/mysqld -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql /data -- user = mysql -- pid-file =/usr/local/mysql/data/cmme. pid -- skip-external-locking -- port = 3306 -- socket =/tmp/mysql. sock
Find the process id from the displayed result and kill them.
# Kill-9 24246
# Kill-9 24273
Restart the instance.

  • 1
  • 2
  • Next Page

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.