一个愚蠢的错误

2020-08-22  本文已影响0人  芒鞋儿

在Mac安装了mysql ,但是采用以下方式

sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

或者直接到环境设定中找到Mysql的小海豚启动之后,仍然登录错误。
参考:mysql在Mac的启动

错误:

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

后来找了另一篇参考:
# Mac下Mysql启动异常["ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"]

  1. 补上PATH 到 .bash_profile 加上/usr/local/mysql/bin
  2. brew info mysql 查看信息
xieheng@XiehengnoMacBook-Pro ~ % brew info mysql
mysql: stable 8.0.21 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
Conflicts with:
  mariadb (because mysql, mariadb, and percona install the same binaries)
  percona-server (because mysql, mariadb, and percona install the same binaries)
/usr/local/Cellar/mysql/8.0.21 (290 files, 291.2MB) *
  Poured from bottle on 2020-08-08 at 22:23:09
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mysql.rb
License: GPL-2.0
==> Dependencies
Build: cmake ✘
Required: openssl@1.1 ✔, protobuf ✔
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Analytics
install: 68,310 (30 days), 198,493 (90 days), 811,027 (365 days)
install-on-request: 66,428 (30 days), 191,941 (90 days), 775,055 (365 days)
build-error: 0 (30 days)
  1. 按文中提示,mysql 其实还没有启动。
    启动如下,然后重新登入,成功了
xieheng@XiehengnoMacBook-Pro ~ % mysql.server start
Starting MySQL
.. SUCCESS! 
xieheng@XiehengnoMacBook-Pro ~ % mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye
xieheng@XiehengnoMacBook-Pro ~ % mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21 Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+

原因,很有可能是安装两个mysql
在/usr/local/下 有Cellar, mysql 两个目录
Cellar下还有一个mysql, 目前没法区分哪个是哪个,但只知道用brew安装的这个是最近用在native php 上的,另一个可能是和XAMP一起安装的也未可知。
因为要做各种环境测试调试,经常会搞混,安装了也未必能记得卸载,因为不知道自己还要用否,所以环境各种重复。

这里记录一下brew 下的mysql 先。
机器还是得定期清理。

上一篇下一篇

猜你喜欢

热点阅读