The default character set of installed MySQL is latin1. In order to change its character set to what the user needs (such as utf8), its related configuration files must be changed.
Since the default installation directory of MySQL under Linux is distributed in different files, it is not placed in the same directory like windows. You only need to modify the my.ini file, and it will take effect after restarting. So first let’s take a look at the database files, configuration files and command files of MySQL under Linux in different directories:
1. Database directory, the database files created are all in this directory
/var/lib/mysql/
2. Configuration file (location of mysql.server command and configuration file)
/usr/share/mysql
3. Related commands (such as mysql mysqladmin, etc.)
/usr/bin
4. Startup script (such as mysql startup command)
/etc/rc.d/init.d/
Solution:
1. View the default character set
#mysql -u root - p #(输入密码) mysql> show variables like 'character_set%';
2. Change the character set by modifying the /etc/my.cnf file
#/etc/my.cnf [client] default-character-set=utf8 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 #default-character-set=utf8 character-set-server=utf8 init_connect='SET NAMES utf8' [mysql] no-auto-rehash default-character-set=utf8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
Remember : added in mysqld It's character-set-server=utf8
instead of default-character-set=utf8
. Otherwise, it will report: Starting MySQL...The server quit without updating PID file [Failure]lib/mysql/localhost.localdomain.pid)
.Exception
3. Restart MySQL server to make its settings effective
一、启动方式 1、使用 service 启动:service mysqld start 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start 3、使用 safe_mysqld 启动:safe_mysqld& 二、停止 1、使用 service 启动:service mysqld stop 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop 3、 mysqladmin shutdown 三、重启 1、 使用 service 启动:service mysqld restart 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart
Recommended tutorial: Linux tutorial
The above is the detailed content of Reasons and solutions for Chinese garbled characters (Chinese question marks) in mysql under Linux. For more information, please follow other related articles on the PHP Chinese website!