Loading... <div class="tip share">请注意,本文编写于 671 天前,最后修改于 671 天前,其中某些信息可能已经过时。</div> 给台式机重装后,决定直接在本机建立开发环境,必不可少的就是 mysql 数据库。 ## 安装 brew 安装过程参见 <div class="preview"> <div class="post-inser post box-shadow-wrap-normal"> <a href="http://blog.ruixiaolu.com/archives/16/" target="_blank" class="post_inser_a no-external-link no-underline-link"> <div class="inner-image bg" style="background-image: url(https://blog.ruixiaolu.com/usr/uploads/20200312022439.png);background-size: cover;"></div> <div class="inner-content" > <p class="inser-title">Homebrew——MacOS下的包管理神器</p> <div class="inster-summary text-muted"> 前言Homebrew(简称为brew)是Mac下的一个包管理工具,可以用它来安装管理许多Mac没有预装的软件程序,... </div> </div> </a> <!-- .inner-content #####--> </div> <!-- .post-inser ####--> </div> 安装完毕后,可以换源加快访问速度 <div class="preview"> <div class="post-inser post box-shadow-wrap-normal"> <a href="http://blog.ruixiaolu.com/archives/17/" target="_blank" class="post_inser_a no-external-link no-underline-link"> <div class="inner-image bg" style="background-image: url(http://blog.ruixiaolu.com/usr/themes/handsome/assets/img/sj/6.jpg);background-size: cover;"></div> <div class="inner-content" > <p class="inser-title">Homebrew 替换默认源</p> <div class="inster-summary text-muted"> brew如果不换成国内源,安装软件时候可能会出问题,不是安装不了就是速度很慢,所以使用它,更换国内游是比较好的选择... </div> </div> </a> <!-- .inner-content #####--> </div> <!-- .post-inser ####--> </div> ## 查询 mysql 在终端输入命令 ```bash $ brew search mysql ==> Formulae automysqlbackup mysql-client@5.7 mysql-search-replace mysql mysql-connector-c++ mysql@5.6 mysql++ mysql-connector-c++@1.1 mysql@5.7 mysql-client ✔ mysql-sandbox mysqltuner ==> Casks homebrew/cask/mysql-connector-python homebrew/cask/navicat-for-mysql homebrew/cask/mysql-shell homebrew/cask/sqlpro-for-mysql homebrew/cask/mysql-utilities ``` 可以看到有很多种版本,这里我们使用 `brew info` 命令查看下 mysql 的信息 ```bash $ brew info mysql mysql: stable 8.0.21 (bottled) Open source relational database management system https://dev.mysql.com/doc/refman/8.0/en/ Conflicts with: mariadb (because mysql, mariadb, and percona install the same binaries) percona-server (because mysql, mariadb, and percona install the same binaries) Not installed From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/mysql.rb License: GPL-2.0 ==> Dependencies Build: cmake ✘ Required: openssl@1.1 ✔, protobuf ✔ ==> Caveats 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 To have launchd 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: mysql.server start ==> Analytics install: 61,328 (30 days), 204,252 (90 days), 799,732 (365 days) install-on-request: 60,225 (30 days), 198,703 (90 days), 769,522 (365 days) build-error: 0 (30 days) ``` 可以看到,默认的 `mysql` 版本为 8,所以我们不安装这个,只安装到 mysql5.7 即可(兼容性好)。 ## 安装 mysql5.7 执行命令 ```bash brew install mysql@5.7 ``` <div class="tip inlineBlock error"> 如果你不慎直接安装了默认版本的 mysql 想要回退到 5.7 版本,可以通过输入以下命令实现,(注意提前备份数据)。 ```bash brew uninstall mysql rm -rf /usr/local/var/mysql rm /usr/local/etc/my.cnf brew install mysql@5.7 ``` </div> 链接可执行文件 ```bash brew link --force mysql@5.7 ``` ## 启动 mysql 开机默认启动,执行命令 ```bash brew services start mysql@5.7 ``` 或者一次运行 ```bash /usr/local/opt/mysql@5.7/bin/mysql.server start ``` ## 初始化配置 执行命令 ```bash $ mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: N // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的 Please set the password for root here. New password: // 设置密码 Re-enter new password: // 再一次确认密码 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y // 移除不用密码的那个账户 Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n //不接受root远程登录账号 ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //删除text数据库 - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! ``` 最后修改:2020 年 10 月 16 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏