安装mysql for Mac

安装mysql for Mac Big Sur 11.1

环境

操作系统: Mac OS Big Sur 11.1
homebrew 版本:2.7.1

apple@Aaron ~ % brew -v
Homebrew 2.7.1-111-ge5eb6a2-dirty
Homebrew/homebrew-core (git revision d3b7e; last commit 2021-01-02)
Homebrew/homebrew-cask (git revision bc52e; last commit 2021-01-02)

安装过程

  1. 使用homebrew一键安装相应的包,因为homebrew会检测最新的版本,所以下载的mysql版本是5.7.*版本
apple@Aaron ~ % brew search mysql 
xcrun: error: active developer path ("/Library/Developer/CommandLineTools") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.
==> Formulae
automysqlbackup            [email protected]           [email protected]
mysql                      mysql-connector-c++        [email protected]
mysql++                    mysql-sandbox              mysqltuner
mysql-client               mysql-search-replace
==> Casks
mysql-connector-python     mysql-utilities            navicat-for-mysql
mysql-shell                mysqlworkbench             sqlpro-for-mysql
  1. 查看brew源是否为国内源,如果不是需要替换为国内源
apple@Aaron ~ % git -C "$(brew --repo)" remote -v
origin	https://mirrors.ustc.edu.cn/brew.git (fetch)
origin	https://mirrors.ustc.edu.cn/brew.git (push)
apple@Aaron ~ % git -C "$(brew --repo homebrew/core)" remote -v
origin	https://mirrors.ustc.edu.cn/homebrew-core.git (fetch)
origin	https://mirrors.ustc.edu.cn/homebrew-core.git (push)
apple@Aaron ~ % git -C "$(brew --repo homebrew/cask)" remote -v
origin	https://mirrors.ustc.edu.cn/homebrew-cask.git (fetch)
origin	https://mirrors.ustc.edu.cn/homebrew-cask.git (push)
  1. 安装mysql
apple@Aaron ~ % brew install [email protected]                         
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/mysql%405.7
######################################################################## 100.0%
==> Installing dependencies for [email protected]: [email protected]
==> Installing [email protected] dependency: [email protected]
==> Pouring [email protected]_sur.bottle.tar.gz ==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/[email protected]/certs

and run
  /usr/local/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For 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"

==> Summary
  /usr/local/Cellar/[email protected]/1.1.1i: 8,067 files, 18.5MB
==> Installing [email protected]
==> Pouring [email protected]_sur.bottle.2.tar.gz
==> /usr/local/Cellar/[email protected]/5.7.32/bin/mysqld --initialize-insecure --user=a
==> 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

[email protected] 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 [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For 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
==> Summary
  /usr/local/Cellar/[email protected]/5.7.32: 319 files, 234.4MB
==> Caveats
==> [email protected]
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/[email protected]/certs

and run
  /usr/local/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For 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"

==> [email protected]
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

[email protected] 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 [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For 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
  1. 设置环境变量
apple@Aaron ~ % echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
  1. 启动mysql,配置root密码
apple@Aaron ~ % mysql.server start 
Starting MySQL
. SUCCESS! 
apple@Aaron ~ % mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string = password('root') where user = 'roo';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

你可能感兴趣的:(mysql,mac,os,mysql)