Home > Database > Mysql Tutorial > body text

mysql中设置默认字符编码为utf-8_MySQL

WBOY
Release: 2016-06-01 13:28:29
Original
826 people have browsed it

bitsCN.com

mysql中设置默认字符编码为utf-8

 

       使用过Linux的同志就知道,在Linux下安装mysql,尤其是使用yum安装的时候,我们是没法选择其默认的字符编码方式。这个就是一个比较头痛的问题,如果Linux数据库中使用到中文的时候,乱码问题会让你很头痛。今天就来先说说Linux下怎么设置其默认编码方式。

1、首先中止其mysql服务,需要在root权限下

 

[plain] service mysqld stop  
Copy after login

2、在/etc/下面找到my.cnf文件,如果没有,找到mysql的安装目录下的support-files文件夹下的my-medium.cnf文件,复制到/etc/下面并改名为my.cnf

3、编辑my.cnf文件,在其[client] 和 [mysqld]后面均加上default-character-set=utf8,保存并关闭。

[plain] [client]  #password   = your_password  port        = 3306  socket      = /tmp/mysql.sock  default-character-set=utf8    # Here follows entries for some specific programs    # The MySQL server  [mysqld]  port        = 3306  socket      = /tmp/mysql.sock  skip-external-locking  key_buffer_size = 16M  max_allowed_packet = 1M  table_open_cache = 64  sort_buffer_size = 512K  net_buffer_length = 8K  read_buffer_size = 256K  read_rnd_buffer_size = 512K  myisam_sort_buffer_size = 8M  default-character-set=utf8  
Copy after login

 

4、重启服务即可。

PS:在Windows系统下的设置方式类似。

只要在mysql安装目录下找到my.ini文件,修改[client] 和 [mysqld]后面均加上default-character-set=utf8,如果没有找到,找到my-medium.ini文件,复制并改名为my.ini即可。
 

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!