mac安装mysql

前言:

因为用mac开发,很多工具不是很熟练,这里做个笔记,以防以后再次入坑!!!


安装方式一:用dmg镜像安装

1、安装

下载好mysql MAC版安装包,常规步骤安装,安装过程中会出现如下提示:

2018-04-22T08:07:19.044013Z 1 [Note] A temporary password is generated for root@localhost: TfrNnt9!k1xi

其中TfrNnt9!k1xi 是初始密码,最好先记住!

2、登陆

但是在终端命令行 登陆mysql

mysql -u root -p

提示:-bash: mysql: command not found

遇上-bash: mysql: command not found的情况别着急,这个是因为/usr/local/bin目录下缺失mysql导致,只需建立软链接,即可以解决:

把mysql安装目录,比如MYSQLPATH/bin/mysql,映射到/usr/local/bin目录下:

cd /usr/local/bin

ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

接下来登陆就OK啦(完事!)

3、修改密码
在MySQL8.0.4以前,执行

SET PASSWORD=PASSWORD('修改的密码'); 

即可修改密码。

如果mysql是8.0版本以上,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。

因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,我暂时还是改回了“mysql_native_password”认证插件。

在MySQL中执行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

总结:

其实镜像安装非常简单,只是在映射mysql指令的时候需要烧点脑子。


安装方式二:用Homebrew进行安装

最近发现mac上一个神奇工具 Homebrew(包缺失管理),就像maven管理jar包的依赖一样,Homebrew帮忙管理各种工具,真是太方便。Homebrew的常用指令

安装mysql:brew install mysql
feideMacBook-Air:~ fei$ brew install mysql@5.7
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.23.high_sierra.
Already downloaded: /Users/fei/Library/Caches/Homebrew/mysql@5.7-5.7.23.high_sierra.bottle.tar.gz
==> Pouring mysql@5.7-5.7.23.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.23/bin/mysqld --initialize-insecure --user=fei
==> 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

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/mysql@5.7/lib
    CPPFLAGS: -I/usr/local/opt/mysql@5.7/include


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
?  /usr/local/Cellar/mysql@5.7/5.7.23: 317 files, 234.4MB

看看输出的提示,剩下的该怎么操作其实brew提示的很清楚了!!!

对mysql进行初始化操作:mysql_secure_installation
cometdeMacBook-Pro:~ comet
$ 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?
 // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Press y|Y for Yes, any other key for No: N   
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
 
 ... 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.
 
 // 是否删除test库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - 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!

OK!这样brew提示中的第一步就完成!接下来就可以尝试登陆了

登陆mysql:mysql -u root -p
启动mysql:brew services start mysql@5.7
停止mysql:brew services stop mysql@5.7



作者:luckXiaofei
链接:https://www.jianshu.com/p/e5c9e8ef8ccb
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值