mysql数据库需改默认字符编码

来源:互联网 发布:国家网络安全法 解读 编辑:程序博客网 时间:2024/06/07 01:43

以下配置指配置文件my.ini:

[plain] view plain copy
  1. [mysqld]  
  2.   
  3. character_set_server=utf8  
  4. collation-server=utf8_general_ci  
  5.   
  6. ......  
  7.   
  8. [client]    
  9. #设置客户端字符集    
  10. default-character-set=utf8  

 

然后重启服务器,编码配置即更改,注意位置,default-character-set=utf8只能放在[client]下面,否则不能启动MySQL

下面给出一个示例(仅供参考):

 

[plain] view plain copy
  1. # For advice on how to change settings please see  
  2. # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html  
  3. # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the  
  4. # *** default location during install, and will be replaced if you  
  5. # *** upgrade to a newer version of MySQL.  
  6.   
  7. [mysqld]  
  8.   
  9. # Remove leading # and set to the amount of RAM for the most important data  
  10. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  
  11. # innodb_buffer_pool_size = 128M  
  12.   
  13. # Remove leading # to turn on a very important data integrity option: logging  
  14. # changes to the binary log between backups.  
  15. # log_bin  
  16.   
  17. # These are commonly set, remove the # and set as required.  
  18. # basedir = .....  
  19. # datadir = .....  
  20. # port = .....  
  21. # server_id = .....  
  22.   
  23. #skip-grant-tables    
  24. #设置字符集为utf8  
  25. character_set_server=utf8  
  26. collation-server=utf8_general_ci  
  27. loose-default-character-set = utf8   
  28. basedir = D:/Java/mysql5.6    
  29. datadir = D:/Java/mysql5.6/data    
  30.     
  31. [client]    
  32. #设置客户端字符集    
  33. default-character-set=utf8  
  34. loose-default-character-set = utf8    
  35.     
  36. [WinMySQLadmin]    
  37. Server = D:/Java/mysql5.6/bin/mysqld.exe  
  38.   
  39.   
  40. # Remove leading # to set options mainly useful for reporting servers.  
  41. # The server defaults are faster for transactions and fast SELECTs.  
  42. # Adjust sizes as needed, experiment to find the optimal values.  
  43. # join_buffer_size = 128M  
  44. # sort_buffer_size = 2M  
  45. # read_rnd_buffer_size = 2M   
  46.   
  47. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   
原创粉丝点击