前言

本文记录一下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';
GitHub 加速计划 / br / brew
40.4 K
9.47 K
下载
🍺 The missing package manager for macOS (or Linux)
最近提交(Master分支:30 天前 )
90a90b30 2 个月前
47b1cab7 2 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐