本文记录一下mac安装mysql的一些过程。
没有brew的小伙伴可以看看这个 Homebrew, 该网站有安装的命令(国内在镜像下安装比较快)。brew很方便也很推荐,例如装些Nginx, redis啥的也很方便。
另外, linux的移步 linux安装mysql (详细步骤,初次初始化,sql小例子,可视化操作客户端推荐)
推荐使用5.7的版本,暂时还不推荐新版本。
brew install [email protected]
然后就会自己安装一系列东西。然后就以输出一些提示信息.
文字版本, 方便后期拷贝命令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
[email protected] 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 [email protected] first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
To start [email protected]:
brew services start [email protected]
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/[email protected]/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
==> Summary
/opt/homebrew/Cellar/[email protected]/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
==> [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 /opt/homebrew,
because this is an alternate version of another formula.
If you need to have [email protected] first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
To start [email protected]:
brew services start [email protected]
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/[email protected]/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
设置路径
echo 'export PATH="/opt/homebrew/opt/[email protected]/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';