brew 安装mysql (Mac OS)

前言

本文记录一下mac安装mysql的一些过程。
没有brew的小伙伴可以看看这个 Homebrew, 该网站有安装的命令(国内在镜像下安装比较快)。brew很方便也很推荐,例如装些Nginx, redis啥的也很方便。

另外, linux的移步 linux安装mysql (详细步骤,初次初始化,sql小例子,可视化操作客户端推荐)


安装

推荐使用5.7的版本,暂时还不推荐新版本。

brew install mysql@5.7

然后就会自己安装一系列东西。然后就以输出一些提示信息.


文字版本, 方便后期拷贝命令hhhm

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 /opt/homebrew,
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="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"


To start mysql@5.7:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mysql@5.7/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
==> Summary
🍺  /opt/homebrew/Cellar/mysql@5.7/5.7.36: 320 files, 233.3MB
==> `brew cleanup` has not been run in the last 30 days, running now...
Removing: /Users/andydennis/Library/Logs/Homebrew/cmake... (64B)
Pruned 0 symbolic links and 2 directories from /opt/homebrew
==> Caveats
==> mysql@5.7
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 /opt/homebrew,
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="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"

To start mysql@5.7:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mysql@5.7/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql

设置路径

echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc



启动

记住安装后要重开一个终端界面再启动

mysql.server start

输入以下命令会发现多了3306端口号

netstat -AaLlnW

或者用以下命令查看一下3306端口对应的进程

lsof -i :3306


关闭

关闭数据库

mysql.server stop



连接

mysql -u root

关于数据库的用法推荐查看 mysql教程-菜鸟教程

另外不喜欢命令行操作的也可以使用vscode的插件或者JetBrains全家桶的软件连接数据库。



修改密码

记得选定mysql数据库下(use mysql;)运行以下命令,将root用户密码改为root123

alter USER root@localhost IDENTIFIED BY 'root123';
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值