大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说Mac上用 homebrew 装 mysql,解决‘/tmp/mysql.sock‘ 报错,希望您对编程的造诣更进一步.
mac上用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_profileFor 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-binbinlog_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‘ 报错
原文地址:https://blog.51cto.com/13238147/2511539
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/7273.html