brew安装Mysql

安装Mysql

peter@MacBook-Pro mysql % brew install mysql@5.7
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/api/formula.jws.json
##O=#    #
==> Fetching mysql@5.7
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/mysql%405.7-5.7.42.ventura.bottle.tar.gz
Already downloaded: /Users/peter/Library/Caches/Homebrew/downloads/ec15e70578b4a7df698816b9d822effb66332950a3bf2c4e03aebcbf74250baa--mysql@5.7-5.7.42.ventura.bottle.tar.gz
==> Pouring mysql@5.7-5.7.42.ventura.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.42/bin/mysqld --initialize-insecure --user=peter --basedir=/usr/local/Cellar/mysql@5.7/5.7.42 --datadir=/usr/local/var/
==> 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

mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mysql@5.7 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

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 restart mysql@5.7 after an upgrade:
  brew services restart mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysqld_safe --datadir=/usr/local/var/mysql
==> Summary
🍺  /usr/local/Cellar/mysql@5.7/5.7.42: 321 files, 234.6MB
==> Running `brew cleanup mysql@5.7`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
peter@MacBook-Pro mysql % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": null
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro mysql % brew services restart mysql@5.7
==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
peter@MacBook-Pro mysql % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "started",
    "user": "peter",
    "file": "/Users/peter/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": 0
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro mysql % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "started",
    "user": "peter",
    "file": "/Users/peter/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": 0
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro mysql % mysql
ERROR 1045 (28000): Access denied for user 'peter'@'localhost' (using password: NO)
peter@MacBook-Pro mysql % mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.42 Homebrew

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> exit
Bye

结果启动的时候就报错了 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决办法

  1. brew services list --json 查看启动情况 如果显示stop 就是未启动成功
  2. brew services stop mysql@5.7 关闭服务
  3. brew uninstall mysql
  4. find / -name mysql 查找卸载残留
  5. 重新安装 brew install mysql@5.7 启动成功

纠错参考 https://blog.csdn.net/qq_24909089/article/details/126936656

==> Successfully stopped `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
peter@MacBook-Pro ~ % mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
peter@MacBook-Pro ~ % mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
peter@MacBook-Pro ~ % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": null
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro ~ % brew services stop mysql@5.7
Warning: Service `mysql@5.7` is not started.
peter@MacBook-Pro ~ % brew services start mysql@5.7
==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
peter@MacBook-Pro ~ % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "stopped",
    "user": "peter",
    "file": "/Users/peter/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": 0
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro ~ % brew services stop mysql@5.7
Stopping `mysql@5.7`... (might take a while)
==> Successfully stopped `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
peter@MacBook-Pro ~ % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": null
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro ~ % brew uninstall mysql
Error: No such keg: /usr/local/Cellar/mysql
peter@MacBook-Pro ~ % brew uninstall mysql@5.7
Uninstalling /usr/local/Cellar/mysql@5.7/5.7.42... (321 files, 234.6MB)
peter@MacBook-Pro ~ % pwd
/Users/peter
peter@MacBook-Pro ~ % cd /usr/local
peter@MacBook-Pro local % ls
Caskroom	Frameworks	bin		include		n		sbin		var
Cellar		Homebrew	etc		lib		opt		share		www
peter@MacBook-Pro local % cd etc
peter@MacBook-Pro etc % ls
ODBCDataSources		freetds.conf		odbc.ini		php
bash_completion.d	locales.conf		odbcinst.ini		pool.conf
ca-certificates		my.cnf			openldap		siegerc
fonts			my.cnf.default		openssl@1.1		urls.txt
peter@MacBook-Pro etc % ll
zsh: command not found: ll
peter@MacBook-Pro etc % ls
ODBCDataSources		freetds.conf		odbc.ini		php
bash_completion.d	locales.conf		odbcinst.ini		pool.conf
ca-certificates		my.cnf			openldap		siegerc
fonts			my.cnf.default		openssl@1.1		urls.txt
peter@MacBook-Pro etc % rm my.cnf my.cnf.default
peter@MacBook-Pro etc % ls
ODBCDataSources		fonts			odbc.ini		openssl@1.1		siegerc
bash_completion.d	freetds.conf		odbcinst.ini		php			urls.txt
ca-certificates		locales.conf		openldap		pool.conf
peter@MacBook-Pro etc % cd /tmp
peter@MacBook-Pro /tmp % ls
WillFinish.txt				com.google.Keystone			sunlogin_helper.log
com.adobe.AdobeIPCBroker.ctrl-peter	pear
com.apple.launchd.7FyVDkzIJT		powerlog
peter@MacBook-Pro /tmp % cd /tmp
peter@MacBook-Pro /tmp % ls
WillFinish.txt				com.google.Keystone			sunlogin_helper.log
com.adobe.AdobeIPCBroker.ctrl-peter	pear
com.apple.launchd.7FyVDkzIJT		powerlog
peter@MacBook-Pro /tmp % find / -name mysql
find: /usr/sbin/authserver: Permission denied
/usr/local/var/mysql
/usr/local/var/mysql/mysql
find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /Library/Application Support/ApplePushService: Permission denied
find: /Library/Application Support/com.apple.TCC: Operation not permitted
find: /Library/OSAnalytics/Preferences/Library: Permission denied
find: /Library/Caches/com.apple.iconservices.store: Permission denied
find: /Library/Caches/com.apple.aned: Operation not permitted
find: /System/Library/DirectoryServices/DefaultLocalDB/Default: Permission denied
find: /System/Library/Templates/Data/Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /System/Library/Templates/Data/Library/Application Support/com.apple.TCC: Operation not permitted
find: /System/Library/Templates/Data/private/etc/cups/certs: Permission denied
find: /System/Library/Templates/Data/private/var/install: Permission denied
find: /System/Library/Templates/Data/private/var/ma: Permission denied
find: /System/Library/Templates/Data/private/var/spool/mqueue: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/saved: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/trace: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/defer: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/flush: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/deferred: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/corrupt: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/public: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/private: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/incoming: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/active: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/maildrop: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/hold: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/bounce: Permission denied
find: /System/Library/Templates/Data/private/var/spool/cups: Permission denied
find: /System/Library/Templates/Data/private/var/jabberd: Permission denied
find: /System/Library/Templates/Data/private/var/audit: Permission denied
find: /System/Library/Templates/Data/private/var/root: Permission denied
find: /System/Library/Templates/Data/private/var/lib/postfix: Permission denied
find: /System/Library/Templates/Data/private/var/db/appinstalld: Permission denied
find: /System/Library/Templates/Data/private/var/db/diskimagesiod: Permission denied
find: /System/Library/Templates/Data/private/var/db/locationd: Permission denied
find: /System/Library/Templates/Data/private/var/db/sysdiagnose/com.apple.sysdiagnose: Permission denied
find: /System/Library/Templates/Data/private/var/db/analyticsd: Permission denied
find: /System/Library/Templates/Data/private/var/db/rmd: Permission denied
find: /System/Library/Templates/Data/private/var/db/knowledgegraphd: Permission denied
find: /System/Library/Templates/Data/private/var/db/nsurlsessiond: Permission denied
find: /System/Library/Templates/Data/private/var/db/fpsd: Permission denied
find: /System/Library/Templates/Data/private/var/db/hidd: Permission denied
find: /System/Library/Templates/Data/private/var/db/installcoordinationd: Permission denied
find: /System/Library/Templates/Data/private/var/db/geod: Permission denied
find: /System/Library/Templates/Data/private/var/db/oah: Operation not permitted
find: /System/Library/Templates/Data/private/var/db/reportmemoryexception: Permission denied
find: /System/Library/Templates/Data/private/var/db/lockdown: Permission denied
find: /System/Library/Templates/Data/private/var/db/biome: Permission denied
find: /System/Library/Templates/Data/private/var/db/datadetectors: Permission denied
find: /System/Library/Templates/Data/private/var/db/cmiodalassistants: Permission denied
find: /System/Library/Templates/Data/private/var/db/com.apple.xpc.roleaccountd.staging: Permission denied
find: /System/Library/Templates/Data/private/var/db/dslocal/nodes/Default: Permission denied
find: /System/Library/Templates/Data/private/var/db/nearbyd: Permission denied
find: /System/Library/Templates/Data/private/var/db/mmaintenanced: Permission denied
find: /System/Library/Templates/Data/private/var/db/timed: Permission denied
find: /System/Library/Templates/Data/private/var/db/applepay: Permission denied
find: /System/Library/Templates/Data/private/var/db/darwindaemon: Permission denied
find: /System/Library/Templates/Data/private/var/db/securityagent: Permission denied
find: /System/Library/Templates/Data/private/var/db/accessoryupdater: Permission denied
find: /System/Library/Templates/Data/private/var/db/ConfigurationProfiles/Store: Permission denied
find: /System/Library/Templates/Data/private/var/db/caches/opendirectory: Permission denied
find: /System/Library/Templates/Data/private/var/at/tabs: Permission denied
find: /System/Library/Templates/Data/private/var/at/tmp: Permission denied
find: /System/Library/Templates/Data/private/var/backups: Permission denied
find: /System/Library/Templates/Data/private/var/agentx: Permission denied
find: /System/Library/Caches/com.apple.appstored: Permission denied
find: /System/Library/Caches/com.apple.coresymbolicationd: Permission denied
find: /System/Volumes/Update/Hardware: Permission denied
find: /System/Volumes/Update/Controller: Permission denied
find: /System/Volumes/Preboot/.Trashes: Operation not permitted
/System/Volumes/Data/usr/local/var/mysql
/System/Volumes/Data/usr/local/var/mysql/mysql
find: /System/Volumes/Data/.Spotlight-V100: No such file or directory
find: /System/Volumes/Data/boot: No such file or directory
find: /System/Volumes/Data/Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /System/Volumes/Data/Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /System/Volumes/Data/Library/Application Support/ApplePushService: Permission denied
find: /System/Volumes/Data/Library/Application Support/com.apple.TCC: Operation not permitted
find: /System/Volumes/Data/Library/OSAnalytics/Preferences/Library: Permission denied
find: /System/Volumes/Data/Library/Caches/com.apple.iconservices.store: Permission denied
find: /System/Volumes/Data/Library/Caches/com.apple.aned: Operation not permitted
^C
peter@MacBook-Pro /tmp % cd /System/Volumes/Data/usr/local/var/mysql
peter@MacBook-Pro mysql % ls
#ib_16384_0.dblwr	auto.cnf		client-cert.pem		ibdata1			public_key.pem		undo_002
#ib_16384_1.dblwr	binlog.000001		client-key.pem		mysql			server-cert.pem
#innodb_redo		binlog.index		ib_buffer_pool		mysql.ibd		server-key.pem
#innodb_temp		ca-key.pem		ib_logfile0		performance_schema	sys
MacBook-Pro.err		ca.pem			ib_logfile1		private_key.pem		undo_001
peter@MacBook-Pro mysql % open .
peter@MacBook-Pro mysql % cd /usr/local/var/mysql
peter@MacBook-Pro mysql % open .
peter@MacBook-Pro mysql % find / -name mysql.sock
find: /usr/sbin/authserver: Permission denied
find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /Library/Application Support/ApplePushService: Permission denied
find: /Library/Application Support/com.apple.TCC: Operation not permitted
find: /Library/OSAnalytics/Preferences/Library: Permission denied
find: /Library/Caches/com.apple.iconservices.store: Permission denied
find: /Library/Caches/com.apple.aned: Operation not permitted
find: /System/Library/DirectoryServices/DefaultLocalDB/Default: Permission denied
find: /System/Library/Templates/Data/Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /System/Library/Templates/Data/Library/Application Support/com.apple.TCC: Operation not permitted
find: /System/Library/Templates/Data/private/etc/cups/certs: Permission denied
find: /System/Library/Templates/Data/private/var/install: Permission denied
find: /System/Library/Templates/Data/private/var/ma: Permission denied
find: /System/Library/Templates/Data/private/var/spool/mqueue: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/saved: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/trace: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/defer: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/flush: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/deferred: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/corrupt: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/public: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/private: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/incoming: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/active: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/maildrop: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/hold: Permission denied
find: /System/Library/Templates/Data/private/var/spool/postfix/bounce: Permission denied
find: /System/Library/Templates/Data/private/var/spool/cups: Permission denied
find: /System/Library/Templates/Data/private/var/jabberd: Permission denied
find: /System/Library/Templates/Data/private/var/audit: Permission denied
find: /System/Library/Templates/Data/private/var/root: Permission denied
find: /System/Library/Templates/Data/private/var/lib/postfix: Permission denied
find: /System/Library/Templates/Data/private/var/db/appinstalld: Permission denied
find: /System/Library/Templates/Data/private/var/db/diskimagesiod: Permission denied
find: /System/Library/Templates/Data/private/var/db/locationd: Permission denied
find: /System/Library/Templates/Data/private/var/db/sysdiagnose/com.apple.sysdiagnose: Permission denied
find: /System/Library/Templates/Data/private/var/db/analyticsd: Permission denied
find: /System/Library/Templates/Data/private/var/db/rmd: Permission denied
find: /System/Library/Templates/Data/private/var/db/knowledgegraphd: Permission denied
find: /System/Library/Templates/Data/private/var/db/nsurlsessiond: Permission denied
find: /System/Library/Templates/Data/private/var/db/fpsd: Permission denied
find: /System/Library/Templates/Data/private/var/db/hidd: Permission denied
find: /System/Library/Templates/Data/private/var/db/installcoordinationd: Permission denied
find: /System/Library/Templates/Data/private/var/db/geod: Permission denied
find: /System/Library/Templates/Data/private/var/db/oah: Operation not permitted
find: /System/Library/Templates/Data/private/var/db/reportmemoryexception: Permission denied
find: /System/Library/Templates/Data/private/var/db/lockdown: Permission denied
find: /System/Library/Templates/Data/private/var/db/biome: Permission denied
find: /System/Library/Templates/Data/private/var/db/datadetectors: Permission denied
find: /System/Library/Templates/Data/private/var/db/cmiodalassistants: Permission denied
find: /System/Library/Templates/Data/private/var/db/com.apple.xpc.roleaccountd.staging: Permission denied
find: /System/Library/Templates/Data/private/var/db/dslocal/nodes/Default: Permission denied
find: /System/Library/Templates/Data/private/var/db/nearbyd: Permission denied
find: /System/Library/Templates/Data/private/var/db/mmaintenanced: Permission denied
find: /System/Library/Templates/Data/private/var/db/timed: Permission denied
find: /System/Library/Templates/Data/private/var/db/applepay: Permission denied
find: /System/Library/Templates/Data/private/var/db/darwindaemon: Permission denied
find: /System/Library/Templates/Data/private/var/db/securityagent: Permission denied
find: /System/Library/Templates/Data/private/var/db/accessoryupdater: Permission denied
find: /System/Library/Templates/Data/private/var/db/ConfigurationProfiles/Store: Permission denied
find: /System/Library/Templates/Data/private/var/db/caches/opendirectory: Permission denied
find: /System/Library/Templates/Data/private/var/at/tabs: Permission denied
find: /System/Library/Templates/Data/private/var/at/tmp: Permission denied
find: /System/Library/Templates/Data/private/var/backups: Permission denied
find: /System/Library/Templates/Data/private/var/agentx: Permission denied
find: /System/Library/Caches/com.apple.appstored: Permission denied
find: /System/Library/Caches/com.apple.coresymbolicationd: Permission denied
find: /System/Volumes/Update/Hardware: Permission denied
find: /System/Volumes/Update/Controller: Permission denied
find: /System/Volumes/Preboot/.Trashes: Operation not permitted
find: /System/Volumes/Data/.Spotlight-V100: No such file or directory
find: /System/Volumes/Data/boot: No such file or directory
find: /System/Volumes/Data/Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /System/Volumes/Data/Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /System/Volumes/Data/Library/Application Support/ApplePushService: Permission denied
find: /System/Volumes/Data/Library/Application Support/com.apple.TCC: Operation not permitted
find: /System/Volumes/Data/Library/OSAnalytics/Preferences/Library: Permission denied
find: /System/Volumes/Data/Library/Caches/com.apple.iconservices.store: Permission denied
find: /System/Volumes/Data/Library/Caches/com.apple.aned: Operation not permitted
find: /System/Volumes/Data/System/Library/DirectoryServices/DefaultLocalDB/Default: Permission denied
^C
peter@MacBook-Pro mysql % cd /usr/local/etc
peter@MacBook-Pro etc % open .
peter@MacBook-Pro etc % cd /usr/local/var/mysql
peter@MacBook-Pro mysql % open .
peter@MacBook-Pro mysql % cd /usr/local/var/mysql
peter@MacBook-Pro mysql %
peter@MacBook-Pro mysql % brew install mysql@5.7
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/api/formula.jws.json
##O=#    #
==> Fetching mysql@5.7
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/mysql%405.7-5.7.42.ventura.bottle.tar.gz
Already downloaded: /Users/peter/Library/Caches/Homebrew/downloads/ec15e70578b4a7df698816b9d822effb66332950a3bf2c4e03aebcbf74250baa--mysql@5.7-5.7.42.ventura.bottle.tar.gz
==> Pouring mysql@5.7-5.7.42.ventura.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.42/bin/mysqld --initialize-insecure --user=peter --basedir=/usr/local/Cellar/mysql@5.7/5.7.42 --datadir=/usr/local/var/
==> 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

mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mysql@5.7 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

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 restart mysql@5.7 after an upgrade:
  brew services restart mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysqld_safe --datadir=/usr/local/var/mysql
==> Summary
🍺  /usr/local/Cellar/mysql@5.7/5.7.42: 321 files, 234.6MB
==> Running `brew cleanup mysql@5.7`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
peter@MacBook-Pro mysql % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": null
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro mysql % brew services restart mysql@5.7
==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
peter@MacBook-Pro mysql % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "started",
    "user": "peter",
    "file": "/Users/peter/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": 0
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro mysql % brew services list --json
[
  {
    "name": "mysql@5.7",
    "status": "started",
    "user": "peter",
    "file": "/Users/peter/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist",
    "exit_code": 0
  },
  {
    "name": "php@8.1",
    "status": "none",
    "user": null,
    "file": "/usr/local/opt/php@8.1/homebrew.mxcl.php@8.1.plist",
    "exit_code": null
  }
]
peter@MacBook-Pro mysql % mysql
ERROR 1045 (28000): Access denied for user 'peter'@'localhost' (using password: NO)
peter@MacBook-Pro mysql % mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.42 Homebrew

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> exit
Bye
posted @ 2023-05-05 20:26  窦戈  阅读(278)  评论(0)    收藏  举报