卸载原因,某次启动时,sock文件和pid文件都找不到
卸载参考如下:
https://blog.csdn.net/liuxw1/article/details/81434005
1.brew remove mysql
2.brew cleanup
3.launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
4.rm ~/Library/LaunchAgents/com.mysql.mysqld.plist
5.sudo rm -rf /opt/homebrew/var/mysql
此外,我还删除了etc下面的my.cnf文件
然后执行brew install [email protected]
之后brew services list如下:
Name Status User Plist
consul stopped
[email protected] stopped
nginx stopped
rabbitmq stopped
redis stopped
/opt/homebrew/etc下又重新生成了my.cnf文件
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
使用brew info [email protected]
bin文件地址:
/opt/homebrew/Cellar/[email protected]/5.7.34
/opt/homebrew/var/mysql此时还未生成.pid 和.error文件(brew services start [email protected]后生成)
auto.cnf ib_logfile0 public_key.pem
ca-key.pem ib_logfile1 server-cert.pem
ca.pem ibdata1 server-key.pem
client-cert.pem mysql sys
client-key.pem performance_schema
ib_buffer_pool private_key.pem
/tmp 也还未生成socket
com.apple.launchd.YNqPrRsKcQ (mysql.sock.lock mysql.sock也是启动后生成)
配置环境变量/初始化
export MYSQL_HOME=/opt/homebrew/Cellar/[email protected]/5.7.34
exprot path=
source ~/.bash_profile
进入/opt/homebrew/cellar/[email protected]/5.7.34/bin
执行mysql.server start(不配置环境变量不生效)
设置初始密码:
https://www.jianshu.com/p/092691b617ac
执行mysql_secure_installation
一路yes
这样设置完成后,可以在~目录下输入mysql -u root -p,回车输入密码登陆
同时,也可以在~目录下完成 mysql.server stop、 mysql.server start
注意这样的方式启动后 brew services list查看的状态仍是stopped
my.cnf配置
为了防止出现和上次一样的异常,我在/opt/homebrew/var/mysql下新建了文件夹tmp,用来存放socket文件
yeb@yuanerbeideMacBook-Pro mysql % pwd
yeb@yuanerbeideMacBook-Pro mysql % ls
auto.cnf mysql
ca-key.pem performance_schema
ca.pem private_key.pem
client-cert.pem public_key.pem
client-key.pem server-cert.pem
dbcloud server-key.pem
ib_buffer_pool sys
ib_logfile0 tmp
ib_logfile1 yuanerbeideMacBook-Pro.local.err
ibdata1 yuanerbeideMacBook-Pro.local.pid
ibtmp1
然后修改etc下my.cnf
添加:
socket= /opt/homebrew/var/mysql/tmp/mysql.sock
[client]
port=3306
socket= /opt/homebrew/var/mysql/tmp/mysql.sock
注意一定要修改tmp文件的权!!!!
sudo chmod -R 777 tmp
否则还是会报错:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/opt/homebrew/var/mysql/tmp/mysql.sock’ (2)
启动等命令
~% brew services start [email protected]
之后 mysql -u root -p
~% brew services stop [email protected]
或者
~% mysql.server start
之后 mysql -u root -p
~% mysql.server stop