tmp mysql.sock mac_Mac上用 homebrew 装 mysql,解决‘/tmp/mysql.sock‘ 报错

930671b180dfce3a079bdab1f0f224e0.pngmac上用homebrew安装mysql(Mac自带homebrew)

brew install mysql

安装后如下:

If you need to have [email protected] first in your PATH run:

echo ‘export PATH="/usr/local/opt/[email protected]/bin:$PATH"‘ >> /Users/chenyang/.bash_profile

For compilers to find [email protected] you may need to set:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"

export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

To have launchd start [email protected] now and restart at login:

brew services start [email protected]

Or, if you don‘t want/need a background service you can just run:

/usr/local/opt/[email protected]/bin/mysql.server start

做好my.cnf的设置,我这里的路径为:/usr/local/etc/my.cnf,内容如下:

[client]

default-character-set=utf8

#password = your_password

port = 3306

socket = /tmp/mysql/mysql.sock

[mysqld]

character-set-server=utf8

init_connect=‘SET NAMES utf8

port = 3306

socket = /tmp/mysql/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

character-set-server=utf8

init_connect=‘SET NAMES utf8‘

#skip-networking

replication

log-bin=mysql-bin

binlog_format=mixed

server-id = 1

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

#safe-updates

default-character-set=utf8

[myisamchk]

key_buffer_size = 20M

sort_buffer_size = 20M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

此时在控制台运行会报错:

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)

google各教程教程,发现就是mysql.sock这个文件的路径问题,最后解决办法:

修改/usr/local/etc/my.cnf文件(如果没有自创建),将文件里面socket的路径指向你mysql的安装路径,使用了很多网上的方式,结果还是不行,应该是安装路径不一样,你必须找到你的路径,(mysql版本5.7.20)路径是在/usr/local/var/mysql/

[client]

default-character-set=utf8

#password = your_password

port = 3306

socket = /usr/local/var/mysql/mysql.sock

#/tmp/mysql/mysql.sock

[mysqld]

character-set-server=utf8

init_connect=‘SET NAMES utf8

port = 3306

socket = /usr/local/var/mysql/mysql.sock

#/tmp/mysql/mysql.sock

修改后问题解决,数据库正常连接

Mac上用 homebrew 装 mysql,解决‘/tmp/mysql.sock‘ 报错

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值