• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

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

mysql技术 daydaydream 62次浏览 已收录 0个评论

mac上用homebrew安装mysql(Mac自带homebrew)

brew install mysql

安装后如下:

If you need to have mysql@5.7 first in your PATH run:
echo ‘export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"’ >> /Users/chenyang/.bash_profile

For compilers to find mysql@5.7 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"

To have launchd start mysql@5.7 now and restart at login:
brew services start mysql@5.7
Or, if you don’t want/need a background service you can just run:
/usr/local/opt/mysql@5.7/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

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


VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明Mac上用 homebrew 装 mysql,解决’/tmp/mysql.sock’ 报错
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址