签到成功

知道了

CNDBA社区CNDBA社区

macos 通过 brew 安装mysql

2024-12-21 10:30 474 0 原创 MySQL
作者: dave

本打算用docker 来整的,发现dockerhub 都不可用, 就用brew直接安装。 随笔小记。http://www.cndba.cn/dave/article/131606

操作之前需要先配置好homebrew,可以参考之前的博客:http://www.cndba.cn/dave/article/131606

http://www.cndba.cn/dave/article/131606

Mac 安装 Homebrew 操作示例
https://www.cndba.cn/dave/article/116428http://www.cndba.cn/dave/article/131606http://www.cndba.cn/dave/article/131606http://www.cndba.cn/dave/article/131606

http://www.cndba.cn/dave/article/131606

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

先启动:http://www.cndba.cn/dave/article/131606

david@Lotus bin % brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

连接:

http://www.cndba.cn/dave/article/131606
http://www.cndba.cn/dave/article/131606

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>

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2261
    原创
  • 3
    翻译
  • 578
    转载
  • 191
    评论
  • 访问:7964677次
  • 积分:4346
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ