`
qilixiang012
  • 浏览: 202726 次
文章分类
社区版块
存档分类
最新评论

mysql mac下解决MySQL中文乱码的问题

 
阅读更多

mac osx 10.9

mysql 5.5

安装mysql的dmg文件后,将/usr/local/mysql/support-files中的任意一个.cnf文件copy到/etc/目录并重命名为my.cnf

修改my.cnf


找到[mysqld] 添加

character-set-server=utf8chatracter-set-server=utf8

init_connect='SET NAMES utf8'

找到[mysql]

default-character-set=utf8

然后重启mysql服务。


注:如果在mysqld中添加的是default-character-set=utf8,则会导致mysql无法启动

  1. #ExampleMySQLconfigfileformediumsystems.
  2. #
  3. #Thisisforasystemwithlittlememory(32M-64M)whereMySQLplays
  4. #animportantpart,orsystemsupto128MwhereMySQLisusedtogetherwith
  5. #otherprograms(suchasawebserver)
  6. #
  7. #MySQLprogramslookforoptionfilesinasetof
  8. #locationswhichdependonthedeploymentplatform.
  9. #Youcancopythisoptionfiletooneofthose
  10. #locations.Forinformationabouttheselocations,see:
  11. #http://dev.mysql.com/doc/mysql/en/option-files.html
  12. #
  13. #Inthisfile,youcanusealllongoptionsthataprogramsupports.
  14. #Ifyouwanttoknowwhichoptionsaprogramsupports,runtheprogram
  15. #withthe"--help"option.
  16. #ThefollowingoptionswillbepassedtoallMySQLclients
  17. [client]
  18. #password=your_password
  19. port=3306
  20. socket=/tmp/mysql.sock
  21. #Herefollowsentriesforsomespecificprograms
  22. #TheMySQLserver
  23. [mysqld]
  24. port=3306
  25. socket=/tmp/mysql.sock
  26. skip-external-locking
  27. key_buffer_size=16M
  28. max_allowed_packet=1M
  29. table_open_cache=64
  30. sort_buffer_size=512K
  31. net_buffer_length=8K
  32. read_buffer_size=256K
  33. read_rnd_buffer_size=512K
  34. myisam_sort_buffer_size=8M
  35. character-set-server=utf8
  36. init_connect='SETNAMESutf8'
  37. #Don'tlistenonaTCP/IPportatall.Thiscanbeasecurityenhancement,
  38. #ifallprocessesthatneedtoconnecttomysqldrunonthesamehost.
  39. #AllinteractionwithmysqldmustbemadeviaUnixsocketsornamedpipes.
  40. #NotethatusingthisoptionwithoutenablingnamedpipesonWindows
  41. #(viathe"enable-named-pipe"option)willrendermysqlduseless!
  42. #
  43. #skip-networking
  44. #ReplicationMasterServer(default)
  45. #binaryloggingisrequiredforreplication
  46. log-bin=mysql-bin
  47. #binaryloggingformat-mixedrecommended
  48. binlog_format=mixed
  49. #requireduniqueidbetween1and2^32-1
  50. #defaultsto1ifmaster-hostisnotset
  51. #butwillnotfunctionasamasterifomitted
  52. server-id=1
  53. #ReplicationSlave(commentoutmastersectiontousethis)
  54. #
  55. #Toconfigurethishostasareplicationslave,youcanchoosebetween
  56. #twomethods:
  57. #
  58. #1)UsetheCHANGEMASTERTOcommand(fullydescribedinourmanual)-
  59. #thesyntaxis:
  60. #
  61. #CHANGEMASTERTOMASTER_HOST=<host>,MASTER_PORT=<port>,
  62. #MASTER_USER=<user>,MASTER_PASSWORD=<password>;
  63. #
  64. #whereyoureplace<host>,<user>,<password>byquotedstringsand
  65. #<port>bythemaster'sportnumber(3306bydefault).
  66. #
  67. #Example:
  68. #
  69. #CHANGEMASTERTOMASTER_HOST='125.564.12.1',MASTER_PORT=3306,
  70. #MASTER_USER='joe',MASTER_PASSWORD='secret';
  71. #
  72. #OR
  73. #
  74. #2)Setthevariablesbelow.However,incaseyouchoosethismethod,then
  75. #startreplicationforthefirsttime(evenunsuccessfully,forexample
  76. #ifyoumistypedthepasswordinmaster-passwordandtheslavefailsto
  77. #connect),theslavewillcreateamaster.infofile,andanylater
  78. #changeinthisfiletothevariables'valuesbelowwillbeignoredand
  79. #overriddenbythecontentofthemaster.infofile,unlessyoushutdown
  80. #theslaveserver,deletemaster.infoandrestarttheslaverserver.
  81. #Forthatreason,youmaywanttoleavethelinesbelowuntouched
  82. #(commented)andinsteaduseCHANGEMASTERTO(seeabove)
  83. #
  84. #requireduniqueidbetween2and2^32-1
  85. #(anddifferentfromthemaster)
  86. #defaultsto2ifmaster-hostisset
  87. #butwillnotfunctionasaslaveifomitted
  88. #server-id=2
  89. #
  90. #Thereplicationmasterforthisslave-required
  91. #master-host=<hostname>
  92. #
  93. #Theusernametheslavewilluseforauthenticationwhenconnecting
  94. #tothemaster-required
  95. #master-user=<username>
  96. #
  97. #Thepasswordtheslavewillauthenticatewithwhenconnectingto
  98. #themaster-required
  99. #master-password=<password>
  100. #
  101. #Theportthemasterislisteningon.
  102. #optional-defaultsto3306
  103. #master-port=<port>
  104. #
  105. #binarylogging-notrequiredforslaves,butrecommended
  106. #log-bin=mysql-bin
  107. #UncommentthefollowingifyouareusingInnoDBtables
  108. #innodb_data_home_dir=/usr/local/mysql/data
  109. #innodb_data_file_path=ibdata1:10M:autoextend
  110. #innodb_log_group_home_dir=/usr/local/mysql/data
  111. #Youcanset.._buffer_pool_sizeupto50-80%
  112. #ofRAMbutbewareofsettingmemoryusagetoohigh
  113. #innodb_buffer_pool_size=16M
  114. #innodb_additional_mem_pool_size=2M
  115. #Set.._log_file_sizeto25%ofbufferpoolsize
  116. #innodb_log_file_size=5M
  117. #innodb_log_buffer_size=8M
  118. #innodb_flush_log_at_trx_commit=1
  119. #innodb_lock_wait_timeout=50
  120. [mysqldump]
  121. quick
  122. max_allowed_packet=16M
  123. [mysql]
  124. no-auto-rehash
  125. #RemovethenextcommentcharacterifyouarenotfamiliarwithSQL
  126. #safe-updates
  127. default-character-set=utf8
  128. [myisamchk]
  129. key_buffer_size=20M
  130. sort_buffer_size=20M
  131. read_buffer=2M
  132. write_buffer=2M
  133. [mysqlhotcopy]
  134. interactive-timeout
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics