本打算用docker 来整的,发现dockerhub 都不可用, 就用brew直接安装。 随笔小记。
操作之前需要先配置好homebrew,可以参考之前的博客:
Mac 安装 Homebrew 操作示例
https://www.cndba.cn/dave/article/116428
1 搜索mysql
david@Lotus bin % brew search mysql
==> Formulae
automysqlbackup mysql-client@8.0 mysql@8.0
mysql mysql-client@8.4 mysqltuner
mysql++ mysql-connector-c++ qt-mysql
mysql-client mysql-search-replace
mysql-client@5.7 mysql@5.7
==> Casks
mysql-connector-python mysqlworkbench sqlpro-for-mysql
mysql-shell navicat-for-mysql
2 安装mysql
david@Lotus bin % brew install mysql
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
……
==> mysql
Upgrading from MySQL <8.4 to MySQL >9.0 requires running MySQL 8.4 first:
- brew services stop mysql
- brew install mysql@8.4
- brew services start mysql@8.4
- brew services stop mysql@8.4
- brew services start mysql
--这里有启动和停止mysql的命令
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
--这里提示默认root是没有密码的
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -u root
--先启动mysql,然后直接mysql 就能连接了
To 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:
/opt/homebrew/opt/mysql/bin/mysqld_safe --datadir/=/opt/homebrew/var/mysql
==> openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"
david@Lotus bin %
3 登录mysql
先启动:
david@Lotus bin % brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
连接:
david@Lotus bin % mysql -u root
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 8
Server version: 9.0.1 Homebrew
Copyright (c) 2000, 2024, 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> select @@version;
+-----------+
| @@version |
+-----------+
| 9.0.1 |
+-----------+
1 row in set (0.00 sec)
默认没有密码,我们设置个密码:
mysql> alter user root@'localhost' identified by "root";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
重新登录就需要密码了:
david@Lotus bin % mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 12
Server version: 9.0.1 Homebrew
Copyright (c) 2000, 2024, 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>
版权声明:本文为博主原创文章,未经博主允许不得转载。