如何解决mac中mysql乱码问题
这篇文章主要为大家展示了“如何解决mac中mysql乱码问题”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何解决mac中mysql乱码问题”这篇文章吧。
mac mysql乱码的解决办法:1、找到并打开my.cnf文件;2、添加代码为“character-set-server=utf8 init_connect='SET NAMES utf8...”即可。
本文操作环境:macOS10.15系统、Mysql5.7.26版、macbook pro 2020电脑。
mac下MySQL出现乱码的解决方法
本文说下mac下的处理,其实处理方式是一样的,我电脑的mysql版本是5.7.26-log
网上很多帖子都说去/usr/local/mysql/support-files目录拷贝my-default.cnf到/etc/my.cnf 然后和linux的修改方式就一样了,这里说明下:Mac版MySQL在5.7.18之后在my-default.cnf就取消了,于是找不到my-default.cnf也找不到my.cnf,my-default.cnf是之前的版本中才有的文件。
假如不幸你的mysql版本恰好是5.7.18之后的,那么直接新建即可
cd/etcsudovimmy.cnf
拷贝以下代码到my.cnf中
#ExampleMySQLconfigfileformediumsystems.##Thisisforasystemwithlittlememory(32M-64M)whereMySQLplays#animportantpart,orsystemsupto128MwhereMySQLisusedtogetherwith#otherprograms(suchasawebserver)##MySQLprogramslookforoptionfilesinasetof#locationswhichdependonthedeploymentplatform.#Youcancopythisoptionfiletooneofthose#locations.Forinformationabouttheselocations,see:#http://dev.mysql.com/doc/mysql/en/option-files.html##Inthisfile,youcanusealllongoptionsthataprogramsupports.#Ifyouwanttoknowwhichoptionsaprogramsupports,runtheprogram#withthe"--help"option.#ThefollowingoptionswillbepassedtoallMySQLclients[client]default-character-set=utf8#password=your_passwordport=3306socket=/tmp/mysql.sock#Herefollowsentriesforsomespecificprograms#TheMySQLserver[mysqld]character-set-server=utf8init_connect='SETNAMESutf8port=3306socket=/tmp/mysql.sockskip-external-lockingkey_buffer_size=16Mmax_allowed_packet=1Mtable_open_cache=64sort_buffer_size=512Knet_buffer_length=8Kread_buffer_size=256Kread_rnd_buffer_size=512Kmyisam_sort_buffer_size=8Mcharacter-set-server=utf8init_connect='SETNAMESutf8'#Don'tlistenonaTCP/IPportatall.Thiscanbeasecurityenhancement,#ifallprocessesthatneedtoconnecttomysqldrunonthesamehost.#AllinteractionwithmysqldmustbemadeviaUnixsocketsornamedpipes.#NotethatusingthisoptionwithoutenablingnamedpipesonWindows#(viathe"enable-named-pipe"option)willrendermysqlduseless!##skip-networking#ReplicationMasterServer(default)#binaryloggingisrequiredforreplicationlog-bin=mysql-bin#binaryloggingformat-mixedrecommendedbinlog_format=mixed#requireduniqueidbetween1and2^32-1#defaultsto1ifmaster-hostisnotset#butwillnotfunctionasamasterifomittedserver-id=1#ReplicationSlave(commentoutmastersectiontousethis)##Toconfigurethishostasareplicationslave,youcanchoosebetween#twomethods:##1)UsetheCHANGEMASTERTOcommand(fullydescribedinourmanual)-#thesyntaxis:##CHANGEMASTERTOMASTER_HOST=<host>,MASTER_PORT=<port>,#MASTER_USER=<user>,MASTER_PASSWORD=<password>;##whereyoureplace<host>,<user>,<password>byquotedstringsand#<port>bythemaster'sportnumber(3306bydefault).##Example:##CHANGEMASTERTOMASTER_HOST='125.564.12.1',MASTER_PORT=3306,#MASTER_USER='joe',MASTER_PASSWORD='secret';##OR##2)Setthevariablesbelow.However,incaseyouchoosethismethod,then#startreplicationforthefirsttime(evenunsuccessfully,forexample#ifyoumistypedthepasswordinmaster-passwordandtheslavefailsto#connect),theslavewillcreateamaster.infofile,andanylater#changeinthisfiletothevariables'valuesbelowwillbeignoredand#overriddenbythecontentofthemaster.infofile,unlessyoushutdown#theslaveserver,deletemaster.infoandrestarttheslaverserver.#Forthatreason,youmaywanttoleavethelinesbelowuntouched#(commented)andinsteaduseCHANGEMASTERTO(seeabove)##requireduniqueidbetween2and2^32-1#(anddifferentfromthemaster)#defaultsto2ifmaster-hostisset#butwillnotfunctionasaslaveifomitted#server-id=2##Thereplicationmasterforthisslave-required#master-host=<hostname>##Theusernametheslavewilluseforauthenticationwhenconnecting#tothemaster-required#master-user=<username>##Thepasswordtheslavewillauthenticatewithwhenconnectingto#themaster-required#master-password=<password>##Theportthemasterislisteningon.#optional-defaultsto3306#master-port=<port>##binarylogging-notrequiredforslaves,butrecommended#log-bin=mysql-bin#UncommentthefollowingifyouareusingInnoDBtables#innodb_data_home_dir=/usr/local/mysql/data#innodb_data_file_path=ibdata1:10M:autoextend#innodb_log_group_home_dir=/usr/local/mysql/data#Youcanset.._buffer_pool_sizeupto50-80%#ofRAMbutbewareofsettingmemoryusagetoohigh#innodb_buffer_pool_size=16M#innodb_additional_mem_pool_size=2M#Set.._log_file_sizeto25%ofbufferpoolsize#innodb_log_file_size=5M#innodb_log_buffer_size=8M#innodb_flush_log_at_trx_commit=1#innodb_lock_wait_timeout=50[mysqldump]quickmax_allowed_packet=16M[mysql]no-auto-rehash#RemovethenextcommentcharacterifyouarenotfamiliarwithSQL#safe-updatesdefault-character-set=utf8[myisamchk]key_buffer_size=20Msort_buffer_size=20Mread_buffer=2Mwrite_buffer=2M[mysqlhotcopy]interactive-timeout
最后一步重启下mysql服务即可
以上是“如何解决mac中mysql乱码问题”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。