Home > Database > Mysql Tutorial > Linux下mysql中文乱码问题_MySQL

Linux下mysql中文乱码问题_MySQL

WBOY
Release: 2016-06-01 13:18:16
Original
879 people have browsed it

bitsCN.com 安装完的MySQL的默认字符集为 latin1 ,为了要将其字符集改为用户所需要的(比如utf8),就必须改其相关的配置文件;由于linux下MySQL的默认安装目录分布在不同的文件下;不像windows一样放在同一目录下,只需修改其中的my.ini文件,重起后就生效了;所以先来看看linux下MySQL的数据库文件、配置文件和命令文件分别在不同的目录 :

1、数据库目录,其所创建的数据库文件都在该目录下
  /var/lib/mysql/

2、配置文件 (mysql.server命令及配置文件所在地)
  /usr/share/mysql

3、相关命令(如mysql mysqladmin等)
  /usr/bin
4、启动脚本(如mysql启动命令)
  /etc/rc.d/init.d/

查看默认字符集
#mysql -u root - p
#(输入密码)
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/ |
+--------------------------+----------------------------+

修改字符集修改 /etc/my.cnf文件

#/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
Copy after login

切记:在mysqld中加入的是character-set-server=utf8 而不是 default-character-set=utf8
否则会报:Starting MySQL...The server quit without updating PID file [失败]lib/mysql/localhost.localdomain.pid).异常

重起MySQL服务器,使其设置的内容生效
#/etc/init.d/mysql restart
bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template