Mac M1 安装MySQL

Mac M1 安装MySQL

安装MySQL

手动安装

手动安装是需要下载合适版本的MySQL,然后进行安装。下载地址:https://dev.mysql.com/downloads/mysql/

自动安装

使用终端命令行,直接可以进行安装,前提是电脑上已经安装了Homebrew。

终端使用 brew install mysql

~ brew install mysql
Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
    arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.

如果是M1 芯片的Mac的话,使用 arch -arm64 brew install mysql 命令

下面是更新的时候终端里的一些日志

~ arch -arm64 brew install mysql
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/libevent-2.1.12.arm64_big_sur.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/six-1.16.0_1.arm64_big_sur.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/protobuf-3.17.3.arm64_big_sur.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/mysql-8.0.25_1.arm64_big_sur.bottle.tar.gz
#=#=#      
## 这里报错了,下面自动切换到别的下载路径继续下载了                                                                   
curl: (22) The requested URL returned error: 404  Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/manifests/8.0.25_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/blobs/sha256:2e4b10e541bb3bdd076139c13bf6df3f729280c795552dd0d2b4
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:2e4b10e541bb3bdd076139c13bf6df3f729
######################################################################## 100.0%
==> Installing dependencies for mysql: libevent, six and protobuf
==> Installing mysql dependency: libevent
==> Pouring libevent-2.1.12.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libevent/2.1.12: 57 files, 2.2MB
==> Installing mysql dependency: six
==> Pouring six-1.16.0_1.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/six/1.16.0_1: 15 files, 86.2KB
==> Installing mysql dependency: protobuf
==> Pouring protobuf-3.17.3.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/protobuf/3.17.3: 210 files, 18.1MB
==> Installing mysql
==> Pouring mysql--8.0.25_1.arm64_big_sur.bottle.tar.gz
==> /opt/homebrew/Cellar/mysql/8.0.25_1/bin/mysqld --initialize-insecure --user=morris --basedir=/opt/homebrew/Cellar/my
==> 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
==> Summary
🍺  /opt/homebrew/Cellar/mysql/8.0.25_1: 300 files, 294.3MB
==> Caveats
==> mysql
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

这个有一些提示,我们按照提示来做就好了

We’ve installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
这个告诉我们MySQL已经安装成功,没有设置密码,如果要设置的话,执行mysql_secure_installation命令。

mysql_secure_installation

MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
现在的配置默认是连接到本地MySQL服务

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
这告诉我们如何启动MySQL

mysql.server start

这时候我们在终端里试一下,输入 mysql 回车

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

需要启动MySQL,启动之后重新输入 mysql 回车

~ mysql.server start
Starting MySQL
.. SUCCESS!~ mysql
ERROR 1045 (28000): Access denied for user 'morris'@'localhost' (using password: NO)

需要设置密码

~ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

输入 y 回车,提示选择密码强度

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

我选择了0回车,然后设置密码

Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 

后面还有一些调试,确认等,一路 y 回车,最后 All done! ,表示成功。

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

终端中查看了一下是否已经安装上,看到里面多了mysql

~ brew list
==> Formulae
apr		gettext		libev		libuv		ncurses		protobuf	utf8proc
apr-util	gmp		libevent	libyaml		nghttp2		readline	wget
brotli		icu4c		libidn2		lz4		nvm		ruby		zsh
c-ares		isl		libmpc		mpfr		openssl@1.1	six		zstd
gcc		jemalloc	libunistring	mysql		pcre		subversion

Access denied for user ‘morris’@‘localhost’ (using password: NO)

~ mysql
ERROR 1045 (28000): Access denied for user 'morris'@'localhost' (using password: NO)

还是报这个错误,看起来应该是权限问题,使用如下命令 mysql -u root -p 回车,输入密码即可。

~ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.25 Homebrew

Copyright (c) 2000, 2021, 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> 

我看网上有人手动下载安装之后,在偏好设置里面会出来一个MySQL的图标,为啥终端命令安装之后没有呢?初学SQL也不是很懂。

补充

下载MySQL直接安装,安装成功后在偏好设置里面会出现一个MySQL的图标。

在这里插入图片描述

建议不要使用终端去安装了,直接下载傻瓜式安装很方便。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morris_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值